Skip to content

Commit

Permalink
Merge pull request #233 from Open-Telecoms-Data/2022-12-15-examples-t…
Browse files Browse the repository at this point in the history
…ests-1

actions: Add tests to test some of the examples match the schema
  • Loading branch information
odscjames authored Dec 16, 2022
2 parents db5d054 + de553f1 commit 062de09
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Empty file added tests/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions tests/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import os
import jsonref

from libcoveofds.schema import OFDSSchema


class CurrentVersionOFDSSchema(OFDSSchema):

def __init__(self):
filename_package = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "schema", "network-package-schema.json")
filename_network = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "schema", "network-schema.json")
with open(filename_package) as fp:
self.schema = json.load(fp)
with open(filename_network) as fp:
self.data_schema = jsonref.load(fp)
self.schema['properties']['networks']['items'] = self.data_schema

def get_package_schema_dereferenced(self):
return self.schema

def get_package_schema(self):
return self.schema
51 changes: 51 additions & 0 deletions tests/test_examples_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import json

from .schema import CurrentVersionOFDSSchema
from libcoveofds.additionalfields import AdditionalFields
from libcoveofds.python_validate import PythonValidate
from libcoveofds.jsonschemavalidate import JSONSchemaValidator


class BaseTest:

def setup_class(self):
self.schema = CurrentVersionOFDSSchema()

def get_data(self):
return {}

def test_additional_fields(self):
worker = AdditionalFields(self.schema)
results = worker.process(self.get_data())
assert results == {}

def test_jsonschema_validation(self):
worker = JSONSchemaValidator(self.schema)
results = worker.validate(self.get_data())
# We call .json() so that if there any any problems, the output error messages are usefull.
results = [r.json() for r in results]
assert results == []

def test_python_validation(self):
worker = PythonValidate(self.schema)
results = worker.validate(self.get_data())
assert results == []


class TestNetworkPackage(BaseTest):

def get_data(self):
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "json",
"network-package.json")
with open(filename) as fp:
return json.load(fp)


class TestMultipleNetworks(BaseTest):

def get_data(self):
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "json",
"multiple-networks.json")
with open(filename) as fp:
return json.load(fp)

0 comments on commit 062de09

Please sign in to comment.