Example #1
0
 def test_success_v1(self):
     self.override_waffle_switch(True)
     self.login_and_enroll()
     submit_completions_for_testing(self.user, [self.unit.location])
     response = self.api_response(api_version=API_V1)
     self.assertEqual(response.data["last_visited_block_id"],
                      six.text_type(self.unit.location))
Example #2
0
 def test_success_v1(self):
     self.override_waffle_switch(True)
     self.login_and_enroll()
     submit_completions_for_testing(self.user, [self.unit.location])
     response = self.api_response(api_version=API_V1)
     assert response.data['last_visited_block_id'] == str(
         self.unit.location)
Example #3
0
 def test_resume_with_completion(self):
     self.override_waffle_switch(True)
     submit_completions_for_testing(self.user, [self.unit.location])
     response = self.client.get(self.url)
     assert response.status_code == 200
     assert response.data['block_id'] == str(self.unit.location)
     assert response.data['unit_id'] == str(self.unit.location)
     assert response.data['section_id'] == str(self.sequence.location)
Example #4
0
 def test_resume_invalid_key(self):
     """A resume key that does not exist should return null IDs (i.e. "redirect to first section")"""
     self.override_waffle_switch(True)
     submit_completions_for_testing(self.user, [self.course.id.make_usage_key('html', 'doesnotexist')])
     response = self.client.get(self.url)
     assert response.status_code == 200
     assert response.data['block_id'] is None
     assert response.data['unit_id'] is None
     assert response.data['section_id'] is None
    def test_completion_all_course_with_requested_fields_as_string(self):
        for block in self.non_orphaned_raw_block_usage_keys:
            submit_completions_for_testing(self.user, [block])

        response = self.verify_response(params={
            'depth': 'all',
            'requested_fields': 'completion,children',
        })
        for block_id in self.non_orphaned_block_usage_keys:
            assert response.data['blocks'][block_id].get('completion')
 def test_completion_all_course_with_nav_depth(self):
     # when we include nav_depth we get descendants in parent nodes
     for block in self.non_orphaned_raw_block_usage_keys:
         submit_completions_for_testing(self.user, [block])
     response = self.verify_response(params={
         'depth': 'all',
         'nav_depth': 3,
         'requested_fields': ['completion'],
     })
     for block_id in self.non_orphaned_block_usage_keys:
         assert response.data['blocks'][block_id].get('completion')
Example #7
0
    def test_resume_course_appears_on_dashboard(self):
        """
        When a course has completion data, its course card should display a
        "Resume Course" button.
        """
        self.override_waffle_switch(True)

        course = CourseFactory.create()
        CourseEnrollmentFactory.create(
            user=self.user,
            course_id=course.id
        )

        course_key = course.id
        block_keys = [
            ItemFactory.create(
                category='video',
                parent_location=course.location,
                display_name='Video {0}'.format(unicode(number))
            ).location
            for number in xrange(5)
        ]

        submit_completions_for_testing(self.user, course_key, block_keys)

        with patch('completion.utilities.visual_progress_enabled', return_value=True):
            response = self.client.get(reverse('dashboard'))

        course_key_string = str(course_key)
        resume_block_key_string = str(block_keys[-1])
        course_run_string = self._pull_course_run_from_course_key(course_key_string)

        view_button_html = self._get_html_for_view_course_button(
            course_key_string,
            course_run_string
        )
        resume_button_html = self._get_html_for_resume_course_button(
            course_key_string,
            resume_block_key_string,
            course_run_string
        )

        view_button_html = self._remove_whitespace_from_html_string(view_button_html)
        resume_button_html = self._remove_whitespace_from_html_string(resume_button_html)
        dashboard_html = self._remove_whitespace_from_html_string(response.content)

        self.assertIn(
            resume_button_html,
            dashboard_html
        )
        self.assertNotIn(
            view_button_html,
            dashboard_html
        )
    def test_completion_all_course_with_list_return_type(self):
        for block in self.non_orphaned_raw_block_usage_keys:
            submit_completions_for_testing(self.user, [block])

        response = self.verify_response(params={
            'depth': 'all',
            'return_type': 'list',
            'requested_fields': ['completion', 'children'],
        })
        for block in response.data:
            if block['block_id'] in self.non_orphaned_block_usage_keys:
                assert block.get('completion')
    def test_completion_one_unit(self):
        for item in self.store.get_items(self.course_key):
            if item.category == 'html':
                block_usage_key = item.location
                break

        submit_completions_for_testing(self.user, [block_usage_key])
        response = self.verify_response(params={
            'depth': 'all',
            'requested_fields': ['completion', 'children'],
        })

        completion = response.data['blocks'][str(block_usage_key)].get('completion')
        assert completion
