def test_enrollment(self, mock_refresh, mock_edx_enr, mock_index): # pylint: disable=unused-argument
"""
Test for happy path
"""
cache_enr = CachedEnrollment.objects.filter(
user=self.user, course_run__edx_course_key=self.course_id).first()
assert cache_enr is None
enr_json = {'course_details': {'course_id': self.course_id}}
enrollment = Enrollment(enr_json)
mock_edx_enr.return_value = enrollment
resp = self.client.post(self.url, {'course_id': self.course_id}, format='json')
assert resp.status_code == status.HTTP_200_OK
assert mock_edx_enr.call_count == 1
assert mock_edx_enr.call_args[0][1] == self.course_id
assert resp.data == enr_json
mock_index.delay.assert_called_once_with([self.user.id], check_if_changed=True)
cache_enr = CachedEnrollment.objects.filter(
user=self.user, course_run__edx_course_key=self.course_id).first()
assert cache_enr is not None
评论列表
文章目录