Commit 0de4f601 by Matt Drayer Committed by Jonathan Piacenti

mattdrayer/rebase-20140916: Initial test fixes

parent 6454290f
......@@ -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
......
......@@ -23,7 +23,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 openedx.core.djangoapps.user_api.models import UserPreference
from student.roles import CourseAccessRole, CourseInstructorRole, CourseObserverRole, CourseStaffRole, CourseAssistantRole, UserBasedRole
......@@ -32,9 +35,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
......@@ -42,12 +47,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")
......@@ -121,7 +121,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
......@@ -332,6 +332,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
......@@ -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
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)
......
......@@ -693,8 +693,8 @@ def get_module_system_for_user(user, field_data_cache, # TODO # pylint: disabl
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
......
......@@ -53,6 +53,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