Commit c1d0dcd2 by Calen Pennington

Fix failing tests

parent c20cf81a
......@@ -30,6 +30,7 @@ class AuthTestCase(TestCase):
self.email = 'a@b.com'
self.pw = 'xyz'
self.username = 'testuser'
self.client = Client()
def check_page_get(self, url, expected):
resp = self.client.get(url)
......@@ -63,7 +64,8 @@ class AuthTestCase(TestCase):
'language' : 'Franglish',
'name' : 'Fred Weasley',
'terms_of_service' : 'true',
'honor_code' : 'true'})
'honor_code' : 'true',
})
return resp
def create_account(self, username, email, pw):
......@@ -121,7 +123,7 @@ class AuthTestCase(TestCase):
resp = self._login(self.email, self.pw)
data = parse_json(resp)
self.assertFalse(data['success'])
self.activate_user(self.email)
# Now login should work
......@@ -144,6 +146,9 @@ class AuthTestCase(TestCase):
# need an activated user
self.test_create_account()
# Create a new session
self.client = Client()
# Not logged in. Should redirect to login.
print 'Not logged in'
for page in auth_pages:
......
from util.json_request import expect_json
import json
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from django.contrib.auth.decorators import login_required
from django.core.context_processors import csrf
from django_future.csrf import ensure_csrf_cookie
from django.core.urlresolvers import reverse
from fs.osfs import OSFS
from xmodule.modulestore import Location
from github_sync import export_to_github
......@@ -14,6 +13,7 @@ from github_sync import export_to_github
from mitxmako.shortcuts import render_to_response
from xmodule.modulestore.django import modulestore
# ==== Public views ==================================================
@ensure_csrf_cookie
......@@ -22,7 +22,8 @@ def signup(request):
Display the signup form.
"""
csrf_token = csrf(request)['csrf_token']
return render_to_response('signup.html', {'csrf': csrf_token })
return render_to_response('signup.html', {'csrf': csrf_token})
@ensure_csrf_cookie
def login_page(request):
......@@ -30,8 +31,9 @@ def login_page(request):
Display the login form.
"""
csrf_token = csrf(request)['csrf_token']
return render_to_response('login.html', {'csrf': csrf_token })
return render_to_response('login.html', {'csrf': csrf_token})
# ==== Views for any logged-in user ==================================
@login_required
......@@ -47,6 +49,7 @@ def index(request):
for course in courses]
})
# ==== Views with per-item permissions================================
def has_access(user, location):
......@@ -54,18 +57,20 @@ def has_access(user, location):
# TODO (vshnayder): actually check perms
return user.is_active and user.is_authenticated
@login_required
@ensure_csrf_cookie
def course_index(request, org, course, name):
location = ['i4x', org, course, 'course', name]
if not has_access(request.user, location):
raise Http404 # TODO (vshnayder): better error
# TODO (cpennington): These need to be read in from the active user
course = modulestore().get_item(location)
weeks = course.get_children()
return render_to_response('course_index.html', {'weeks': weeks})
@login_required
def edit_item(request):
# TODO (vshnayder): change name from id to location in coffee+html as well.
......@@ -73,7 +78,7 @@ def edit_item(request):
print item_location, request.GET
if not has_access(request.user, item_location):
raise Http404 # TODO (vshnayder): better error
item = modulestore().get_item(item_location)
return render_to_response('unit.html', {
'contents': item.get_html(),
......@@ -98,6 +103,7 @@ def user_author_string(user):
last=l,
email=user.email)
@login_required
@expect_json
def save_item(request):
......
Someone, hopefully you, signed up for an account for edX's on-line
offering of "${ course_title}" using this email address. If it was
you, and you'd like to activate and use your account, copy and paste
this address into your web browser's address bar:
Thank you for signing up for edX! To activate your account,
please copy and paste this address into your web browser's
address bar:
% if is_secure:
https://${ site }/activate/${ key }
% else:
http://edx4edx.mitx.mit.edu/activate/${ key }
http://${ site }/activate/${ key }
% endif
If you didn't request this, you don't need to do anything; you won't
......
Your account for edX's on-line ${course_title} course
Your account for edX
<%! from django.core.urlresolvers import reverse %>
<%inherit file="../base.html" />
<%namespace name='static' file='../static_content.html'/>
<section class="container activation">
<section class="message">
%if not already_active:
<h1 class="valid">Activation Complete!</h1>
%else:
<h1>Account already active!</h1>
%endif
<hr class="horizontal-divider">
<p>
%if not already_active:
Thanks for activating your account.
%else:
This account has already been activated.
%endif
%if user_logged_in:
Visit your <a href="${reverse('dashboard')}">dashboard</a> to see your courses.
%else:
You can now <a href="#login-modal" rel="leanModal">login</a>.
%endif
</p>
</section>
</section>
......@@ -306,14 +306,14 @@ def create_account(request, post_override=None):
up = UserProfile(user=u)
up.name = post_vars['name']
up.level_of_education = post_vars['level_of_education']
up.gender = post_vars['gender']
up.mailing_address = post_vars['mailing_address']
up.goals = post_vars['goals']
up.level_of_education = post_vars.get('level_of_education')
up.gender = post_vars.get('gender')
up.mailing_address = post_vars.get('mailing_address')
up.goals = post_vars.get('goals')
try:
up.year_of_birth = int(post_vars['year_of_birth'])
except ValueError:
except (ValueError, KeyError):
up.year_of_birth = None # If they give us garbage, just ignore it instead
# of asking them to put an integer.
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment