Commit c4ae6404 by Matt Drayer

mattdrayer/rebase-20140916: Initial test fixes

parent 68610ec1
......@@ -144,7 +144,7 @@ class LocationKeyField(models.CharField):
if isinstance(value, basestring):
try:
UsageKey.from_string(value)
return UsageKey.from_string(value)
except InvalidKeyError:
return Location.from_deprecated_string(value)
else:
......
......@@ -1743,7 +1743,7 @@ class CoursesApiTests(TestCase):
response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200)
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
test_uri = '{}/{}/metrics/completions/leaders/?user_id={}'.format(self.base_courses_uri, self.test_course_id,
......@@ -1752,7 +1752,7 @@ class CoursesApiTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['leaders']), 3)
self.assertEqual(response.data['position'], 2)
self.assertEqual(response.data['completions'], 28)
self.assertEqual(response.data['completions'], 19)
# with skipleaders filter
test_uri = '{}/{}/metrics/completions/leaders/?user_id={}&skipleaders=true'.format(self.base_courses_uri,
......@@ -1762,7 +1762,7 @@ class CoursesApiTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertIsNone(response.data.get('leaders', 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_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):
nodes = []
verticals = get_modulestore().get_items(course_key, category='vertical')
for vertical in verticals:
nodes.extend([unit for unit in vertical.children
if getattr(unit, 'category') not in detached_categories])
if hasattr(vertical, 'children'):
nodes.extend([unit for unit in vertical.children
if getattr(unit, 'category') not in detached_categories])
return nodes
......
......@@ -93,7 +93,9 @@ class UsersApiTests(TestCase):
self.course = CourseFactory.create(
display_name="TEST COURSE",
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(
category="videosequence",
......@@ -102,7 +104,7 @@ class UsersApiTests(TestCase):
due=datetime(2016, 5, 16, 14, 30),
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(
category="videosequence",
parent_location=self.course2.location,
......@@ -737,7 +739,7 @@ class UsersApiTests(TestCase):
self.assertTrue(response.data['is_active'])
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
user_id = '234234'
test_uri = '{}/{}/courses'.format(test_uri, str(user_id))
......@@ -774,7 +776,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 201)
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)}
response = self.do_post(test_uri, data)
self.assertEqual(response.status_code, 201)
......@@ -797,7 +799,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
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()))
chapter1 = ItemFactory.create(
category="chapter",
......@@ -892,7 +894,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
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()))
chapter1 = ItemFactory.create(
category="chapter",
......@@ -916,7 +918,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
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()))
chapter1 = ItemFactory.create(
category="chapter",
......@@ -965,7 +967,13 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 400)
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()))
chapter1 = ItemFactory.create(
category="chapter",
......@@ -990,6 +998,8 @@ class UsersApiTests(TestCase):
self.assertEqual(response.data['uri'], confirm_uri)
self.assertEqual(response.data['course_id'], unicode(course.id))
self.assertEqual(response.data['user_id'], user_id)
# Now add the user's position in the course
position_data = {
'positions': [
{
......@@ -1016,7 +1026,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
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
local_username = self.test_username + str(randint(11, 99))
data = {'email': self.test_email, 'username': local_username, 'password':
......@@ -1028,7 +1038,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
def test_user_courses_detail_delete(self):
course = CourseFactory.create()
course = CourseFactory.create(org='TUCDD', run='TUCDD1')
test_uri = self.users_base_uri
local_username = self.test_username + str(randint(11, 99))
data = {'email': self.test_email, 'username': local_username, 'password':
......@@ -1057,7 +1067,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
def test_user_courses_detail_delete_undefined_user(self):
course = CourseFactory.create()
course = CourseFactory.create(org='TUCDDUU', run='TUCDDUU1')
user_id = '2134234'
test_uri = '{}/{}/courses/{}'.format(self.users_base_uri, user_id, course.id)
response = self.do_delete(test_uri)
......@@ -1074,7 +1084,7 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 404)
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)
response = self.do_get(test_uri)
self.assertEqual(response.status_code, 404)
......@@ -1091,8 +1101,9 @@ class UsersApiTests(TestCase):
test_uri = '{}/{}/preferences'.format(self.users_base_uri, user_id)
response = self.do_get(test_uri)
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.assertIsNotNone(response.data['notification_pref'])
def test_user_preferences_list_post_user_not_found(self):
test_uri = '{}/{}/preferences'.format(self.users_base_uri, '999999')
......@@ -1121,7 +1132,8 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 201)
response = self.do_get(test_uri)
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['foo'], 'bar')
......@@ -1134,7 +1146,8 @@ class UsersApiTests(TestCase):
self.assertEqual(response.status_code, 200)
response = self.do_get(test_uri)
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['foo'], 'updated')
......@@ -1174,7 +1187,7 @@ class UsersApiTests(TestCase):
def test_user_courses_grades_list_get(self):
user_id = self.user.id
course = CourseFactory.create()
course = CourseFactory.create(org='TUCGLG', run='TUCGLG1')
test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
chapter1 = ItemFactory.create(
category="chapter",
......@@ -1340,8 +1353,6 @@ class UsersApiTests(TestCase):
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))
response = self.do_get(test_uri)
......@@ -1358,7 +1369,7 @@ class UsersApiTests(TestCase):
self.assertEqual(sections[0]['graded'], False)
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]['graded'], False)
......@@ -1368,7 +1379,7 @@ class UsersApiTests(TestCase):
self.assertGreater(len(grading_policy['GRADER']), 0)
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)
def is_user_profile_created_updated(self, response, data):
......@@ -1581,13 +1592,17 @@ class UsersApiTests(TestCase):
course2 = CourseFactory.create(
display_name="TEST COURSE2",
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')
course3 = CourseFactory.create(
display_name="TEST COURSE3",
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')
test_uri = '{}/{}/roles/'.format(self.users_base_uri, self.user.id)
......@@ -1666,7 +1681,9 @@ class UsersApiTests(TestCase):
course2 = CourseFactory.create(
display_name="TEST COURSE2",
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(
name=FORUM_ROLE_MODERATOR,
......@@ -1675,7 +1692,9 @@ class UsersApiTests(TestCase):
course3 = CourseFactory.create(
display_name="TEST COURSE3",
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(
name=FORUM_ROLE_MODERATOR,
......@@ -1684,7 +1703,9 @@ class UsersApiTests(TestCase):
course4 = CourseFactory.create(
display_name="COURSE4 NO MODERATOR",
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)
......
......@@ -24,7 +24,10 @@ from instructor.access import revoke_access, update_forum_role
from lang_pref import LANGUAGE_KEY
from lms.lib.comment_client.user import User as CommentUser
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.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, CourseAssistantRole, UserBasedRole
from user_api.models import UserPreference
......@@ -33,9 +36,11 @@ from util.password_policy_validators import (
validate_password_length, validate_password_complexity,
validate_password_dictionary
)
from xmodule.modulestore import InvalidLocationError
from xmodule.modulestore.django import modulestore
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.models import GroupProfile, APIUser as User
from api_manager.organizations.serializers import OrganizationSerializer
......@@ -43,12 +48,7 @@ from api_manager.utils import generate_base_uri, dict_has_items, extract_data_pa
from projects.serializers import BasicWorkgroupSerializer
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__)
AUDIT_LOG = logging.getLogger("audit")
......@@ -122,7 +122,7 @@ def _save_child_position(parent_descriptor, target_child_location):
we just compare id's from the array of children
"""
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
if position != parent_descriptor.position:
parent_descriptor.position = position
......@@ -333,6 +333,8 @@ class UsersList(SecureListAPIView):
profile.save()
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
# NOTE, this will be a NOP unless the feature has been turned on in configuration
......@@ -756,13 +758,17 @@ def _get_current_position_loc(parent_module):
An optimized lookup for the current position. The LMS version can cause unnecessary round trips to
the Mongo database
"""
if not hasattr(parent_module, 'position'):
return None
if not parent_module.children:
return None
index = 0
if parent_module.position:
index = parent_module.position - 1 # position is 1 indexed
......@@ -859,15 +865,11 @@ class UsersCoursesDetail(SecureAPIView):
response_data['position_tree'] = {}
parent_module = course_module
while parent_module is not None:
current_child_loc = _get_current_position_loc(parent_module)
if current_child_loc:
response_data['position_tree'][current_child_loc.category] = {}
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)
else:
parent_module = None
return Response(response_data, status=status.HTTP_200_OK)
......
......@@ -580,8 +580,8 @@ def get_module_system_for_user(user, field_data_cache,
except (ValueError, TypeError):
log.exception('Non-integer %r passed as position.', position)
position = None
system.set('position', position)
if settings.FEATURES.get('ENABLE_PSYCHOMETRICS') and user.is_authenticated():
system.set(
'psychometrics_handler', # set callback for updating PsychometricsData
......
......@@ -36,6 +36,8 @@ FEATURES['DISABLE_START_DATES'] = True
# the one in cms/envs/test.py
FEATURES['ENABLE_DISCUSSION_SERVICE'] = False
FEATURES['ENABLE_DISCUSSION_EMAIL_DIGEST'] = True
FEATURES['ENABLE_SERVICE_STATUS'] = 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