def setUp(self):
     super(CourseEngagementVideoMixin, self).setUp()
     self.factory = CourseEngagementDataFactory()
     self.sections = self.factory.presented_sections
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.sections',
         return_value=self.sections)
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.section',
         return_value=self.sections[0])
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.subsections',
         return_value=self.sections[0]['children'])
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.subsection',
         return_value=self.sections[0]['children'][0])
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_children',
         return_value=self.sections[0]['children'][0]['children'])
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.get_video_timeline',
         return_value=self.factory.get_presented_video_timeline())
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.block',
         return_value=self.sections[0]['children'][0]['children'][0])
     self._patch(
         'courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_child',
         return_value=self.sections[0]['children'][0]['children'][0])
     self.start_patching()
    def test_fetch_course_module_data(self, mock_videos):
        factory = CourseEngagementDataFactory()
        videos = factory.videos()
        mock_videos.return_value = videos
        self.assertListEqual(self.presenter.fetch_course_module_data(), videos)

        mock_videos.side_effect = NoVideosError(course_id=self.course_id)
        with self.assertRaises(NoVideosError):
            self.presenter.fetch_course_module_data()
    def test_get_video_timeline(self, mock_timeline):
        factory = CourseEngagementDataFactory()
        video_module = {
            'pipeline_video_id': 'edX/DemoX/Demo_Course|i4x-edX-DemoX-videoalpha-0b9e39477cf34507a7a48f74be381fdd',
            'segment_length': 5,
            'duration': None
        }
        # duration can be null/None
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        expected_timeline = factory.get_presented_video_timeline(duration=495)
        self.assertEqual(100, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)

        video_module['duration'] = 499
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        last_segment = expected_timeline[-1].copy()
        last_segment.update({
            'segment': last_segment['segment'] + 1,
            'start_time': video_module['duration']
        })
        expected_timeline.append(last_segment)
        self.assertEqual(101, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)

        video_module['duration'] = 501
        expected_timeline[-1].update({
            'start_time': 500,
            'num_users': 0,
            'num_views': 0,
            'num_replays': 0
        })
        last_segment = expected_timeline[-1].copy()
        last_segment.update({
            'segment': last_segment['segment'] + 1,
            'start_time': video_module['duration']
        })
        expected_timeline.append(last_segment)
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        self.assertEqual(102, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)
Esempio n. 4
0
class CourseEngagementVideoMixin(CourseEngagementViewTestMixin, CourseStructureViewMixin):
    active_secondary_nav_label = 'Video'
    sections = None

    def get_expected_secondary_nav(self, course_id):
        expected = super(CourseEngagementVideoMixin, self).get_expected_secondary_nav(course_id)
        expected[0].update({
            'href': reverse('courses:engagement:content', kwargs={'course_id': course_id}),
            'active': False
        })
        return expected

    @httpretty.activate
    def test_invalid_course(self):
        self._test_invalid_course('course_structures/{}/')

    def setUp(self):
        super(CourseEngagementVideoMixin, self).setUp()
        self.factory = CourseEngagementDataFactory()
        self.sections = self.factory.presented_sections
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.sections',
                    return_value=self.sections)
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.section',
                    return_value=self.sections[0])
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsections',
                    return_value=self.sections[0]['children'])
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection',
                    return_value=self.sections[0]['children'][0])
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_children',
                    return_value=self.sections[0]['children'][0]['children'])
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.get_video_timeline',
                    return_value=self.factory.get_presented_video_timeline())
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.block',
                    return_value=self.sections[0]['children'][0]['children'][0])
        self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_child',
                    return_value=self.sections[0]['children'][0]['children'][0])
        self.start_patching()

    def assertValidContext(self, context):
        expected = {
            'sections': self.sections,
        }
        self.assertDictContainsSubset(expected, context)

    @httpretty.activate
    @patch('courses.presenters.engagement.CourseEngagementVideoPresenter.sections', Mock(return_value=dict()))
    def test_missing_sections(self):
        """ Every video page will use sections and will return 200 if sections aren't available. """
        self.mock_course_detail(DEMO_COURSE_ID)
        response = self.client.get(self.path(course_id=DEMO_COURSE_ID))
        # base page will should return a 200 even if no sections found
        self.assertEqual(response.status_code, 200)
 def setUp(self):
     super(CourseEngagementVideoMixin, self).setUp()
     self.factory = CourseEngagementDataFactory()
     self.sections = self.factory.presented_sections
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.sections',
                 return_value=self.sections)
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.section',
                 return_value=self.sections[0])
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsections',
                 return_value=self.sections[0]['children'])
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection',
                 return_value=self.sections[0]['children'][0])
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_children',
                 return_value=self.sections[0]['children'][0]['children'])
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.get_video_timeline',
                 return_value=self.factory.get_presented_video_timeline())
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.block',
                 return_value=self.sections[0]['children'][0]['children'][0])
     self._patch('courses.presenters.engagement.CourseEngagementVideoPresenter.subsection_child',
                 return_value=self.sections[0]['children'][0]['children'][0])
     self.start_patching()
Esempio n. 6
0
    def test_get_video_timeline(self, mock_timeline):
        factory = CourseEngagementDataFactory()
        video_module = {
            'pipeline_video_id':
            'edX/DemoX/Demo_Course|i4x-edX-DemoX-videoalpha-0b9e39477cf34507a7a48f74be381fdd',
            'segment_length': 5,
            'duration': None
        }
        # duration can be null/None
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        expected_timeline = factory.get_presented_video_timeline(duration=495)
        self.assertEqual(100, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)

        video_module['duration'] = 499
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        last_segment = expected_timeline[-1].copy()
        last_segment.update({
            'segment': last_segment['segment'] + 1,
            'start_time': video_module['duration']
        })
        expected_timeline.append(last_segment)
        self.assertEqual(101, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)

        video_module['duration'] = 501
        expected_timeline[-1].update({
            'start_time': 500,
            'num_users': 0,
            'num_views': 0,
            'num_replays': 0
        })
        last_segment = expected_timeline[-1].copy()
        last_segment.update({
            'segment': last_segment['segment'] + 1,
            'start_time': video_module['duration']
        })
        expected_timeline.append(last_segment)
        mock_timeline.return_value = factory.get_video_timeline_api_response()
        actual_timeline = self.presenter.get_video_timeline(video_module)
        self.assertEqual(102, len(actual_timeline))
        self.assertTimeline(expected_timeline, actual_timeline)