Commit 0de4f601 by Matt Drayer Committed by Jonathan Piacenti

mattdrayer/rebase-20140916: Initial test fixes

parent 6454290f
...@@ -1743,7 +1743,7 @@ class CoursesApiTests(TestCase): ...@@ -1743,7 +1743,7 @@ class CoursesApiTests(TestCase):
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['leaders']), 4) self.assertEqual(len(response.data['leaders']), 4)
self.assertEqual(response.data['course_avg'], 20) self.assertEqual(response.data['course_avg'], 14)
# without count filter and user_id # without count filter and user_id
test_uri = '{}/{}/metrics/completions/leaders/?user_id={}'.format(self.base_courses_uri, self.test_course_id, test_uri = '{}/{}/metrics/completions/leaders/?user_id={}'.format(self.base_courses_uri, self.test_course_id,
...@@ -1752,7 +1752,7 @@ class CoursesApiTests(TestCase): ...@@ -1752,7 +1752,7 @@ class CoursesApiTests(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['leaders']), 3) self.assertEqual(len(response.data['leaders']), 3)
self.assertEqual(response.data['position'], 2) self.assertEqual(response.data['position'], 2)
self.assertEqual(response.data['completions'], 28) self.assertEqual(response.data['completions'], 19)
# with skipleaders filter # with skipleaders filter
test_uri = '{}/{}/metrics/completions/leaders/?user_id={}&skipleaders=true'.format(self.base_courses_uri, test_uri = '{}/{}/metrics/completions/leaders/?user_id={}&skipleaders=true'.format(self.base_courses_uri,
...@@ -1762,7 +1762,7 @@ class CoursesApiTests(TestCase): ...@@ -1762,7 +1762,7 @@ class CoursesApiTests(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIsNone(response.data.get('leaders', None)) self.assertIsNone(response.data.get('leaders', None))
self.assertIsNone(response.data.get('position', None)) self.assertIsNone(response.data.get('position', None))
self.assertEqual(response.data['completions'], 28) self.assertEqual(response.data['completions'], 19)
# test with bogus course # test with bogus course
test_uri = '{}/{}/metrics/completions/leaders/'.format(self.base_courses_uri, self.test_bogus_course_id) test_uri = '{}/{}/metrics/completions/leaders/'.format(self.base_courses_uri, self.test_bogus_course_id)
......
...@@ -69,8 +69,9 @@ def get_course_leaf_nodes(course_key, detached_categories): ...@@ -69,8 +69,9 @@ def get_course_leaf_nodes(course_key, detached_categories):
nodes = [] nodes = []
verticals = get_modulestore().get_items(course_key, category='vertical') verticals = get_modulestore().get_items(course_key, category='vertical')
for vertical in verticals: for vertical in verticals:
nodes.extend([unit for unit in vertical.children if hasattr(vertical, 'children'):
if getattr(unit, 'category') not in detached_categories]) nodes.extend([unit for unit in vertical.children
if getattr(unit, 'category') not in detached_categories])
return nodes return nodes
......
...@@ -90,7 +90,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -90,7 +90,9 @@ class UsersApiTests(ModuleStoreTestCase):
self.course = CourseFactory.create( self.course = CourseFactory.create(
display_name="TEST COURSE", display_name="TEST COURSE",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='USERTEST',
run='USERTEST1'
) )
self.course_content = ItemFactory.create( self.course_content = ItemFactory.create(
category="videosequence", category="videosequence",
...@@ -99,7 +101,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -99,7 +101,7 @@ class UsersApiTests(ModuleStoreTestCase):
due=datetime(2016, 5, 16, 14, 30), due=datetime(2016, 5, 16, 14, 30),
display_name="View_Sequence" display_name="View_Sequence"
) )
self.course2 = CourseFactory.create(display_name="TEST COURSE2", org='TESTORG2') self.course2 = CourseFactory.create(display_name="TEST COURSE2", org='TESTORG2', run='USERTEST2')
self.course2_content = ItemFactory.create( self.course2_content = ItemFactory.create(
category="videosequence", category="videosequence",
parent_location=self.course2.location, parent_location=self.course2.location,
...@@ -734,7 +736,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -734,7 +736,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertTrue(response.data['is_active']) self.assertTrue(response.data['is_active'])
def test_user_courses_list_post_undefined_user(self): def test_user_courses_list_post_undefined_user(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCLPUU', run='TUCLPUU1')
test_uri = self.users_base_uri test_uri = self.users_base_uri
user_id = '234234' user_id = '234234'
test_uri = '{}/{}/courses'.format(test_uri, str(user_id)) test_uri = '{}/{}/courses'.format(test_uri, str(user_id))
...@@ -771,7 +773,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -771,7 +773,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 201) self.assertEqual(response.status_code, 201)
confirm_uri = self.test_server_prefix + test_uri + '/' + unicode(self.course.id) confirm_uri = self.test_server_prefix + test_uri + '/' + unicode(self.course.id)
course_with_out_date_values = CourseFactory.create() course_with_out_date_values = CourseFactory.create(org='TUCLG', run='TUCLG1')
data = {'course_id': unicode(course_with_out_date_values.id)} data = {'course_id': unicode(course_with_out_date_values.id)}
response = self.do_post(test_uri, data) response = self.do_post(test_uri, data)
self.assertEqual(response.status_code, 201) self.assertEqual(response.status_code, 201)
...@@ -794,7 +796,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -794,7 +796,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_post_position_course_as_descriptor(self): def test_user_courses_detail_post_position_course_as_descriptor(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDPPCAD', run='TUCDPPCAD1')
test_data = '<html>{}</html>'.format(str(uuid.uuid4())) test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create( chapter1 = ItemFactory.create(
category="chapter", category="chapter",
...@@ -889,7 +891,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -889,7 +891,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_post_position_invalid_user(self): def test_user_courses_detail_post_position_invalid_user(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDPPIU', run='TUCDPPIU1')
test_data = '<html>{}</html>'.format(str(uuid.uuid4())) test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create( chapter1 = ItemFactory.create(
category="chapter", category="chapter",
...@@ -913,7 +915,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -913,7 +915,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_post_position_course_as_content(self): def test_user_courses_detail_post_position_course_as_content(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDPPCAS', run='TUCDPPCAS1')
test_data = '<html>{}</html>'.format(str(uuid.uuid4())) test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create( chapter1 = ItemFactory.create(
category="chapter", category="chapter",
...@@ -962,7 +964,13 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -962,7 +964,13 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
def test_user_courses_detail_get(self): def test_user_courses_detail_get(self):
course = CourseFactory.create() course = CourseFactory.create(
display_name="UserCoursesDetailTestCourse",
start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30),
org='TUCDG',
run='TUCDG1'
)
test_data = '<html>{}</html>'.format(str(uuid.uuid4())) test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create( chapter1 = ItemFactory.create(
category="chapter", category="chapter",
...@@ -987,6 +995,8 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -987,6 +995,8 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.data['uri'], confirm_uri) self.assertEqual(response.data['uri'], confirm_uri)
self.assertEqual(response.data['course_id'], unicode(course.id)) self.assertEqual(response.data['course_id'], unicode(course.id))
self.assertEqual(response.data['user_id'], user_id) self.assertEqual(response.data['user_id'], user_id)
# Now add the user's position in the course
position_data = { position_data = {
'positions': [ 'positions': [
{ {
...@@ -1013,7 +1023,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1013,7 +1023,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_get_undefined_enrollment(self): def test_user_courses_detail_get_undefined_enrollment(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDGUE', run='TUCDGUE1')
test_uri = self.users_base_uri test_uri = self.users_base_uri
local_username = self.test_username + str(randint(11, 99)) local_username = self.test_username + str(randint(11, 99))
data = {'email': self.test_email, 'username': local_username, 'password': data = {'email': self.test_email, 'username': local_username, 'password':
...@@ -1025,7 +1035,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1025,7 +1035,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_delete(self): def test_user_courses_detail_delete(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDD', run='TUCDD1')
test_uri = self.users_base_uri test_uri = self.users_base_uri
local_username = self.test_username + str(randint(11, 99)) local_username = self.test_username + str(randint(11, 99))
data = {'email': self.test_email, 'username': local_username, 'password': data = {'email': self.test_email, 'username': local_username, 'password':
...@@ -1054,7 +1064,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1054,7 +1064,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_courses_detail_delete_undefined_user(self): def test_user_courses_detail_delete_undefined_user(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCDDUU', run='TUCDDUU1')
user_id = '2134234' user_id = '2134234'
test_uri = '{}/{}/courses/{}'.format(self.users_base_uri, user_id, course.id) test_uri = '{}/{}/courses/{}'.format(self.users_base_uri, user_id, course.id)
response = self.do_delete(test_uri) response = self.do_delete(test_uri)
...@@ -1071,7 +1081,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1071,7 +1081,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_user_course_grades_user_not_found(self): def test_user_course_grades_user_not_found(self):
course = CourseFactory.create() course = CourseFactory.create(org='TUCGUNF', run='TUCGUNF1')
test_uri = '{}/99999999/courses/{}/grades'.format(self.users_base_uri, course.id) test_uri = '{}/99999999/courses/{}/grades'.format(self.users_base_uri, course.id)
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
...@@ -1088,8 +1098,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1088,8 +1098,9 @@ class UsersApiTests(ModuleStoreTestCase):
test_uri = '{}/{}/preferences'.format(self.users_base_uri, user_id) test_uri = '{}/{}/preferences'.format(self.users_base_uri, user_id)
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1) self.assertEqual(len(response.data), 2)
self.assertEqual(response.data['pref-lang'], 'en') self.assertEqual(response.data['pref-lang'], 'en')
self.assertIsNotNone(response.data['notification_pref'])
def test_user_preferences_list_post_user_not_found(self): def test_user_preferences_list_post_user_not_found(self):
test_uri = '{}/{}/preferences'.format(self.users_base_uri, '999999') test_uri = '{}/{}/preferences'.format(self.users_base_uri, '999999')
...@@ -1118,7 +1129,8 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1118,7 +1129,8 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 201) self.assertEqual(response.status_code, 201)
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2) self.assertEqual(len(response.data), 3)
self.assertIsNotNone(response.data['notification_pref'])
self.assertEqual(response.data['pref-lang'], 'en') self.assertEqual(response.data['pref-lang'], 'en')
self.assertEqual(response.data['foo'], 'bar') self.assertEqual(response.data['foo'], 'bar')
...@@ -1131,7 +1143,8 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1131,7 +1143,8 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2) self.assertEqual(len(response.data), 3)
self.assertIsNotNone(response.data['notification_pref'])
self.assertEqual(response.data['pref-lang'], 'en') self.assertEqual(response.data['pref-lang'], 'en')
self.assertEqual(response.data['foo'], 'updated') self.assertEqual(response.data['foo'], 'updated')
...@@ -1171,7 +1184,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1171,7 +1184,7 @@ class UsersApiTests(ModuleStoreTestCase):
def test_user_courses_grades_list_get(self): def test_user_courses_grades_list_get(self):
user_id = self.user.id user_id = self.user.id
course = CourseFactory.create() course = CourseFactory.create(org='TUCGLG', run='TUCGLG1')
test_data = '<html>{}</html>'.format(str(uuid.uuid4())) test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create( chapter1 = ItemFactory.create(
category="chapter", category="chapter",
...@@ -1337,8 +1350,6 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1337,8 +1350,6 @@ class UsersApiTests(ModuleStoreTestCase):
due=datetime(2015, 1, 16, 14, 30).replace(tzinfo=timezone.utc) due=datetime(2015, 1, 16, 14, 30).replace(tzinfo=timezone.utc)
) )
test_uri = '{}/{}/courses/{}/grades'.format(self.users_base_uri, user_id, unicode(course.id)) test_uri = '{}/{}/courses/{}/grades'.format(self.users_base_uri, user_id, unicode(course.id))
response = self.do_get(test_uri) response = self.do_get(test_uri)
...@@ -1355,7 +1366,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1355,7 +1366,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertEqual(sections[0]['graded'], False) self.assertEqual(sections[0]['graded'], False)
sections = courseware_summary[1]['sections'] sections = courseware_summary[1]['sections']
self.assertEqual(len(sections), 8) self.assertEqual(len(sections), 12)
self.assertEqual(sections[0]['display_name'], 'Sequence 2') self.assertEqual(sections[0]['display_name'], 'Sequence 2')
self.assertEqual(sections[0]['graded'], False) self.assertEqual(sections[0]['graded'], False)
...@@ -1365,7 +1376,7 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1365,7 +1376,7 @@ class UsersApiTests(ModuleStoreTestCase):
self.assertGreater(len(grading_policy['GRADER']), 0) self.assertGreater(len(grading_policy['GRADER']), 0)
self.assertIsNotNone(grading_policy['GRADE_CUTOFFS']) self.assertIsNotNone(grading_policy['GRADE_CUTOFFS'])
self.assertEqual(response.data['current_grade'], 0.7) self.assertEqual(response.data['current_grade'], 0.73)
self.assertEqual(response.data['proforma_grade'], 0.9375) self.assertEqual(response.data['proforma_grade'], 0.9375)
def is_user_profile_created_updated(self, response, data): def is_user_profile_created_updated(self, response, data):
...@@ -1578,13 +1589,17 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1578,13 +1589,17 @@ class UsersApiTests(ModuleStoreTestCase):
course2 = CourseFactory.create( course2 = CourseFactory.create(
display_name="TEST COURSE2", display_name="TEST COURSE2",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='TURLG',
run='TURLG1'
) )
allow_access(course2, self.user, 'instructor') allow_access(course2, self.user, 'instructor')
course3 = CourseFactory.create( course3 = CourseFactory.create(
display_name="TEST COURSE3", display_name="TEST COURSE3",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='TURLG2',
run='TURLG2'
) )
allow_access(course3, self.user, 'staff') allow_access(course3, self.user, 'staff')
test_uri = '{}/{}/roles/'.format(self.users_base_uri, self.user.id) test_uri = '{}/{}/roles/'.format(self.users_base_uri, self.user.id)
...@@ -1663,7 +1678,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1663,7 +1678,9 @@ class UsersApiTests(ModuleStoreTestCase):
course2 = CourseFactory.create( course2 = CourseFactory.create(
display_name="TEST COURSE2", display_name="TEST COURSE2",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='TURLP2',
run='TURLP2'
) )
Role.objects.get_or_create( Role.objects.get_or_create(
name=FORUM_ROLE_MODERATOR, name=FORUM_ROLE_MODERATOR,
...@@ -1672,7 +1689,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1672,7 +1689,9 @@ class UsersApiTests(ModuleStoreTestCase):
course3 = CourseFactory.create( course3 = CourseFactory.create(
display_name="TEST COURSE3", display_name="TEST COURSE3",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='TURLP3',
run='TURLP3'
) )
Role.objects.get_or_create( Role.objects.get_or_create(
name=FORUM_ROLE_MODERATOR, name=FORUM_ROLE_MODERATOR,
...@@ -1681,7 +1700,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1681,7 +1700,9 @@ class UsersApiTests(ModuleStoreTestCase):
course4 = CourseFactory.create( course4 = CourseFactory.create(
display_name="COURSE4 NO MODERATOR", display_name="COURSE4 NO MODERATOR",
start=datetime(2014, 6, 16, 14, 30), start=datetime(2014, 6, 16, 14, 30),
end=datetime(2015, 1, 16, 14, 30) end=datetime(2015, 1, 16, 14, 30),
org='TURLP4',
run='TURLP4'
) )
test_uri = '{}/{}/roles/'.format(self.users_base_uri, self.user.id) test_uri = '{}/{}/roles/'.format(self.users_base_uri, self.user.id)
......
...@@ -23,7 +23,10 @@ from instructor.access import revoke_access, update_forum_role ...@@ -23,7 +23,10 @@ from instructor.access import revoke_access, update_forum_role
from lang_pref import LANGUAGE_KEY from lang_pref import LANGUAGE_KEY
from lms.lib.comment_client.user import User as CommentUser from lms.lib.comment_client.user import User as CommentUser
from lms.lib.comment_client.utils import CommentClientRequestError from lms.lib.comment_client.utils import CommentClientRequestError
from opaque_keys.edx.locations import SlashSeparatedCourseKey from notification_prefs.views import enable_notifications
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey, CourseKey
from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey
from student.models import CourseEnrollment, PasswordHistory, UserProfile from student.models import CourseEnrollment, PasswordHistory, UserProfile
from openedx.core.djangoapps.user_api.models import UserPreference from openedx.core.djangoapps.user_api.models import UserPreference
from student.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, CourseAssistantRole, UserBasedRole from student.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, CourseAssistantRole, UserBasedRole
...@@ -32,9 +35,11 @@ from util.password_policy_validators import ( ...@@ -32,9 +35,11 @@ from util.password_policy_validators import (
validate_password_length, validate_password_complexity, validate_password_length, validate_password_complexity,
validate_password_dictionary validate_password_dictionary
) )
from xmodule.modulestore import InvalidLocationError
from xmodule.modulestore.django import modulestore
from api_manager.courses.serializers import CourseModuleCompletionSerializer from api_manager.courses.serializers import CourseModuleCompletionSerializer
from api_manager.courseware_access import get_course, get_course_child, get_course_key, course_exists, calculate_proforma_grade from api_manager.courseware_access import get_course, get_course_child, get_course_child_content, get_course_key, course_exists, calculate_proforma_grade
from api_manager.permissions import SecureAPIView, SecureListAPIView, IdsInFilterBackend, HasOrgsFilterBackend from api_manager.permissions import SecureAPIView, SecureListAPIView, IdsInFilterBackend, HasOrgsFilterBackend
from api_manager.models import GroupProfile, APIUser as User from api_manager.models import GroupProfile, APIUser as User
from api_manager.organizations.serializers import OrganizationSerializer from api_manager.organizations.serializers import OrganizationSerializer
...@@ -42,12 +47,7 @@ from api_manager.utils import generate_base_uri, dict_has_items, extract_data_pa ...@@ -42,12 +47,7 @@ from api_manager.utils import generate_base_uri, dict_has_items, extract_data_pa
from projects.serializers import BasicWorkgroupSerializer from projects.serializers import BasicWorkgroupSerializer
from .serializers import UserSerializer, UserCountByCitySerializer, UserRolesSerializer from .serializers import UserSerializer, UserCountByCitySerializer, UserRolesSerializer
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey, CourseKey
from opaque_keys.edx.locations import Location
from xmodule.modulestore import InvalidLocationError
from xmodule.modulestore.django import modulestore
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
AUDIT_LOG = logging.getLogger("audit") AUDIT_LOG = logging.getLogger("audit")
...@@ -121,7 +121,7 @@ def _save_child_position(parent_descriptor, target_child_location): ...@@ -121,7 +121,7 @@ def _save_child_position(parent_descriptor, target_child_location):
we just compare id's from the array of children we just compare id's from the array of children
""" """
for position, child_location in enumerate(parent_descriptor.children, start=1): for position, child_location in enumerate(parent_descriptor.children, start=1):
if child_location == target_child_location: if unicode(child_location) == unicode(target_child_location):
# Only save if position changed # Only save if position changed
if position != parent_descriptor.position: if position != parent_descriptor.position:
parent_descriptor.position = position parent_descriptor.position = position
...@@ -332,6 +332,8 @@ class UsersList(SecureListAPIView): ...@@ -332,6 +332,8 @@ class UsersList(SecureListAPIView):
profile.save() profile.save()
UserPreference.set_preference(user, LANGUAGE_KEY, get_language()) UserPreference.set_preference(user, LANGUAGE_KEY, get_language())
if settings.FEATURES.get('ENABLE_DISCUSSION_EMAIL_DIGEST'):
enable_notifications(user)
# add this account creation to password history # add this account creation to password history
# NOTE, this will be a NOP unless the feature has been turned on in configuration # NOTE, this will be a NOP unless the feature has been turned on in configuration
...@@ -755,13 +757,17 @@ def _get_current_position_loc(parent_module): ...@@ -755,13 +757,17 @@ def _get_current_position_loc(parent_module):
An optimized lookup for the current position. The LMS version can cause unnecessary round trips to An optimized lookup for the current position. The LMS version can cause unnecessary round trips to
the Mongo database the Mongo database
""" """
if not hasattr(parent_module, 'position'): if not hasattr(parent_module, 'position'):
return None return None
if not parent_module.children: if not parent_module.children:
return None return None
index = 0 index = 0
if parent_module.position: if parent_module.position:
index = parent_module.position - 1 # position is 1 indexed index = parent_module.position - 1 # position is 1 indexed
...@@ -859,15 +865,11 @@ class UsersCoursesDetail(SecureAPIView): ...@@ -859,15 +865,11 @@ class UsersCoursesDetail(SecureAPIView):
response_data['position_tree'] = {} response_data['position_tree'] = {}
parent_module = course_module parent_module = course_module
while parent_module is not None: while parent_module is not None:
current_child_loc = _get_current_position_loc(parent_module) current_child_loc = _get_current_position_loc(parent_module)
if current_child_loc: if current_child_loc:
response_data['position_tree'][current_child_loc.category] = {} response_data['position_tree'][current_child_loc.category] = {}
response_data['position_tree'][current_child_loc.category]['id'] = unicode(current_child_loc) response_data['position_tree'][current_child_loc.category]['id'] = unicode(current_child_loc)
_,_,parent_module = get_course_child(request, user, course_key, unicode(current_child_loc), load_content=True) _,_,parent_module = get_course_child(request, user, course_key, unicode(current_child_loc), load_content=True)
else: else:
parent_module = None parent_module = None
return Response(response_data, status=status.HTTP_200_OK) return Response(response_data, status=status.HTTP_200_OK)
......
...@@ -693,8 +693,8 @@ def get_module_system_for_user(user, field_data_cache, # TODO # pylint: disabl ...@@ -693,8 +693,8 @@ def get_module_system_for_user(user, field_data_cache, # TODO # pylint: disabl
except (ValueError, TypeError): except (ValueError, TypeError):
log.exception('Non-integer %r passed as position.', position) log.exception('Non-integer %r passed as position.', position)
position = None position = None
system.set('position', position) system.set('position', position)
if settings.FEATURES.get('ENABLE_PSYCHOMETRICS') and user.is_authenticated(): if settings.FEATURES.get('ENABLE_PSYCHOMETRICS') and user.is_authenticated():
system.set( system.set(
'psychometrics_handler', # set callback for updating PsychometricsData 'psychometrics_handler', # set callback for updating PsychometricsData
......
...@@ -53,6 +53,8 @@ FEATURES['DISABLE_START_DATES'] = True ...@@ -53,6 +53,8 @@ FEATURES['DISABLE_START_DATES'] = True
# the one in cms/envs/test.py # the one in cms/envs/test.py
FEATURES['ENABLE_DISCUSSION_SERVICE'] = False FEATURES['ENABLE_DISCUSSION_SERVICE'] = False
FEATURES['ENABLE_DISCUSSION_EMAIL_DIGEST'] = True
FEATURES['ENABLE_SERVICE_STATUS'] = True FEATURES['ENABLE_SERVICE_STATUS'] = True
FEATURES['ENABLE_HINTER_INSTRUCTOR_VIEW'] = True FEATURES['ENABLE_HINTER_INSTRUCTOR_VIEW'] = True
......
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