Skip to content

Commit

Permalink
fetch extra schema items locally
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Jan 31, 2024
1 parent 6a9cbb3 commit 6d702ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
21 changes: 21 additions & 0 deletions reconcile/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import os
import re
import warnings

from referencing.jsonschema import DRAFT7

SCHEMA_DIR = os.path.join(os.path.dirname(__file__), "specs")
SUPPORTED_API_VERSIONS = ["0.2"]

Expand All @@ -23,3 +26,21 @@ def get_schema(
msg = f"Schema file {schema_path} not found"
warnings.warn(msg)
return schemas


# set up jsonschema registry
def retrieve_schema_from_filesystem(uri: str):
recon_schema = re.match(
r"https://reconciliation-api\.github\.io/specs/(.*)/schemas/(.*\.json)",
uri,
)
if recon_schema:
schema_version = recon_schema.group(1)
schema_file = recon_schema.group(2)
return DRAFT7.create_resource(
get_schema(schema_file, supported_api_versions=[schema_version])[
schema_version
]
)

raise ValueError(f"Unknown URI {uri}")
10 changes: 9 additions & 1 deletion reconcile/tests/test_company_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import os

import jsonschema
from referencing import Registry

from ftc.tests import TestCase

from .conftest import get_schema
from .conftest import get_schema, retrieve_schema_from_filesystem

logger = logging.getLogger(__name__)

Expand All @@ -22,6 +23,10 @@


class TestCompanyReconcileAPI(TestCase):
def setUp(self):
super().setUp()
self.registry = Registry(retrieve=retrieve_schema_from_filesystem)

# GET request to /api/v1/reconcile/company should return the service spec
def test_get_company_service_spec(self):
for schema_version, schema in get_schema("manifest.json").items():
Expand All @@ -47,6 +52,7 @@ def test_get_company_service_spec(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile/company should return a list of candidates
Expand Down Expand Up @@ -74,6 +80,7 @@ def test_company_reconcile(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile should return a list of candidates
Expand All @@ -100,4 +107,5 @@ def test_reconcile_empty(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)
13 changes: 12 additions & 1 deletion reconcile/tests/test_reconcile_all_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from typing import Tuple

import jsonschema
from referencing import Registry

from ftc.tests import TestCase

from .conftest import get_schema
from .conftest import get_schema, retrieve_schema_from_filesystem

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,6 +45,10 @@ def get_test_cases(schema_file):


class TestReconcileAllAPI(TestCase):
def setUp(self):
super().setUp()
self.registry = Registry(retrieve=retrieve_schema_from_filesystem)

# GET request to /api/v1/reconcile should return the service spec
def test_get_service_spec(self):
for base_url, schema_version, schema in get_test_cases("manifest.json"):
Expand All @@ -62,6 +67,7 @@ def test_get_service_spec(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile should return a list of candidates
Expand Down Expand Up @@ -89,6 +95,7 @@ def test_reconcile(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile should return a list of candidates
Expand All @@ -115,6 +122,7 @@ def test_reconcile_empty(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile/suggest/entity should return a list of candidates
Expand Down Expand Up @@ -149,6 +157,7 @@ def test_reconcile_suggest_entity(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# POST request to /api/v1/reconcile/suggest/entity should return a list of candidates
Expand Down Expand Up @@ -194,6 +203,7 @@ def test_reconcile_extend(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

# GET request to /api/v1/reconcile/suggest/entity should return a list of candidates
Expand Down Expand Up @@ -228,4 +238,5 @@ def test_reconcile_propose_properties(self):
instance=data,
schema=schema,
cls=jsonschema.Draft7Validator,
registry=self.registry,
)

0 comments on commit 6d702ec

Please sign in to comment.