def test_get_course_completions_no_grade_record(self): """ Make sure get_course_completions works as expected """ # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command user = factories.UserFactory() enterprise_course_enrollments = [mock.Mock(id=42, user_id=user.id)] Command.get_course_completions(enterprise_course_enrollments)
def test_get_xapi_transmission_queryset(self, mock_transmission_audit): """ Make sure operation works as expected. """ # Import is placed here because if placed at the top it affects mocking. # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command enterprise_enrollment_ids = [2, 24, 632] Command.get_xapi_transmission_queryset(enterprise_enrollment_ids) assert mock_transmission_audit.objects.filter.called
def test_get_object_type(self): """ Make sure get_object_type logic works as expected. """ # Import is placed here because if placed at the top it affects mocking. # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command xapi_transmission = mock.Mock(course_id='edX+DemoX') assert Command.get_object_type(xapi_transmission) == ContentType.COURSE xapi_transmission = mock.Mock(course_id='course-v1:edX+DemoX+Demo_Course') assert Command.get_object_type(xapi_transmission) == ContentType.COURSE_RUN
def test_get_pertinent_enrollment_ids(self): """ Make sure operation works as expected. """ # Import is placed here because if placed at the top it affects mocking. # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command mock_transmission_queryset = mock.MagicMock(return_value=[mock.Mock( id=1234, enterprise_course_enrollment_id=23243, course_id='course-v1:edX+DemoX+Demo_Course' )]) Command.get_pertinent_enrollment_ids(mock_transmission_queryset)
def test_get_course_completions(self, mock_persistent_course_grade): """ Make sure get_course_completions works as expected """ # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command user = factories.UserFactory() enterprise_course_enrollments = [mock.Mock(id=42, user_id=user.id)] Command.get_course_completions(enterprise_course_enrollments) assert mock_persistent_course_grade.objects.filter.called mock_persistent_course_grade.objects.filter.return_value = mock.MagicMock( ) Command.get_course_completions(enterprise_course_enrollments)
def test_prefetch_users(self): """ Make sure prefetch_users method works as expected. """ # Import is placed here because if placed at the top it affects mocking. from integrated_channels.xapi.management.commands.send_course_completions import Command user = factories.UserFactory() expected = {user.id: user} assert Command.prefetch_users([mock.Mock(user_id=user.id)]) == expected
def test_prefetch_users(self): """ Make sure prefetch_users method works as expected. """ # Import is placed here because if placed at the top it affects mocking. # pylint: disable=import-outside-toplevel from integrated_channels.xapi.management.commands.send_course_completions import Command user = factories.UserFactory() enrollment_grades = {42: mock.Mock(user_id=user.id)} expected = {user.id: user} assert Command.prefetch_users(enrollment_grades) == expected