Example #10
0
    def test_resume_course_appears_on_dashboard(self):
        """
        When a course has completion data, its course card should display a
        "Resume Course" button.
        """
        self.override_waffle_switch(True)

        course = CourseFactory.create()
        CourseEnrollmentFactory.create(
            user=self.user,
            course_id=course.id
        )

        course_key = course.id
        block_keys = [
            ItemFactory.create(
                category='video',
                parent_location=course.location,
                display_name='Video {0}'.format(six.text_type(number))
            ).location
            for number in range(5)
        ]

        submit_completions_for_testing(self.user, block_keys)

        response = self.client.get(reverse('dashboard'))

        course_key_string = str(course_key)
        resume_block_key_string = str(block_keys[-1])
        course_run_string = self._pull_course_run_from_course_key(course_key_string)

        view_button_html = self._get_html_for_view_course_button(
            course_key_string,
            course_run_string
        )
        resume_button_html = self._get_html_for_resume_course_button(
            course_key_string,
            resume_block_key_string,
            course_run_string
        )

        view_button_html = self._remove_whitespace_from_html_string(view_button_html)
        resume_button_html = self._remove_whitespace_from_html_string(resume_button_html)
        dashboard_html = self._remove_whitespace_from_response(response)

        assert resume_button_html in dashboard_html
        assert view_button_html not in dashboard_html
Example #11
0
    def setUp(self):
        super(BatchCompletionMethodTests, self).setUp()
        self.override_waffle_switch(True)

        self.user = UserFactory.create()
        self.other_user = UserFactory.create()
        self.course_key = CourseKey.from_string("edX/MOOC101/2049_T2")
        self.other_course_key = CourseKey.from_string(
            "course-v1:ReedX+Hum110+1904")
        self.block_keys = [
            UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number))
            for number in range(5)
        ]
        self.block_keys_with_runs = [
            key.replace(course_key=self.course_key) for key in self.block_keys
        ]
        self.other_course_block_keys = [
            self.other_course_key.make_usage_key('html', '1')
        ]

        # Submit completions for the main course:
        submit_completions_for_testing(self.user,
                                       self.block_keys_with_runs[:3])
        # Different user:
        submit_completions_for_testing(self.other_user,
                                       self.block_keys_with_runs[2:])
        # Different course:
        submit_completions_for_testing(self.user, self.other_course_block_keys)
Example #12
0
    def setUp(self):
        super(BatchCompletionMethodTests, self).setUp()
        self.override_waffle_switch(True)

        self.user = UserFactory.create()
        self.other_user = UserFactory.create()
        self.course_key = CourseKey.from_string("edX/MOOC101/2049_T2")
        self.other_course_key = CourseKey.from_string("course-v1:ReedX+Hum110+1904")
        self.block_keys = [UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in xrange(5)]

        submit_completions_for_testing(self.user, self.course_key, self.block_keys[:3])
        submit_completions_for_testing(self.other_user, self.course_key, self.block_keys[2:])
        submit_completions_for_testing(self.user, self.other_course_key, [self.block_keys[4]])
Example #13
0
    def test_dashboard_with_resume_buttons_and_view_buttons(self):
        '''
        The Test creates a four-course-card dashboard. The user completes course
        blocks in the even-numbered course cards. The test checks that courses
        with completion data have course cards with "Resume Course" buttons;
        those without have "View Course" buttons.

        '''
        self.override_waffle_switch(True)

        isEven = lambda n: n % 2 == 0

        num_course_cards = 4

        html_for_view_buttons = []
        html_for_resume_buttons = []
        html_for_entitlement = []

        for i in range(num_course_cards):

            course = CourseFactory.create()
            course_enrollment = CourseEnrollmentFactory(
                user=self.user,
                course_id=course.id
            )

            course_key = course_enrollment.course_id
            course_key_string = str(course_key)

            if i == 1:
                CourseEntitlementFactory.create(user=self.user, enrollment_course_run=course_enrollment)

            else:
                last_completed_block_string = ''
                course_run_string = self._pull_course_run_from_course_key(
                    course_key_string)

            # Submit completed course blocks in even-numbered courses.
            if isEven(i):
                block_keys = [
                    ItemFactory.create(
                        category='video',
                        parent_location=course.location,
                        display_name='Video {0}'.format(six.text_type(number))
                    ).location
                    for number in range(5)
                ]
                last_completed_block_string = str(block_keys[-1])

                submit_completions_for_testing(self.user, block_keys)

            html_for_view_buttons.append(
                self._get_html_for_view_course_button(
                    course_key_string,
                    course_run_string
                )
            )
            html_for_resume_buttons.append(
                self._get_html_for_resume_course_button(
                    course_key_string,
                    last_completed_block_string,
                    course_run_string
                )
            )
            html_for_entitlement.append(
                self._get_html_for_entitlement_button(
                    course_key_string
                )
            )

        response = self.client.get(reverse('dashboard'))

        html_for_view_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_view_buttons
        ]
        html_for_resume_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_resume_buttons
        ]
        html_for_entitlement = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_entitlement
        ]

        dashboard_html = self._remove_whitespace_from_response(response)

        for i in range(num_course_cards):
            expected_button = None
            unexpected_button = None

            if i == 1:
                expected_button = html_for_entitlement[i]
                unexpected_button = html_for_view_buttons[i] + html_for_resume_buttons[i]

            elif isEven(i):
                expected_button = html_for_resume_buttons[i]
                unexpected_button = html_for_view_buttons[i] + html_for_entitlement[i]
            else:
                expected_button = html_for_view_buttons[i]
                unexpected_button = html_for_resume_buttons[i] + html_for_entitlement[i]

            self.assertIn(
                expected_button,
                dashboard_html
            )
            self.assertNotIn(
                unexpected_button,
                dashboard_html
            )
Example #14
0
    def test_dashboard_with_resume_buttons_and_view_buttons(self):
        '''
        The Test creates a four-course-card dashboard. The user completes course
        blocks in the even-numbered course cards. The test checks that courses
        with completion data have course cards with "Resume Course" buttons;
        those without have "View Course" buttons.

        '''
        self.override_waffle_switch(True)

        isEven = lambda n: n % 2 == 0

        num_course_cards = 4

        html_for_view_buttons = []
        html_for_resume_buttons = []

        for i in range(num_course_cards):
            course = CourseFactory.create()
            course_enrollment = CourseEnrollmentFactory(user=self.user,
                                                        course_id=course.id)

            course_key = course_enrollment.course_id
            course_key_string = str(course_key)
            last_completed_block_string = ''
            course_run_string = self._pull_course_run_from_course_key(
                course_key_string)

            # Submit completed course blocks in even-numbered courses.
            if isEven(i):
                block_keys = [
                    course_key.make_usage_key('video', unicode(number))
                    for number in xrange(5)
                ]
                last_completed_block_string = str(block_keys[-1])

                submit_completions_for_testing(self.user, course_key,
                                               block_keys)

            html_for_view_buttons.append(
                self._get_html_for_view_course_button(course_key_string,
                                                      course_run_string))
            html_for_resume_buttons.append(
                self._get_html_for_resume_course_button(
                    course_key_string, last_completed_block_string,
                    course_run_string))

        with patch('completion.utilities.visual_progress_enabled',
                   return_value=True):
            response = self.client.get(reverse('dashboard'))

        html_for_view_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_view_buttons
        ]
        html_for_resume_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_resume_buttons
        ]
        dashboard_html = self._remove_whitespace_from_html_string(
            response.content)

        for i in range(num_course_cards):
            expected_button = None
            unexpected_button = None

            if isEven(i):
                expected_button = html_for_resume_buttons[i]
                unexpected_button = html_for_view_buttons[i]
            else:
                expected_button = html_for_view_buttons[i]
                unexpected_button = html_for_resume_buttons[i]

            self.assertIn(expected_button, dashboard_html)
            self.assertNotIn(unexpected_button, dashboard_html)
Example #15
0
    def test_dashboard_with_resume_buttons_and_view_buttons(self):
        '''
        The Test creates a four-course-card dashboard. The user completes course
        blocks in the even-numbered course cards. The test checks that courses
        with completion data have course cards with "Resume Course" buttons;
        those without have "View Course" buttons.

        '''
        self.override_waffle_switch(True)

        isEven = lambda n: n % 2 == 0

        num_course_cards = 4

        html_for_view_buttons = []
        html_for_resume_buttons = []
        html_for_entitlement = []

        for i in range(num_course_cards):

            course = CourseFactory.create()
            course_enrollment = CourseEnrollmentFactory(
                user=self.user,
                course_id=course.id
            )

            course_key = course_enrollment.course_id
            course_key_string = str(course_key)

            if i == 1:
                CourseEntitlementFactory.create(user=self.user, enrollment_course_run=course_enrollment)

            else:
                last_completed_block_string = ''
                course_run_string = self._pull_course_run_from_course_key(
                    course_key_string)

            # Submit completed course blocks in even-numbered courses.
            if isEven(i):
                block_keys = [
                    ItemFactory.create(
                        category='video',
                        parent_location=course.location,
                        display_name='Video {0}'.format(six.text_type(number))
                    ).location
                    for number in range(5)
                ]
                last_completed_block_string = str(block_keys[-1])

                submit_completions_for_testing(self.user, course_key, block_keys)

            html_for_view_buttons.append(
                self._get_html_for_view_course_button(
                    course_key_string,
                    course_run_string
                )
            )
            html_for_resume_buttons.append(
                self._get_html_for_resume_course_button(
                    course_key_string,
                    last_completed_block_string,
                    course_run_string
                )
            )
            html_for_entitlement.append(
                self._get_html_for_entitlement_button(
                    course_key_string
                )
            )

        response = self.client.get(reverse('dashboard'))

        html_for_view_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_view_buttons
        ]
        html_for_resume_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_resume_buttons
        ]
        html_for_entitlement = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_entitlement
        ]

        dashboard_html = self._remove_whitespace_from_html_string(response.content)

        for i in range(num_course_cards):
            expected_button = None
            unexpected_button = None

            if i == 1:
                expected_button = html_for_entitlement[i]
                unexpected_button = html_for_view_buttons[i] + html_for_resume_buttons[i]

            elif isEven(i):
                expected_button = html_for_resume_buttons[i]
                unexpected_button = html_for_view_buttons[i] + html_for_entitlement[i]
            else:
                expected_button = html_for_view_buttons[i]
                unexpected_button = html_for_resume_buttons[i] + html_for_entitlement[i]

            self.assertIn(
                expected_button,
                dashboard_html
            )
            self.assertNotIn(
                unexpected_button,
                dashboard_html
            )