forked from 1EdTech/cert-schema
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from blockchain-certificates/feat/context_url_…
…getter Feat/context url getter
- Loading branch information
Showing
6 changed files
with
267 additions
and
60 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
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,65 @@ | ||
import os | ||
import json | ||
BASE_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
class ContextUrls: | ||
def __init__(self): | ||
with open(os.path.join(BASE_DIR, 'context_urls.json')) as context_data: | ||
self.CONTEXT_URLS = json.load(context_data) | ||
|
||
def v2(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V2_CONTEXT'] | ||
|
||
def v2_canonical(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V2_CANONICAL_CONTEXT'] | ||
|
||
def v2_blockcerts_org(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_ORG_V2_CONTEXT'] | ||
|
||
def v2_all(self): | ||
return [ | ||
self.v2(), | ||
self.v2_canonical(), | ||
self.v2_blockcerts_org() | ||
] | ||
|
||
def v2_1(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V2_1_CONTEXT'] | ||
|
||
def v2_1_canonical(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V2_1_CANONICAL_CONTEXT'] | ||
|
||
def v2_1_blockcerts_org(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_ORG_V2_1_CONTEXT'] | ||
|
||
def v2_1_all(self): | ||
return [ | ||
self.v2_1(), | ||
self.v2_1_canonical(), | ||
self.v2_1_blockcerts_org() | ||
] | ||
|
||
def v3(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V3_CONTEXT'] | ||
|
||
def v3_canonical(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_V3_CANONICAL_CONTEXT'] | ||
|
||
def v3_blockcerts_org(self): | ||
return self.CONTEXT_URLS['BLOCKCERTS_ORG_V3_CONTEXT'] | ||
|
||
def v3_all(self): | ||
return [ | ||
self.v3(), | ||
self.v3_canonical(), | ||
self.v3_blockcerts_org() | ||
] | ||
|
||
def open_badge(self): | ||
return self.CONTEXT_URLS['OPEN_BADGES_V2_CONTEXT'] | ||
|
||
def open_badge_canonical(self): | ||
return self.CONTEXT_URLS['OPEN_BADGES_V2_CANONICAL_CONTEXT'] | ||
|
||
def verifiable_credential(self): | ||
return self.CONTEXT_URLS['VERIFIABLE_CREDENTIAL_V1_CONTEXT'] |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
setup( | ||
name='cert-schema', | ||
version='3.0.7', | ||
version='3.1.0', | ||
description='Blockchain certificates JSON-LD context and JSON schemas', | ||
author='[email protected]', | ||
url='https://github.com/blockchain-certificates/cert-schema', | ||
|
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,80 @@ | ||
import unittest | ||
|
||
from cert_schema import ContextUrls | ||
|
||
class TestContextUrls(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(self): | ||
self.instance = ContextUrls() | ||
|
||
def test_v2(self): | ||
output = self.instance.v2() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/schema/2.0/context.json') | ||
|
||
def test_v2_canonical(self): | ||
output = self.instance.v2_canonical() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/v2') | ||
|
||
def test_v2_blockcerts_org(self): | ||
output = self.instance.v2_blockcerts_org() | ||
self.assertTrue(output == 'https://www.blockcerts.org/schema/2.0/context.json') | ||
|
||
def test_v2_all(self): | ||
output = self.instance.v2_all() | ||
self.assertEqual(output, [ | ||
'https://w3id.org/blockcerts/schema/2.0/context.json', | ||
'https://w3id.org/blockcerts/v2', | ||
'https://www.blockcerts.org/schema/2.0/context.json' | ||
]) | ||
|
||
def test_v2_1(self): | ||
output = self.instance.v2_1() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/schema/2.1/context.json') | ||
|
||
def test_v2_1_canonical(self): | ||
output = self.instance.v2_1_canonical() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/v2.1') | ||
|
||
def test_v2_1_blockcerts_org(self): | ||
output = self.instance.v2_1_blockcerts_org() | ||
self.assertTrue(output == 'https://www.blockcerts.org/schema/2.1/context.json') | ||
|
||
def test_v2_1_all(self): | ||
output = self.instance.v2_1_all() | ||
self.assertEqual(output, [ | ||
'https://w3id.org/blockcerts/schema/2.1/context.json', | ||
'https://w3id.org/blockcerts/v2.1', | ||
'https://www.blockcerts.org/schema/2.1/context.json' | ||
]) | ||
|
||
def test_v3(self): | ||
output = self.instance.v3() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/schema/3.0/context.json') | ||
|
||
def test_v3_canonical(self): | ||
output = self.instance.v3_canonical() | ||
self.assertTrue(output == 'https://w3id.org/blockcerts/v3') | ||
|
||
def test_v3_blockcerts_org(self): | ||
output = self.instance.v3_blockcerts_org() | ||
self.assertTrue(output == 'https://www.blockcerts.org/schema/3.0/context.json') | ||
|
||
def test_v3_all(self): | ||
output = self.instance.v3_all() | ||
self.assertEqual(output, [ | ||
'https://w3id.org/blockcerts/schema/3.0/context.json', | ||
'https://w3id.org/blockcerts/v3', | ||
'https://www.blockcerts.org/schema/3.0/context.json' | ||
]) | ||
|
||
def test_open_badge(self): | ||
output = self.instance.open_badge() | ||
self.assertTrue(output == 'https://openbadgespec.org/v2/context.json') | ||
|
||
def test_open_badge_canonical(self): | ||
output = self.instance.open_badge_canonical() | ||
self.assertTrue(output == 'https://w3id.org/openbadges/v2') | ||
|
||
def test_verifiable_credentials(self): | ||
output = self.instance.verifiable_credential() | ||
self.assertTrue(output == 'https://www.w3.org/2018/credentials/v1') |