-
Notifications
You must be signed in to change notification settings - Fork 3
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 #233 from Open-Telecoms-Data/2022-12-15-examples-t…
…ests-1 actions: Add tests to test some of the examples match the schema
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,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 |
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,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) |