def test_sibling(self, fixture, start_block, offset, expected_sibling_block): """Tests the _sibling method of the `CourseAPIPresenterMixin`.""" with mock.patch( 'analyticsclient.course.Course.videos', mock.Mock(return_value=utils.get_mock_video_data(fixture)) ): with mock.patch('slumber.Resource.get', mock.Mock(return_value=fixture.course_structure())): sibling = self.presenter.sibling_block(utils.get_encoded_module_id(start_block['id']), offset) if expected_sibling_block is None: self.assertIsNone(sibling) else: self.assertEqual(sibling['id'], utils.get_encoded_module_id(expected_sibling_block['id']))
def test_graded_modes(self, grade_status): """ Ensure that video structure will be retrieved for both graded and ungraded. """ course_structure_fixtures = self._create_graded_and_ungraded_course_structure_fixtures() course_fixture = course_structure_fixtures['course'] chapter_fixture = course_structure_fixtures['chapter'] with mock.patch('slumber.Resource.get', mock.Mock(return_value=course_fixture.course_structure())): with mock.patch('analyticsclient.course.Course.videos', mock.Mock(return_value=utils.get_mock_video_data(course_fixture))): # check that we get results for both graded and ungraded sequential_fixture = course_structure_fixtures[grade_status]['sequential'] video_id = sequential_fixture.children[0].children[0].id actual_videos = self.presenter.subsection_children(chapter_fixture.id, sequential_fixture.id) expected_url = reverse('courses:engagement:video_timeline', kwargs={ 'course_id': self.course_id, 'section_id': chapter_fixture.id, 'subsection_id': sequential_fixture.id, 'video_id': video_id }) expected = [{'id': utils.get_encoded_module_id(video_id), 'url': expected_url}] self.assertEqual(len(actual_videos), len(expected)) for index, actual_video in enumerate(actual_videos): self.assertDictContainsSubset(expected[index], actual_video)
def test_sibling_no_data(self): """ Verify that _sibling() skips over siblings with no data (no associated URL). """ fixture = CourseFixture().add_children(ChapterFixture().add_children( SequentialFixture().add_children(VerticalFixture().add_children( self.VIDEO_1, self.VIDEO_2, # self.VIDEO_2 will have no data self.VIDEO_3)))) with mock.patch( 'analyticsclient.course.Course.videos', mock.Mock(return_value=utils.get_mock_video_data( fixture, excluded_module_ids=[self.VIDEO_2['id']]))): with mock.patch( 'slumber.Resource.get', mock.Mock(return_value=fixture.course_structure())): sibling = self.presenter.sibling_block( utils.get_encoded_module_id(self.VIDEO_1['id']), 1) self.assertEqual( sibling['id'], utils.get_encoded_module_id(self.VIDEO_3['id']))
def test_sibling_no_data(self): """ Verify that _sibling() skips over siblings with no data (no associated URL). """ fixture = CourseFixture().add_children( ChapterFixture().add_children( SequentialFixture().add_children( VerticalFixture().add_children( self.VIDEO_1, self.VIDEO_2, # self.VIDEO_2 will have no data self.VIDEO_3 ) ) ) ) with mock.patch( 'analyticsclient.course.Course.videos', mock.Mock(return_value=utils.get_mock_video_data(fixture, excluded_module_ids=[self.VIDEO_2['id']])) ): with mock.patch('slumber.Resource.get', mock.Mock(return_value=fixture.course_structure())): sibling = self.presenter.sibling_block(utils.get_encoded_module_id(self.VIDEO_1['id']), 1) self.assertEqual(sibling['id'], utils.get_encoded_module_id(self.VIDEO_3['id']))