Skip to content

Commit 0509866

Browse files
committed
re add deleted files
1 parent 8be7016 commit 0509866

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

lib/tests/__init__.py

Whitespace-only changes.

lib/tests/test_.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from utils import utils
2+
import unittest
3+
import subprocess
4+
import jsonschema
5+
import glob
6+
import os
7+
8+
class TestMethodologies(unittest.TestCase):
9+
def setUp(self):
10+
self.methodologyFilenames = []
11+
for filename in glob.glob(utils.METHODOLOGIES_DIR + '/*.json'):
12+
self.methodologyFilenames.append(filename)
13+
14+
def validate_schema(self, schema_file, data_file):
15+
print("validating ", data_file)
16+
schema = utils.get_json(schema_file)
17+
data = utils.get_json(data_file)
18+
jsonschema.Draft7Validator.check_schema(schema)
19+
error = jsonschema.exceptions.best_match(jsonschema.Draft7Validator(schema).iter_errors(data))
20+
if error:
21+
raise error
22+
23+
def test_schemas(self):
24+
for methodologyFilename in self.methodologyFilenames:
25+
self.validate_schema(utils.SCHEMA_FILENAME, methodologyFilename)
26+
27+
if __name__ == '__main__':
28+
unittest.main()

lib/tests/test_template_mapping.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from utils import utils
2+
from tests.test_ import TestMethodologies
3+
import os
4+
import unittest
5+
import requests
6+
7+
class TestTemplateMapping(unittest.TestCase):
8+
def setUp(self):
9+
self.template_schema = os.path.join(
10+
utils.MAPPING_DIR,
11+
utils.TEMPLATE_SCHEMA
12+
)
13+
self.template_filename = os.path.join(
14+
utils.MAPPING_DIR,
15+
utils.TEMPLATE_FILENAME
16+
)
17+
18+
def test_mapping_schemas(self):
19+
"""
20+
Validate the mapping templates using template.schema.json
21+
get the mapping data from templates.json
22+
and validating the templates data
23+
"""
24+
TestMethodologies.validate_schema(
25+
TestMethodologies,
26+
self.template_schema,
27+
self.template_filename
28+
)
29+
30+
mapping = utils.get_json(self.template_filename)
31+
32+
self.validate_mapping_data(mapping['content'])
33+
34+
def validate_mapping_data(self, mapping):
35+
for methodologyData in mapping:
36+
self.check_template_exists(methodologyData['methodology'], methodologyData['children'])
37+
38+
def check_template_exists(self, methodology, steps):
39+
"""
40+
Check a template mapping path from templates.json file
41+
and check methodology template exists (or not) in template repository
42+
if the template is not found, it will give an error for template missing
43+
"""
44+
print("validating methodology : %s" % methodology)
45+
46+
for step in steps:
47+
template_path = os.path.join('methodology', step['attribute'], methodology, step['template'])
48+
template_url = utils.TEMPLATE_BASE_URL + template_path
49+
response = requests.request("GET", template_url)
50+
print("validating methodology step : %s" % step['key'])
51+
52+
self.assertEqual(response.status_code, 200, 'Missing template file for %s mapping' % methodology)
53+
54+
if __name__ == "__main__":
55+
unittest.main()

lib/utils/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)