Skip to content

Commit

Permalink
docs: polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Hantkovskyi committed Jun 17, 2024
1 parent ecdeef0 commit 79a447d
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .annotation_safe_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ auth.Permission:
badges.BadgePenalty:
".. no_pii:": "This model has no PII"
badges.BadgeProgress:
".. no_pii:": "This model has no PII"
".. pii": "Username"
".. pii_types": other
".. pii_retirement": retained
badges.BadgeRequirement:
".. no_pii:": "This model has no PII"
badges.CredlyOrganization:
Expand Down
218 changes: 206 additions & 12 deletions credentials/apps/badges/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CredlyOrganization,
DataRule,
Fulfillment,
PenaltyDataRule,
)
from credentials.apps.core.models import User

Expand All @@ -29,7 +30,11 @@ def setUp(self):
)
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization, uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)
self.requirement = BadgeRequirement.objects.create(
template=self.badge_template,
Expand Down Expand Up @@ -68,7 +73,8 @@ def setUp(self):
uuid=uuid.uuid4(), name="test_template2", state="draft", site=self.site
)
self.badge_requirement = BadgeRequirement.objects.create(
template=self.badge_template1, event_type="org.openedx.learning.course.passing.status.updated.v1"
template=self.badge_template1,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)
self.data_rule1 = DataRule.objects.create(
requirement=self.badge_requirement,
Expand Down Expand Up @@ -103,7 +109,11 @@ def setUp(self):
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.credlybadge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization, uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)

self.requirement1 = BadgeRequirement.objects.create(
Expand Down Expand Up @@ -154,7 +164,9 @@ def test_fulfill(self):
with patch("credentials.apps.badges.models.notify_requirement_fulfilled") as mock_notify:
created = self.requirement.fulfill(username)
fulfillment = Fulfillment.objects.get(
progress=progress, requirement=self.requirement, blend=self.requirement.blend
progress=progress,
requirement=self.requirement,
blend=self.requirement.blend,
)

self.assertTrue(created)
Expand All @@ -166,6 +178,13 @@ def test_fulfill(self):
fulfillment_id=fulfillment.id,
)

def test_is_active(self):
self.requirement.template.is_active = True
self.assertTrue(self.requirement.is_active)

self.requirement.template.is_active = False
self.assertFalse(self.requirement.is_active)


class RequirementFulfillmentCheckTestCase(TestCase):
def setUp(self):
Expand All @@ -178,7 +197,8 @@ def setUp(self):
)
self.badge_progress = BadgeProgress.objects.create(template=self.badge_template1, username="test1")
self.badge_requirement = BadgeRequirement.objects.create(
template=self.badge_template1, event_type="org.openedx.learning.course.passing.status.updated.v1"
template=self.badge_template1,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)
self.fulfillment = Fulfillment.objects.create(progress=self.badge_progress, requirement=self.badge_requirement)

Expand Down Expand Up @@ -208,7 +228,8 @@ def setUp(self):
blend="group1",
)
self.badge_requirement3 = BadgeRequirement.objects.create(
template=self.badge_template, event_type="org.openedx.learning.course.passing.status.updated.v1"
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)

