|
| 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() |
0 commit comments