'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'

@ddt.data(True, False)
@override_settings(CERT_QUEUE='test-queue')
@patch('certificates.api.XQueueCertInterface', spec=True)
def test_clear_badge(self, issue_badges, xqueue):

    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)
    self._run_command(username=self.user.email, course=unicode(key), noop=False, insecure=False, template_file=None, grade_value=None)
    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))
