Skip to content

Commit

Permalink
test: [AXM-53] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Mar 29, 2024
1 parent 89acefe commit bc2403e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion lms/djangoapps/mobile_api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ class CourseEnrollmentSerializerModifiedForPrimary(CourseEnrollmentSerializer):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# import pdb; pdb.set_trace()
self.course = modulestore().get_course(self.instance.course.id)

def get_course_status(self, model: CourseEnrollment) -> Optional[Dict[str, List[str]]]:
Expand Down
25 changes: 18 additions & 7 deletions lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def test_student_dont_have_enrollments(self):
'configs': {
'iap_configs': {}
},
'user_timezone': 'UTC',
'enrollments': {
'next': None,
'previous': None,
Expand All @@ -434,7 +435,8 @@ def test_student_dont_have_enrollments(self):
self.assertDictEqual(expected_result, response.data)
self.assertNotIn('primary', response.data)

def test_student_have_one_enrollment(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_student_have_one_enrollment(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand All @@ -458,7 +460,8 @@ def test_student_have_one_enrollment(self):
self.assertIn('primary', response.data)
self.assertEqual(str(course.id), response.data['primary']['course']['id'])

def test_student_have_two_enrollments(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_student_have_two_enrollments(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand All @@ -477,7 +480,8 @@ def test_student_have_two_enrollments(self):
self.assertIn('primary', response.data)
self.assertEqual(response.data['primary']['course']['id'], str(course_second.id))

def test_student_have_more_then_ten_enrollments(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_student_have_more_then_ten_enrollments(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand All @@ -497,7 +501,8 @@ def test_student_have_more_then_ten_enrollments(self):
self.assertIn('primary', response.data)
self.assertEqual(response.data['primary']['course']['id'], str(latest_enrolment.id))

def test_student_have_progress_in_old_course_and_enroll_newest_course(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_student_have_progress_in_old_course_and_enroll_newest_course(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand Down Expand Up @@ -559,6 +564,7 @@ def test_student_enrolled_only_not_mobile_available_courses(self):
"configs": {
"iap_configs": {}
},
"user_timezone": "UTC",
"enrollments": {
"next": None,
"previous": None,
Expand All @@ -576,7 +582,8 @@ def test_student_enrolled_only_not_mobile_available_courses(self):
self.assertDictEqual(expected_result, response.data)
self.assertNotIn('primary', response.data)

def test_do_progress_in_not_mobile_available_course(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_do_progress_in_not_mobile_available_course(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand Down Expand Up @@ -613,7 +620,8 @@ def test_do_progress_in_not_mobile_available_course(self):
self.assertIn('primary', response.data)
self.assertEqual(response.data['primary']['course']['id'], str(new_course.id))

def test_pagination_for_user_enrollments_api_v4(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_pagination_for_user_enrollments_api_v4(self, cache_mock: MagicMock):
"""
Tests `UserCourseEnrollmentsV4Pagination`, api_version == v4.
"""
Expand All @@ -632,7 +640,8 @@ def test_pagination_for_user_enrollments_api_v4(self):
self.assertIn('previous', response.data['enrollments'])
self.assertIn('primary', response.data)

def test_course_status_in_primary_obj_when_student_doesnt_have_progress(self):
@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
def test_course_status_in_primary_obj_when_student_doesnt_have_progress(self, cache_mock: MagicMock):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
"""
Expand All @@ -645,10 +654,12 @@ def test_course_status_in_primary_obj_when_student_doesnt_have_progress(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['primary']['course_status'], None)

@patch('lms.djangoapps.mobile_api.users.serializers.cache.set', return_value=None)
@patch('lms.djangoapps.mobile_api.users.serializers.get_key_to_last_completed_block')
def test_course_status_in_primary_obj_when_student_have_progress(
self,
get_last_completed_block_mock: MagicMock,
cache_mock: MagicMock
):
"""
Testing modified `UserCourseEnrollmentsList` view with api_version == v4.
Expand Down

0 comments on commit bc2403e

Please sign in to comment.