Commit 7a34a8c3 by Calen Pennington

Fix failing tests

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