Commit 9bfddd48 by Jean Manuel Nater

Addressed pull request feedback.

parent 905d884a
...@@ -14,6 +14,22 @@ class ModuleStoreTestCase(TestCase): ...@@ -14,6 +14,22 @@ class ModuleStoreTestCase(TestCase):
collection with templates before running the TestCase collection with templates before running the TestCase
and drops it they are finished. """ and drops it they are finished. """
def update_course(self, course, data):
"""
Updates the version of course in the mongo modulestore
with the metadata in data and returns the updated version.
"""
store = xmodule.modulestore.django.modulestore()
store.update_item(course.location, data)
store.update_metadata(course.location, data)
updated_course = store.get_instance(course.id, course.location)
return updated_course
@staticmethod @staticmethod
def flush_mongo_except_templates(): def flush_mongo_except_templates():
''' '''
......
...@@ -60,6 +60,8 @@ class XModuleCourseFactory(Factory): ...@@ -60,6 +60,8 @@ class XModuleCourseFactory(Factory):
if data is not None: if data is not None:
store.update_item(new_course.location, data) store.update_item(new_course.location, data)
'''update_item updates the the course as it exists in the modulestore, but doesn't
update the instance we are working with, so have to refetch the course after updating it.'''
new_course = store.get_instance(new_course.id, new_course.location) new_course = store.get_instance(new_course.id, new_course.location)
return new_course return new_course
...@@ -150,6 +152,8 @@ class XModuleItemFactory(Factory): ...@@ -150,6 +152,8 @@ class XModuleItemFactory(Factory):
if new_item.location.category not in DETACHED_CATEGORIES: if new_item.location.category not in DETACHED_CATEGORIES:
store.update_children(parent_location, parent.children + [new_item.location.url()]) store.update_children(parent_location, parent.children + [new_item.location.url()])
'''update_children updates the the item as it exists in the modulestore, but doesn't
update the instance we are working with, so have to refetch the item after updating it.'''
new_item = store.get_item(new_item.location) new_item = store.get_item(new_item.location)
return new_item return new_item
......
...@@ -245,8 +245,7 @@ def _has_access_descriptor(user, descriptor, action, course_context=None): ...@@ -245,8 +245,7 @@ def _has_access_descriptor(user, descriptor, action, course_context=None):
if descriptor.lms.start is not None: if descriptor.lms.start is not None:
now = datetime.now(UTC()) now = datetime.now(UTC())
effective_start = _adjust_start_date_for_beta_testers(user, descriptor) effective_start = _adjust_start_date_for_beta_testers(user, descriptor)
difference = (now - effective_start).total_seconds() if now > effective_start:
if difference > 3600:
# after start date, everyone can see it # after start date, everyone can see it
debug("Allow: now > effective start date") debug("Allow: now > effective start date")
return True return True
......
def check_for_get_code(code, url):
"""
Check that we got the expected code when accessing url via GET.
Returns the response.
"""
resp = self.client.get(url)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
def check_for_post_code(code, url, data={}):
"""
Check that we got the expected code when accessing url via POST.
Returns the response.
"""
resp = self.client.post(url, data)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
import json
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from student.models import Registration
from django.test import TestCase
def check_for_get_code(self, code, url):
"""
Check that we got the expected code when accessing url via GET.
Returns the HTTP response.
'self' is a class that subclasses TestCase.
"""
resp = self.client.get(url)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
def check_for_post_code(self, code, url, data={}):
"""
Check that we got the expected code when accessing url via POST.
Returns the HTTP response.
'self' is a class that subclasses TestCase.
"""
resp = self.client.post(url, data)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
class LoginEnrollmentTestCase(TestCase):
def setup_user(self):
"""
Create a user account, activate, and log in.
"""
self.email = 'foo@test.com'
self.password = 'bar'
self.username = 'test'
self.create_account(self.username,
self.email, self.password)
self.activate_user(self.email)
self.login(self.email, self.password)
# ============ User creation and login ==============
def login(self, email, password):
"""
Login, check that the corresponding view's response has a 200 status code.
"""
resp = resp = self.client.post(reverse('login'),
{'email': email, 'password': password})
self.assertEqual(resp.status_code, 200)
data = json.loads(resp.content)
self.assertTrue(data['success'])
def logout(self):
"""
Logout, check that it worked.
Returns an HTTP response which e
"""
resp = self.client.get(reverse('logout'), {})
# should redirect
self.assertEqual(resp.status_code, 302)
def create_account(self, username, email, password):
"""
Create the account and check that it worked.
"""
resp = self.client.post(reverse('create_account'), {
'username': username,
'email': email,
'password': password,
'name': 'username',
'terms_of_service': 'true',
'honor_code': 'true',
})
self.assertEqual(resp.status_code, 200)
data = json.loads(resp.content)
self.assertEqual(data['success'], True)
# Check both that the user is created, and inactive
self.assertFalse(User.objects.get(email=email).is_active)
def activate_user(self, email):
"""
Look up the activation key for the user, then hit the activate view.
No error checking.
"""
activation_key = Registration.objects.get(user__email=email).activation_key
# and now we try to activate
url = reverse('activate', kwargs={'key': activation_key})
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
# Now make sure that the user is now actually activated
self.assertTrue(User.objects.get(email=email).is_active)
def enroll(self, course, verify=False):
"""
Try to enroll and return boolean indicating result.
'course' is an instance of CourseDescriptor.
'verify' is an optional parameter specifying whether we
want to verify that the student was successfully enrolled
in the course.
"""
resp = self.client.post(reverse('change_enrollment'), {
'enrollment_action': 'enroll',
'course_id': course.id,
})
print ('Enrollment in %s result status code: %s'
% (course.location.url(), str(resp.status_code)))
result = resp.status_code == 200
if verify:
self.assertTrue(result)
return result
# def enroll(self, course):
# """
# Enroll the currently logged-in user, and check that it worked.
# """
# result = self.try_enroll(course)
# self.assertTrue(result)
def unenroll(self, course):
"""
Unenroll the currently logged-in user, and check that it worked.
'course' is an instance of CourseDescriptor.
"""
resp = self.client.post('/change_enrollment', {
'enrollment_action': 'unenroll',
'course_id': course.id,
})
self.assertEqual(resp.status_code, 200)
from uuid import uuid4
from django.conf import settings
def mongo_store_config(data_dir):
'''
Defines default module store using MongoModuleStore
Use of this config requires mongo to be running
'''
store = {
'default': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex,
'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string'
}
}
}
store['direct'] = store['default']
return store
def draft_mongo_store_config(data_dir):
'''Defines default module store using DraftMongoModuleStore'''
return {
'default': {
'ENGINE': 'xmodule.modulestore.mongo.DraftMongoModuleStore',
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex,
'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string',
}
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'OPTIONS': {
'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'test_xmodule',
'collection': 'modulestore_%s' % uuid4().hex,
'fs_root': data_dir,
'render_template': 'mitxmako.shortcuts.render_to_string',
}
}
}
def xml_store_config(data_dir):
'''Defines default module store using XMLModuleStore'''
return {
'default': {
'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore',
'OPTIONS': {
'data_dir': data_dir,
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
}
}
}
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
TEST_DATA_XML_MODULESTORE = xml_store_config(TEST_DATA_DIR)
TEST_DATA_MONGO_MODULESTORE = mongo_store_config(TEST_DATA_DIR)
TEST_DATA_DRAFT_MONGO_MODULESTORE = draft_mongo_store_config(TEST_DATA_DIR)
import logging
import json
from urlparse import urlsplit, urlunsplit
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from student.models import Registration
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
log = logging.getLogger("mitx." + __name__)
def parse_json(response):
"""Parse response, which is assumed to be json"""
return json.loads(response.content)
def get_user(email):
'''look up a user by email'''
return User.objects.get(email=email)
def get_registration(email):
'''look up registration object by email'''
return Registration.objects.get(user__email=email)
class MongoLoginHelpers(ModuleStoreTestCase):
def assertRedirectsNoFollow(self, response, expected_url):
"""
http://devblog.point2.com/2010/04/23/djangos-assertredirects-little-gotcha/
Don't check that the redirected-to page loads--there should be other tests for that.
Some of the code taken from django.test.testcases.py
"""
self.assertEqual(response.status_code, 302,
'Response status code was %d instead of 302'
% (response.status_code))
url = response['Location']
e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url)
if not (e_scheme or e_netloc):
expected_url = urlunsplit(('http', 'testserver',
e_path, e_query, e_fragment))
self.assertEqual(url, expected_url,
"Response redirected to '%s', expected '%s'" %
(url, expected_url))
def setup_viewtest_user(self):
'''create a user account, activate, and log in'''
self.viewtest_email = 'view@test.com'
self.viewtest_password = 'foo'
self.viewtest_username = 'viewtest'
self.create_account(self.viewtest_username,
self.viewtest_email, self.viewtest_password)
self.activate_user(self.viewtest_email)
self.login(self.viewtest_email, self.viewtest_password)
# ============ User creation and login ==============
def _login(self, email, password):
'''Login. View should always return 200. The success/fail is in the
returned json'''
resp = self.client.post(reverse('login'),
{'email': email, 'password': password})
self.assertEqual(resp.status_code, 200)
return resp
def login(self, email, password):
'''Login, check that it worked.'''
resp = self._login(email, password)
data = parse_json(resp)
self.assertTrue(data['success'])
return resp
def logout(self):
'''Logout, check that it worked.'''
resp = self.client.get(reverse('logout'), {})
# should redirect
self.assertEqual(resp.status_code, 302)
return resp
def _create_account(self, username, email, password):
'''Try to create an account. No error checking'''
resp = self.client.post('/create_account', {
'username': username,
'email': email,
'password': password,
'name': 'Fred Weasley',
'terms_of_service': 'true',
'honor_code': 'true',
})
return resp
def create_account(self, username, email, password):
'''Create the account and check that it worked'''
resp = self._create_account(username, email, password)
self.assertEqual(resp.status_code, 200)
data = parse_json(resp)
self.assertEqual(data['success'], True)
# Check both that the user is created, and inactive
self.assertFalse(get_user(email).is_active)
return resp
def _activate_user(self, email):
'''Look up the activation key for the user, then hit the activate view.
No error checking'''
activation_key = get_registration(email).activation_key
# and now we try to activate
url = reverse('activate', kwargs={'key': activation_key})
resp = self.client.get(url)
return resp
def activate_user(self, email):
resp = self._activate_user(email)
self.assertEqual(resp.status_code, 200)
# Now make sure that the user is now actually activated
self.assertTrue(get_user(email).is_active)
def try_enroll(self, course):
"""Try to enroll. Return bool success instead of asserting it."""
resp = self.client.post('/change_enrollment', {
'enrollment_action': 'enroll',
'course_id': course.id,
})
print ('Enrollment in %s result status code: %s'
% (course.location.url(), str(resp.status_code)))
return resp.status_code == 200
def enroll(self, course):
"""Enroll the currently logged-in user, and check that it worked."""
result = self.try_enroll(course)
self.assertTrue(result)
def unenroll(self, course):
"""Unenroll the currently logged-in user, and check that it worked."""
resp = self.client.post('/change_enrollment', {
'enrollment_action': 'unenroll',
'course_id': course.id,
})
self.assertTrue(resp.status_code == 200)
def check_for_get_code(self, code, url):
"""
Check that we got the expected code when accessing url via GET.
Returns the response.
"""
resp = self.client.get(url)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
def check_for_post_code(self, code, url, data={}):
"""
Check that we got the expected code when accessing url via POST.
Returns the response.
"""
resp = self.client.post(url, data)
self.assertEqual(resp.status_code, code,
"got code %d for url '%s'. Expected code %d"
% (resp.status_code, url, code))
return resp
from django.test import TestCase
from django.test.utils import override_settings
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import Location
from modulestore_config import TEST_DATA_DRAFT_MONGO_MODULESTORE
@override_settings(MODULESTORE=TEST_DATA_DRAFT_MONGO_MODULESTORE)
class TestDraftModuleStore(TestCase):
def test_get_items_with_course_items(self):
store = modulestore()
# fix was to allow get_items() to take the course_id parameter
store.get_items(Location(None, None, 'vertical', None, None),
course_id='abc', depth=0)
# test success is just getting through the above statement.
# The bug was that 'course_id' argument was
# not allowed to be passed in (i.e. was throwing exception)
...@@ -14,11 +14,13 @@ from django.core.urlresolvers import reverse ...@@ -14,11 +14,13 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE, get_user from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
import xmodule.modulestore.django import xmodule.modulestore.django
import json import json
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase):
''' '''
...@@ -41,7 +43,7 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): ...@@ -41,7 +43,7 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase):
def make_instructor(course): def make_instructor(course):
group_name = _course_staff_group_name(course.location) group_name = _course_staff_group_name(course.location)
g = Group.objects.create(name=group_name) g = Group.objects.create(name=group_name)
g.user_set.add(get_user(self.instructor)) g.user_set.add(User.objects.get(email=self.instructor))
make_instructor(self.graded_course) make_instructor(self.graded_course)
...@@ -67,7 +69,6 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase): ...@@ -67,7 +69,6 @@ class TestStaffMasqueradeAsStudent(LoginEnrollmentTestCase):
self.assertTrue(sdebug in resp.content) self.assertTrue(sdebug in resp.content)
def toggle_masquerade(self): def toggle_masquerade(self):
''' '''
Toggle masquerade state Toggle masquerade state
......
...@@ -11,12 +11,13 @@ django-admin.py test --settings=lms.envs.test --pythonpath=. lms/djangoapps/inst ...@@ -11,12 +11,13 @@ django-admin.py test --settings=lms.envs.test --pythonpath=. lms/djangoapps/inst
from django.test.utils import override_settings from django.test.utils import override_settings
# Need access to internal func to put users in the right group # Need access to internal func to put users in the right group
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE, get_user from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
import xmodule.modulestore.django import xmodule.modulestore.django
...@@ -45,7 +46,7 @@ class TestInstructorDashboardGradeDownloadCSV(LoginEnrollmentTestCase): ...@@ -45,7 +46,7 @@ class TestInstructorDashboardGradeDownloadCSV(LoginEnrollmentTestCase):
def make_instructor(course): def make_instructor(course):
group_name = _course_staff_group_name(course.location) group_name = _course_staff_group_name(course.location)
g = Group.objects.create(name=group_name) g = Group.objects.create(name=group_name)
g.user_set.add(get_user(self.instructor)) g.user_set.add(User.objects.get(email=self.instructor))
make_instructor(self.toy) make_instructor(self.toy)
...@@ -72,7 +73,7 @@ class TestInstructorDashboardGradeDownloadCSV(LoginEnrollmentTestCase): ...@@ -72,7 +73,7 @@ class TestInstructorDashboardGradeDownloadCSV(LoginEnrollmentTestCase):
# All the not-actually-in-the-course hw and labs come from the # All the not-actually-in-the-course hw and labs come from the
# default grading policy string in graders.py # default grading policy string in graders.py
expected_body = '''"ID","Username","Full Name","edX email","External email","HW 01","HW 02","HW 03","HW 04","HW 05","HW 06","HW 07","HW 08","HW 09","HW 10","HW 11","HW 12","HW Avg","Lab 01","Lab 02","Lab 03","Lab 04","Lab 05","Lab 06","Lab 07","Lab 08","Lab 09","Lab 10","Lab 11","Lab 12","Lab Avg","Midterm","Final" expected_body = '''"ID","Username","Full Name","edX email","External email","HW 01","HW 02","HW 03","HW 04","HW 05","HW 06","HW 07","HW 08","HW 09","HW 10","HW 11","HW 12","HW Avg","Lab 01","Lab 02","Lab 03","Lab 04","Lab 05","Lab 06","Lab 07","Lab 08","Lab 09","Lab 10","Lab 11","Lab 12","Lab Avg","Midterm","Final"
"2","u2","Fred Weasley","view2@test.com","","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0" "2","u2","username","view2@test.com","","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"
''' '''
self.assertEqual(body, expected_body, msg) self.assertEqual(body, expected_body, msg)
...@@ -7,7 +7,8 @@ from django.test.utils import override_settings ...@@ -7,7 +7,8 @@ from django.test.utils import override_settings
from django.contrib.auth.models import Group, User from django.contrib.auth.models import Group, User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE, get_user from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
import xmodule.modulestore.django import xmodule.modulestore.django
from student.models import CourseEnrollment, CourseEnrollmentAllowed from student.models import CourseEnrollment, CourseEnrollmentAllowed
...@@ -40,7 +41,7 @@ class TestInstructorEnrollsStudent(LoginEnrollmentTestCase): ...@@ -40,7 +41,7 @@ class TestInstructorEnrollsStudent(LoginEnrollmentTestCase):
def make_instructor(course): def make_instructor(course):
group_name = _course_staff_group_name(course.location) group_name = _course_staff_group_name(course.location)
g = Group.objects.create(name=group_name) g = Group.objects.create(name=group_name)
g.user_set.add(get_user(self.instructor)) g.user_set.add(User.objects.get(email=self.instructor))
make_instructor(self.toy) make_instructor(self.toy)
......
...@@ -6,7 +6,7 @@ Unit tests for instructor dashboard forum administration ...@@ -6,7 +6,7 @@ Unit tests for instructor dashboard forum administration
from django.test.utils import override_settings from django.test.utils import override_settings
# Need access to internal func to put users in the right group # Need access to internal func to put users in the right group
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \ from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \
...@@ -14,7 +14,8 @@ from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \ ...@@ -14,7 +14,8 @@ from django_comment_common.models import Role, FORUM_ROLE_ADMINISTRATOR, \
from django_comment_client.utils import has_forum_access from django_comment_client.utils import has_forum_access
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE, get_user from courseware.tests.helpers import LoginEnrollmentTestCase
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
import xmodule.modulestore.django import xmodule.modulestore.django
...@@ -55,7 +56,7 @@ class TestInstructorDashboardForumAdmin(LoginEnrollmentTestCase): ...@@ -55,7 +56,7 @@ class TestInstructorDashboardForumAdmin(LoginEnrollmentTestCase):
group_name = _course_staff_group_name(self.toy.location) group_name = _course_staff_group_name(self.toy.location)
g = Group.objects.create(name=group_name) g = Group.objects.create(name=group_name)
g.user_set.add(get_user(self.instructor)) g.user_set.add(User.objects.get(email=self.instructor))
self.logout() self.logout()
self.login(self.instructor, self.password) self.login(self.instructor, self.password)
...@@ -146,4 +147,4 @@ class TestInstructorDashboardForumAdmin(LoginEnrollmentTestCase): ...@@ -146,4 +147,4 @@ class TestInstructorDashboardForumAdmin(LoginEnrollmentTestCase):
added_roles.append(rolename) added_roles.append(rolename)
added_roles.sort() added_roles.sort()
roles = ', '.join(added_roles) roles = ', '.join(added_roles)
self.assertTrue(response.content.find('<td>{0}</td>'.format(roles)) >= 0, 'not finding roles "{0}"'.format(roles)) self.assertTrue(response.content.find('<td>{0}</td>'.format(roles)) >= 0, 'not finding roles "{0}"'.format(roles))
\ No newline at end of file
...@@ -8,8 +8,7 @@ import json ...@@ -8,8 +8,7 @@ import json
from mock import MagicMock, patch, Mock from mock import MagicMock, patch, Mock
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, User
from django.http import HttpResponse
from django.conf import settings from django.conf import settings
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
...@@ -21,7 +20,6 @@ from xmodule.x_module import ModuleSystem ...@@ -21,7 +20,6 @@ from xmodule.x_module import ModuleSystem
from open_ended_grading import staff_grading_service, views from open_ended_grading import staff_grading_service, views
from courseware.access import _course_staff_group_name from courseware.access import _course_staff_group_name
from courseware.tests.tests import LoginEnrollmentTestCase, TEST_DATA_XML_MODULESTORE, get_user
import logging import logging
...@@ -31,6 +29,9 @@ from django.test.utils import override_settings ...@@ -31,6 +29,9 @@ from django.test.utils import override_settings
from xmodule.tests import test_util_open_ended from xmodule.tests import test_util_open_ended
from courseware.tests import factories from courseware.tests import factories
from courseware.tests.modulestore_config import TEST_DATA_XML_MODULESTORE
from courseware.tests.helpers import LoginEnrollmentTestCase, check_for_get_code, check_for_post_code
@override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE)
class TestStaffGradingService(LoginEnrollmentTestCase): class TestStaffGradingService(LoginEnrollmentTestCase):
...@@ -58,7 +59,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -58,7 +59,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
def make_instructor(course): def make_instructor(course):
group_name = _course_staff_group_name(course.location) group_name = _course_staff_group_name(course.location)
group = Group.objects.create(name=group_name) group = Group.objects.create(name=group_name)
group.user_set.add(get_user(self.instructor)) group.user_set.add(User.objects.get(email=self.instructor))
make_instructor(self.toy) make_instructor(self.toy)
...@@ -75,8 +76,8 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -75,8 +76,8 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
# both get and post should return 404 # both get and post should return 404
for view_name in ('staff_grading_get_next', 'staff_grading_save_grade'): for view_name in ('staff_grading_get_next', 'staff_grading_save_grade'):
url = reverse(view_name, kwargs={'course_id': self.course_id}) url = reverse(view_name, kwargs={'course_id': self.course_id})
self.check_for_get_code(404, url) check_for_get_code(self, 404, url)
self.check_for_post_code(404, url) check_for_post_code(self, 404, url)
def test_get_next(self): def test_get_next(self):
self.login(self.instructor, self.password) self.login(self.instructor, self.password)
...@@ -84,7 +85,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -84,7 +85,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
url = reverse('staff_grading_get_next', kwargs={'course_id': self.course_id}) url = reverse('staff_grading_get_next', kwargs={'course_id': self.course_id})
data = {'location': self.location} data = {'location': self.location}
response = self.check_for_post_code(200, url, data) response = check_for_post_code(self, 200, url, data)
content = json.loads(response.content) content = json.loads(response.content)
...@@ -113,7 +114,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -113,7 +114,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
if skip: if skip:
data.update({'skipped': True}) data.update({'skipped': True})
response = self.check_for_post_code(200, url, data) response = check_for_post_code(self, 200, url, data)
content = json.loads(response.content) content = json.loads(response.content)
self.assertTrue(content['success'], str(content)) self.assertTrue(content['success'], str(content))
self.assertEquals(content['submission_id'], self.mock_service.cnt) self.assertEquals(content['submission_id'], self.mock_service.cnt)
...@@ -130,7 +131,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase): ...@@ -130,7 +131,7 @@ class TestStaffGradingService(LoginEnrollmentTestCase):
url = reverse('staff_grading_get_problem_list', kwargs={'course_id': self.course_id}) url = reverse('staff_grading_get_problem_list', kwargs={'course_id': self.course_id})
data = {} data = {}
response = self.check_for_post_code(200, url, data) response = check_for_post_code(self, 200, url, data)
content = json.loads(response.content) content = json.loads(response.content)
self.assertTrue(content['success'], str(content)) self.assertTrue(content['success'], str(content))
......
...@@ -36,7 +36,7 @@ urlpatterns = ('', # nopep8 ...@@ -36,7 +36,7 @@ urlpatterns = ('', # nopep8
url(r'^login_ajax$', 'student.views.login_user', name="login"), url(r'^login_ajax$', 'student.views.login_user', name="login"),
url(r'^login_ajax/(?P<error>[^/]*)$', 'student.views.login_user'), url(r'^login_ajax/(?P<error>[^/]*)$', 'student.views.login_user'),
url(r'^logout$', 'student.views.logout_user', name='logout'), url(r'^logout$', 'student.views.logout_user', name='logout'),
url(r'^create_account$', 'student.views.create_account'), url(r'^create_account$', 'student.views.create_account', name='create_account'),
url(r'^activate/(?P<key>[^/]*)$', 'student.views.activate_account', name="activate"), url(r'^activate/(?P<key>[^/]*)$', 'student.views.activate_account', name="activate"),
url(r'^begin_exam_registration/(?P<course_id>[^/]+/[^/]+/[^/]+)$', 'student.views.begin_exam_registration', name="begin_exam_registration"), url(r'^begin_exam_registration/(?P<course_id>[^/]+/[^/]+/[^/]+)$', 'student.views.begin_exam_registration', name="begin_exam_registration"),
......
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