Skip to content

Commit

Permalink
fix: [ACI-987] fix penalties not revoking
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii committed May 20, 2024
1 parent ece7c9a commit e4d0166
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion credentials/apps/badges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def reset(self, username: str):
requirement=self,
progress__username=username,
).first()
deleted, __ = fulfillment.delete()
deleted, __ = fulfillment.delete() if fulfillment else (False, 0)
if deleted:
notify_requirement_regressed(
sender=self,
Expand Down
10 changes: 8 additions & 2 deletions credentials/apps/badges/signals/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ def notify_requirement_fulfilled(*, sender, username, badge_template_id, **kwarg

def notify_requirement_regressed(*, sender, username, badge_template_id):
"""
FIXME: implement/use
Notifies about user's regression on the badge template.
"""

BADGE_REQUIREMENT_REGRESSED.send(
sender=sender,
username=username,
badge_template_id=badge_template_id,
)


def notify_progress_complete(sender, username, badge_template_id):
"""
Expand All @@ -55,7 +61,7 @@ def notify_progress_complete(sender, username, badge_template_id):

def notify_progress_incomplete(sender, username, badge_template_id):
"""
FIXME: implement/use
Notifies about user's regression on the badge template.
"""
BADGE_PROGRESS_INCOMPLETE.send(
sender=sender,
Expand Down
33 changes: 30 additions & 3 deletions credentials/apps/badges/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CredlyOrganization,
)
from credentials.apps.badges.issuers import CredlyBadgeTemplateIssuer
from credentials.apps.badges.signals.signals import BADGE_PROGRESS_COMPLETE
from credentials.apps.badges.signals.signals import BADGE_PROGRESS_COMPLETE, BADGE_PROGRESS_INCOMPLETE


class BadgeSignalReceiverTestCase(TestCase):
Expand All @@ -24,7 +24,7 @@ def setUp(self):
name="test", site_id=1, organization=credly_organization
)

def test_signal_emission_and_receiver_execution(self):
def test_progression_signal_emission_and_receiver_execution(self):
# Emit the signal
with mock.patch("credentials.apps.badges.issuers.notify_badge_awarded"):
with mock.patch.object(CredlyBadgeTemplateIssuer, "issue_credly_badge"):
Expand All @@ -37,7 +37,9 @@ def test_signal_emission_and_receiver_execution(self):
# UserCredential object
user_credential = CredlyBadge.objects.filter(
username="test_user",
credential_content_type=ContentType.objects.get_for_model(self.badge_template),
credential_content_type=ContentType.objects.get_for_model(
self.badge_template
),
credential_id=self.badge_template.id,
)

Expand All @@ -46,3 +48,28 @@ def test_signal_emission_and_receiver_execution(self):

# Check if user credential status is 'awarded'
self.assertTrue(user_credential[0].status == "awarded")

def test_regression_signal_emission_and_receiver_execution(self):
# Emit the signal
with mock.patch("credentials.apps.badges.issuers.notify_badge_revoked"):
with mock.patch.object(CredlyBadgeTemplateIssuer, "revoke_credly_badge"):
BADGE_PROGRESS_INCOMPLETE.send(
sender=self,
username="test_user",
badge_template_id=self.badge_template.id,
)

# UserCredential object
user_credential = CredlyBadge.objects.filter(
username="test_user",
credential_content_type=ContentType.objects.get_for_model(
self.badge_template
),
credential_id=self.badge_template.id,
)

# Check if user credential is created
self.assertTrue(user_credential.exists())

# Check if user credential status is 'revoked'
self.assertTrue(user_credential[0].status == "revoked")

0 comments on commit e4d0166

Please sign in to comment.