Commit 059a497a authored by Sreenath Sasidharan Nair's avatar Sreenath Sasidharan Nair
Browse files

added github workflow and test cases

parent 325a7700
......@@ -42,6 +42,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
......@@ -68,4 +69,6 @@ ENV/
/site
# mypy
.mypy_cache/
\ No newline at end of file
.mypy_cache/
.vscode/
\ No newline at end of file
......@@ -14,7 +14,6 @@
# under the License.
import os
import sys
import json
import argparse
from beacons_bio_3d.utils import JSONUtils, DjangoUtils
......@@ -29,10 +28,11 @@ RES_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__
DEFAULT_SCHEMA_JSON = f"{RES_PATH}/schema.json"
DEFAULT_REGISTRY_JSON = f"{RES_PATH}/registry.json"
def main():
""" This is the application entry point
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
sub_parsers = parser.add_subparsers(dest='subparser_name', help="Available sub-commands")
......@@ -46,7 +46,10 @@ def main():
model_gen_parser = sub_parsers.add_parser("model_generate", help="Generates model JSON from registry JSON.")
model_gen_parser.add_argument("--registry_json", help="Path to registry JSON to be converted", required=True)
model_gen_parser.add_argument("--model_json", help="Path to output model JSON", required=True)
model_gen_parser.add_argument("--django_app", help="The name of Django app, this will be used to define package for model")
model_gen_parser.add_argument(
"--django_app",
help="The name of Django app, this will be used to define package for model",
default="core")
args = parser.parse_args()
......@@ -61,5 +64,6 @@ def main():
print(f"Model JSON generated to {args.model_json}")
if __name__ == "__main__":
main()
\ No newline at end of file
main()
from logging import debug
import os
import json
import jsonschema
from jsonschema.exceptions import ValidationError
class DjangoUtils:
""" This is the utils class for Django
"""
......@@ -11,8 +11,6 @@ class DjangoUtils:
def generate_fixture_json(input_registry_json, django_app="core"):
registry = json.load(open(input_registry_json))
model = []
provider_dict = {}
service_dict = {}
for provider in registry["providers"]:
model.append(
......@@ -27,12 +25,12 @@ class DjangoUtils:
}
}
)
for service in registry["services"]:
model.append({
"model": f"{django_app}.Service",
"fields": {
"service_type": service["serviceType"],
"service_type": service["serviceType"],
"provider": service["provider"],
"access_point": service["accessPoint"]
}
......@@ -40,6 +38,7 @@ class DjangoUtils:
return model
class JSONUtils:
""" This is the utils class for JSON
"""
......@@ -67,7 +66,7 @@ class JSONUtils:
jsonschema.validate(instance, schema=schema)
except ValidationError as e:
raise e
# validate if provider field in services is valid
dict_provider = dict()
......@@ -83,7 +82,7 @@ class JSONUtils:
if unmatched_providers:
raise InvalidProviderException(unmatched_providers)
print("Validation successful")
return True
......@@ -98,4 +97,3 @@ class InvalidProviderException(Exception):
def __init__(self, providers):
self.providers = providers
super().__init__(f"Invalid providers: {self.providers}")
......@@ -2,7 +2,7 @@
"providers": [
{
"providerId": "p1",
"providerName": "p1name",
"providerName": "p1 name",
"providerDescription": "p1 desc",
"providerUrl": "www.example.com",
"baseServiceUrl": "www.example.com",
......@@ -10,7 +10,7 @@
},
{
"providerId": "p2",
"providerName": "p2name",
"providerName": "p2 name",
"providerDescription": "p2 desc",
"providerUrl": "www.example.com",
"baseServiceUrl": "www.example.com",
......
import os
import unittest
import json
from beacons_bio_3d.utils import JSONUtils, DjangoUtils, InvalidProviderException
from jsonschema import ValidationError
RES_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources')
class TestDjangoUtils(unittest.TestCase):
def test_model_generate_valid_case(self):
registry_json = f"{RES_PATH}/valid_full_registry.json"
model_json = f"{RES_PATH}/valid_model.json"
generated_model = DjangoUtils.generate_fixture_json(registry_json)
valid_model = json.load(open(model_json))
self.assertEqual(valid_model, generated_model)
import os
import unittest
import json
from six import assertRaisesRegex
from beacons_bio_3d.utils import JSONUtils, DjangoUtils, InvalidProviderException
from jsonschema import ValidationError
......@@ -25,11 +23,3 @@ class TestJSONUtils(unittest.TestCase):
def test_invalid_providers_case(self):
self.assertRaises(InvalidProviderException, JSONUtils.validate_schema, f"{RES_PATH}/valid_schema.json", f"{RES_PATH}/invalid_providers_registry.json")
class TestDjangoUtils(unittest.TestCase):
def test_model_generate_valid_case(self):
registry_json = f"{RES_PATH}/valid_full_registry.json"
model_json = f"{RES_PATH}/valid_model.json"
generated_model = DjangoUtils.generate_fixture_json(registry_json)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment