Ejemplo n.º 1
0
    def test_assertions_for_user(self):
        """
        Verify that grabbing all assertions for a user behaves as expected.

        This function uses object IDs because for some reason Jenkins trips up
        on its assertItemsEqual check here despite the items being equal.
        """
        user = UserFactory()
        assertions = [BadgeAssertionFactory.create(user=user).id for _i in range(3)]
        course = CourseFactory.create()
        course_key = course.location.course_key
        course_badges = [RandomBadgeClassFactory(course_id=course_key) for _i in range(3)]
        course_assertions = [
            BadgeAssertionFactory.create(user=user, badge_class=badge_class).id for badge_class in course_badges
        ]
        assertions.extend(course_assertions)
        assertions.sort()
        assertions_for_user = [badge.id for badge in BadgeAssertion.assertions_for_user(user)]
        assertions_for_user.sort()
        self.assertEqual(assertions_for_user, assertions)
        course_scoped_assertions = [
            badge.id for badge in BadgeAssertion.assertions_for_user(user, course_id=course_key)
        ]
        course_scoped_assertions.sort()
        self.assertEqual(course_scoped_assertions, course_assertions)
Ejemplo n.º 2
0
    def test_assertions_for_user(self):
        """
        Verify that grabbing all assertions for a user behaves as expected.

        This function uses object IDs because for some reason Jenkins trips up
        on its assertCountEqual check here despite the items being equal.
        """
        user = UserFactory()
        assertions = [BadgeAssertionFactory.create(user=user).id for _i in range(3)]
        course = CourseFactory.create()
        course_key = course.location.course_key
        course_badges = [RandomBadgeClassFactory(course_id=course_key) for _i in range(3)]
        course_assertions = [
            BadgeAssertionFactory.create(user=user, badge_class=badge_class).id for badge_class in course_badges
        ]
        assertions.extend(course_assertions)
        assertions.sort()
        assertions_for_user = [badge.id for badge in BadgeAssertion.assertions_for_user(user)]
        assertions_for_user.sort()
        self.assertEqual(assertions_for_user, assertions)
        course_scoped_assertions = [
            badge.id for badge in BadgeAssertion.assertions_for_user(user, course_id=course_key)
        ]
        course_scoped_assertions.sort()
        self.assertEqual(course_scoped_assertions, course_assertions)
Ejemplo n.º 3
0
    def _get_single_user_badge_progress(self, course_key, username=None):
        """

        """
        progress_response = []

        if not username:
            return progress_response
            # if 'username' in request.GET:
            #     username = request.GET.get('username')
            # else:
            #     username = request.user.username

        if not enrollment_data.get_course_enrollment(username,
                                                     str(course_key)):
            raise CourseEnrollment.DoesNotExist

        progress_user = USER_MODEL.objects.get(username=username)

        # Traverse through all course chapter blocks and check to see if a user has a badge assertion.
        for block_event_badge_config in BlockEventBadgesConfiguration.config_for_block_event(
                course_id=course_key, event_type='chapter_complete'):
            block_event_assertion = None
            if block_event_badge_config.badge_class:
                user_course_assertions = BadgeAssertion.assertions_for_user(
                    progress_user, course_id=course_key)
                for assertion in user_course_assertions:
                    if assertion.badge_class == block_event_badge_config.badge_class:
                        block_event_assertion = assertion
                        pass

            progress_response.append(
                self._make_badge_progress_response(course_key,
                                                   block_event_badge_config,
                                                   block_event_assertion))

        return progress_response