-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: course credentials as verifiable credentials
- Loading branch information
Showing
9 changed files
with
305 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
credentials/apps/verifiable_credentials/composition/tests/test_schemas.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
|
||
from credentials.apps.catalog.tests.factories import ( | ||
CourseFactory, | ||
CourseRunFactory, | ||
OrganizationFactory, | ||
ProgramFactory, | ||
) | ||
from credentials.apps.core.tests.factories import UserFactory | ||
from credentials.apps.core.tests.mixins import SiteMixin | ||
from credentials.apps.credentials.tests.factories import ( | ||
CourseCertificateFactory, | ||
ProgramCertificateFactory, | ||
UserCredentialFactory, | ||
) | ||
from credentials.apps.verifiable_credentials.composition.schemas import EducationalOccupationalCredentialSchema | ||
from credentials.apps.verifiable_credentials.issuance.tests.factories import IssuanceLineFactory | ||
|
||
|
||
class EducationalOccupationalCredentialSchemaTests(SiteMixin, TestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.user = UserFactory() | ||
self.orgs = [OrganizationFactory.create(name=name, site=self.site) for name in ["TestOrg1", "TestOrg2"]] | ||
self.course = CourseFactory.create(site=self.site) | ||
self.course_runs = CourseRunFactory.create_batch(2, course=self.course) | ||
self.program = ProgramFactory( | ||
title="TestProgram1", | ||
course_runs=self.course_runs, | ||
authoring_organizations=self.orgs, | ||
site=self.site, | ||
) | ||
self.course_certs = [ | ||
CourseCertificateFactory.create( | ||
course_id=course_run.key, | ||
course_run=course_run, | ||
site=self.site, | ||
) | ||
for course_run in self.course_runs | ||
] | ||
self.program_cert = ProgramCertificateFactory.create( | ||
program=self.program, program_uuid=self.program.uuid, site=self.site | ||
) | ||
self.course_credential_content_type = ContentType.objects.get( | ||
app_label="credentials", model="coursecertificate" | ||
) | ||
self.program_credential_content_type = ContentType.objects.get( | ||
app_label="credentials", model="programcertificate" | ||
) | ||
self.course_user_credential = UserCredentialFactory.create( | ||
username=self.user.username, | ||
credential_content_type=self.course_credential_content_type, | ||
credential=self.course_certs[0], | ||
) | ||
self.program_user_credential = UserCredentialFactory.create( | ||
username=self.user.username, | ||
credential_content_type=self.program_credential_content_type, | ||
credential=self.program_cert, | ||
) | ||
self.program_issuance_line = IssuanceLineFactory(user_credential=self.program_user_credential, subject_id="did:key:test") | ||
self.course_issuance_line = IssuanceLineFactory(user_credential=self.course_user_credential, subject_id="did:key:test") | ||
|
||
|
||
def test_to_representation_program(self): | ||
data = EducationalOccupationalCredentialSchema(self.program_issuance_line).data | ||
|
||
assert data["id"] == "EducationalOccupationalCredential" | ||
assert data["name"] == self.program_cert.title | ||
assert data["description"] == str(self.program_user_credential.uuid) | ||
assert data["program"]["id"] == "EducationalOccupationalProgram" | ||
assert data["program"]["name"] == self.program.title | ||
assert data["program"]["description"] == str(self.program.uuid) | ||
|
||
def test_to_representation_course(self): | ||
data = EducationalOccupationalCredentialSchema(self.course_issuance_line).data | ||
|
||
assert data["id"] == "EducationalOccupationalCredential" | ||
assert data["name"] == self.course_certs[0].title | ||
assert data["description"] == str(self.course_user_credential.uuid) | ||
assert data["course"]["id"] == "Course" | ||
assert data["course"]["name"] == self.course.title | ||
assert data["course"]["courseCode"] == self.course_certs[0].course_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class CredentialsType: | ||
""" | ||
Enum to define the type of credentials. | ||
""" | ||
PROGRAM = "programcertificate" | ||
COURSE = "coursecertificate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.