def test_requirement_group(self):
Expand All @@ -227,7 +248,11 @@ def setUp(self):
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.credlybadge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization, uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)
self.requirement1 = BadgeRequirement.objects.create(
template=self.badge_template,
Expand Down Expand Up @@ -274,7 +299,11 @@ def setUp(self):
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.credlybadge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization, uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)
self.requirement1 = BadgeRequirement.objects.create(
template=self.badge_template,
Expand Down Expand Up @@ -307,7 +336,11 @@ def setUp(self):
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.credlybadge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization, uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)
self.requirement1 = BadgeRequirement.objects.create(
template=self.badge_template,
Expand Down Expand Up @@ -385,7 +418,10 @@ def test_ratio_no_requirements(self):
class CredlyBadgeAsBadgeDataTestCase(TestCase):
def setUp(self):
self.user = User.objects.create_user(
username="test_user", email="[email protected]", full_name="Test User", lms_user_id=1
username="test_user",
email="[email protected]",
full_name="Test User",
lms_user_id=1,
)
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.credential = BadgeTemplate.objects.create(
Expand Down Expand Up @@ -485,7 +521,8 @@ def setUp(self):
blend="group1",
)
self.badge_requirement3 = BadgeRequirement.objects.create(
template=self.badge_template, event_type="org.openedx.learning.course.passing.status.updated.v1"
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)
self.username = "test_user"

Expand Down Expand Up @@ -531,7 +568,10 @@ def test_get_all_organization_ids(self):

def test_get_preconfigured_organizations(self):
preconfigured_organizations = CredlyOrganization.get_preconfigured_organizations()
self.assertEqual(preconfigured_organizations, settings.BADGES_CONFIG["credly"].get("ORGANIZATIONS", {}))
self.assertEqual(
preconfigured_organizations,
settings.BADGES_CONFIG["credly"].get("ORGANIZATIONS", {}),
)

def test_is_preconfigured(self):
with patch(
Expand All @@ -540,3 +580,157 @@ def test_is_preconfigured(self):
mock_get_preconfigured.return_value = {str(self.uuid): "Test Organization"}
self.assertTrue(self.organization.is_preconfigured)
mock_get_preconfigured.assert_called_once()


class BadgeProgressTestCase(TestCase):
def setUp(self):
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = BadgeTemplate.objects.create(
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.badge_progress = BadgeProgress.objects.create(template=self.badge_template, username="test_user")

def test_reset_progress(self):
Fulfillment.objects.create(progress=self.badge_progress)
self.assertEqual(Fulfillment.objects.filter(progress=self.badge_progress).count(), 1)

self.badge_progress.reset()

self.assertEqual(Fulfillment.objects.filter(progress=self.badge_progress).count(), 0)


class BadgePenaltyIsActiveTestCase(TestCase):
def setUp(self):
self.organization = CredlyOrganization.objects.create(
uuid=uuid.uuid4(), api_key="test-api-key", name="test_organization"
)
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)
self.requirement = BadgeRequirement.objects.create(
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
description="Test description",
)
self.penalty = BadgePenalty.objects.create(
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)

def test_is_active(self):
self.penalty.template.is_active = True
self.assertTrue(self.penalty.is_active)

def test_is_not_active(self):
self.penalty.template.is_active = False
self.assertFalse(self.penalty.is_active)


class DataRuleIsActiveTestCase(TestCase):
def setUp(self):
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = BadgeTemplate.objects.create(
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.requirement = BadgeRequirement.objects.create(
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
description="Test description",
)
self.rule = DataRule.objects.create(
requirement=self.requirement,
data_path="course_passing_status.user.pii.username",
operator="eq",
value="cucumber1997",
)

def test_is_active(self):
self.rule.requirement.template.is_active = True
self.assertTrue(self.rule.is_active)

self.rule.requirement.template.is_active = False
self.assertFalse(self.rule.is_active)


class BadgeTemplateTestCase(TestCase):
def test_by_uuid(self):
template_uuid = uuid.uuid4()
site = Site.objects.create(domain="test_domain", name="test_name")
badge_template = BadgeTemplate.objects.create(uuid=template_uuid, origin=BadgeTemplate.ORIGIN, site=site)

retrieved_template = BadgeTemplate.by_uuid(template_uuid)

self.assertEqual(retrieved_template, badge_template)


class CredlyBadgeTemplateTestCase(TestCase):
def setUp(self):
uuid4 = uuid.uuid4()
self.organization = CredlyOrganization.objects.create(
uuid=uuid4, api_key="test-api-key", name="test_organization"
)
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization,
uuid=uuid4,
name="test_template",
state="draft",
site=self.site,
)

def test_management_url(self):
credly_host_base_url = "https://example.com/"
with patch("credentials.apps.badges.models.get_credly_base_url") as mock_get_credly_base_url:
mock_get_credly_base_url.return_value = credly_host_base_url
expected_url = (
f"{credly_host_base_url}mgmt/organizations/"
f"{self.organization.uuid}/badges/templates/{self.badge_template.uuid}/details"
)
self.assertEqual(self.badge_template.management_url, expected_url)
mock_get_credly_base_url.assert_called_with(settings)


class PenaltyDataruleIsActiveTestCase(TestCase):
def setUp(self):
self.organization = CredlyOrganization.objects.create(
uuid=uuid.uuid4(), api_key="test-api-key", name="test_organization"
)
self.site = Site.objects.create(domain="test_domain", name="test_name")
self.badge_template = BadgeTemplate.objects.create(
uuid=uuid.uuid4(), name="test_template", state="draft", site=self.site
)
self.credlybadge_template = CredlyBadgeTemplate.objects.create(
organization=self.organization,
uuid=uuid.uuid4(),
name="test_template",
state="draft",
site=self.site,
)

self.requirement = BadgeRequirement.objects.create(
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
description="Test description",
)
self.penalty = BadgePenalty.objects.create(
template=self.badge_template,
event_type="org.openedx.learning.course.passing.status.updated.v1",
)
self.rule = PenaltyDataRule.objects.create(
penalty=self.penalty,
data_path="course_passing_status.user.pii.username",
operator="eq",
value="cucumber1997",
)

def test_is_active(self):
self.requirement.template.is_active = True
self.assertTrue(self.rule.is_active)

self.requirement.template.is_active = False
self.assertFalse(self.rule.is_active)
29 changes: 14 additions & 15 deletions docs/badges/index.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
What is Credly?
===============
Badges
======

**Credly** is the end-to-end solution for creating, issuing, and managing digital credentials. Thousands of organizations use **Credly** to recognize achievement.
Users use Credly as a professional board to store badges to visualize their professional success – which courses were completed and when. Badges provide employers and peers concrete evidence of what you had to do to earn your credential and what you're now capable of. Credly also offers labor market insights based on users’ skills. Users can search and apply for job opportunities right through Credly.
The Badges feature allows learners to earn achievements (badges) for their learning activities.

Glossary
--------
- **Badge Template** is another kind of **credential**.
- **Badge** is another kind of **user credential**.

1. **Badge template** – a template of a badge (with design, name, and description) that will be used in settings to set up special rules to create a badge for users to receive on the platform.
Current Badges version is highly integrated with the `Credly (by Pearson)`_ service, but it is fully prepared to be used separately.

2. **Authorization token** – It's a temporary key that verifies identity and authorizes resource access. A token can be computer-generated or hardware-based. A valid token allows a user to retain access to an online service or web application until the token expires.
What is Credly?

3. **UUID** – Universally Unique Identifier – is a value used to identify an object or entity on the internet uniquely. Depending on the specific mechanisms used, a UUID is either guaranteed to be different or is, at least, extremely likely to be different from any other UUID generated.
**Credly** is the end-to-end solution for creating, issuing, and managing digital credentials. Thousands of organizations use **Credly** to recognize achievement.
Users use Credly as a professional board to store badges to visualize their professional success – which courses were completed and when. Badges provide employers and peers concrete evidence of what you had to do to earn your credential and what you're now capable of. Credly also offers labor market insights based on users’ skills. Users can search and apply for job opportunities right through Credly.

Badges
======

The Badges feature allows learners to earn achievements (badges) for their learning activities.
Glossary
--------

- **Badge Template** is another kind of **credential**.
- **Badge** is another kind of **user credential**.
1. **Badge template** – a template of a badge (with design, name, and description) that will be used in settings to set up special rules to create a badge for users to receive on the platform.

2. **Authorization token** – It's a temporary key that verifies identity and authorizes resource access. A token can be computer-generated or hardware-based. A valid token allows a user to retain access to an online service or web application until the token expires.

Current Badges version is highly integrated with the `Credly (by Pearson)`_ service, but it is fully prepared to be used separately.
3. **UUID** – Universally Unique Identifier – is a value used to identify an object or entity on the internet uniquely. Depending on the specific mechanisms used, a UUID is either guaranteed to be different or is, at least, extremely likely to be different from any other UUID generated.

----

Expand Down

0 comments on commit 79a447d

Please sign in to comment.