Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [ACI-938] display inline requirement groups #158

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion credentials/apps/badges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class BadgeRequirementInline(admin.TabularInline):
model = BadgeRequirement
show_change_link = True
extra = 0
fields = ("event_type", "rules", "description")
fields = (
"event_type",
"rules",
"description",
"group",
)
readonly_fields = ("rules",)

def rules(self, obj):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2024-04-24 09:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('badges', '0017_remove_badgeprogress_user_credential'),
]

operations = [
migrations.AlterField(
model_name='badgerequirement',
name='group',
field=models.CharField(blank=True, help_text='Optional. Put requirements into the same arbitrary Group ID to make them interchangeable (OR processing logic applies).', max_length=255, null=True),
),
]
4 changes: 1 addition & 3 deletions credentials/apps/badges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import operator
import uuid

from attrs import asdict
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel
Expand Down Expand Up @@ -168,7 +166,7 @@ class BadgeRequirement(models.Model):
null=True,
blank=True,
help_text=_(
"Optional. Requirements with identical Group ID become interchangeable (OR processing logic applies)."
"Optional. Put requirements into the same arbitrary Group ID to make them interchangeable (OR processing logic applies)."
),
)

Expand Down
1 change: 0 additions & 1 deletion credentials/apps/badges/processing/progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def discover_requirements(event_type: str) -> List[BadgeRequirement]:
return BadgeRequirement.objects.filter(event_type=event_type, template__is_active=True)



def process_requirements(event_type, username, payload):
"""
Finds all relevant requirements, tests them one by one, marks as completed if needed.
Expand Down
2 changes: 1 addition & 1 deletion credentials/apps/badges/processing/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def discover_penalties(event_type: str) -> List[BadgePenalty]:
"""
Picks all relevant penalties based on the event type.
"""

return BadgePenalty.objects.filter(event_type=event_type, template__is_active=True)


Expand Down
76 changes: 19 additions & 57 deletions credentials/apps/badges/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,8 @@ def setUp(self):
site=self.site,
is_active=True,
)
self.COURSE_PASSING_EVENT = (
"org.openedx.learning.course.passing.status.updated.v1"
)
self.CCX_COURSE_PASSING_EVENT = (
"org.openedx.learning.ccx.course.passing.status.updated.v1"
)
self.COURSE_PASSING_EVENT = "org.openedx.learning.course.passing.status.updated.v1"
self.CCX_COURSE_PASSING_EVENT = "org.openedx.learning.ccx.course.passing.status.updated.v1"

# test cases
# A course completion - course A w/o a group;
Expand Down Expand Up @@ -317,15 +313,9 @@ def test_course_a_or_b_completion(self):
"course": {"display_name": "A"},
}
process_requirements(self.COURSE_PASSING_EVENT, "test_username", kwargs)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_a).count(), 1
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_b).count(), 0
)
self.assertTrue(
BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed
)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_a).count(), 1)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_b).count(), 0)
self.assertTrue(BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed)

def test_course_a_or_b_or_c_completion(self):
requirement_a = BadgeRequirement.objects.create(
Expand Down Expand Up @@ -368,18 +358,10 @@ def test_course_a_or_b_or_c_completion(self):
"course": {"display_name": "A"},
}
process_requirements(self.COURSE_PASSING_EVENT, "test_username", kwargs)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_a).count(), 1
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_b).count(), 0
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_c).count(), 0
)
self.assertTrue(
BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed
)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_a).count(), 1)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_b).count(), 0)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_c).count(), 0)
self.assertTrue(BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed)

def test_course_a_or_completion(self):
requirement = BadgeRequirement.objects.create(
Expand All @@ -399,9 +381,7 @@ def test_course_a_or_completion(self):
}
process_requirements(self.COURSE_PASSING_EVENT, "test_username", kwargs)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement).count(), 1)
self.assertTrue(
BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed
)
self.assertTrue(BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed)

def test_course_a_or_b_and_c_completion(self):
requirement_a = BadgeRequirement.objects.create(
Expand Down Expand Up @@ -443,18 +423,10 @@ def test_course_a_or_b_and_c_completion(self):
"course": {"display_name": "A"},
}
process_requirements(self.COURSE_PASSING_EVENT, "test_username", kwargs)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_a).count(), 1
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_b).count(), 0
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_c).count(), 1
)
self.assertTrue(
BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed
)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_a).count(), 1)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_b).count(), 0)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_c).count(), 1)
self.assertTrue(BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed)

def test_course_a_or_b_and_c_or_d_completion(self):
requirement_a = BadgeRequirement.objects.create(
Expand Down Expand Up @@ -509,18 +481,8 @@ def test_course_a_or_b_and_c_or_d_completion(self):
"course": {"display_name": "A"},
}
process_requirements(self.COURSE_PASSING_EVENT, "test_username", kwargs)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_a).count(), 1
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_b).count(), 0
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_c).count(), 1
)
self.assertEqual(
Fulfillment.objects.filter(requirement=requirement_d).count(), 0
)
self.assertTrue(
BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed
)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_a).count(), 1)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_b).count(), 0)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_c).count(), 1)
self.assertEqual(Fulfillment.objects.filter(requirement=requirement_d).count(), 0)
self.assertTrue(BadgeProgress.for_user(username="test_username", template_id=self.badge_template.id).completed)
Loading