Exemplo n.º 1
0
 def test_get_assertions(self):
     """
     Verify we can get all of a user's badge assertions.
     """
     for dummy in range(3):
         BadgeAssertionFactory(user=self.user)
     # Add in a course scoped badge-- these should not be excluded from the full listing.
     BadgeAssertionFactory(user=self.user, badge_class=BadgeClassFactory(course_id=self.course.location.course_key))
     # Should not be included.
     for dummy in range(3):
         self.create_badge_class(False)
     response = self.get_json(self.url())
     self.assertEqual(len(response['results']), 4)
    def test_clear_badge(self, issue_badges, xqueue):
        """
        Given that I have a user with a badge
        If I run regeneration for a user
        Then certificate generation will be requested
        And the badge will be deleted if badge issuing is enabled
        """
        key = self.course.location.course_key
        self._create_cert(key, self.user, CertificateStatuses.downloadable)
        badge_class = get_completion_badge(key, self.user)
        BadgeAssertionFactory(badge_class=badge_class, user=self.user)
        self.assertTrue(
            BadgeAssertion.objects.filter(user=self.user,
                                          badge_class=badge_class))
        self.course.issue_badges = issue_badges
        self.store.update_item(self.course, None)

        args = u'-u {} -c {}'.format(self.user.email, text_type(key))
        call_command(self.command, *args.split(' '))

        xqueue.return_value.regen_cert.assert_called_with(self.user,
                                                          key,
                                                          course=self.course,
                                                          forced_grade=None,
                                                          template_file=None,
                                                          generate_pdf=True)
        self.assertEquals(
            bool(
                BadgeAssertion.objects.filter(user=self.user,
                                              badge_class=badge_class)),
            not issue_badges)