import pytest from collections import OrderedDict from calculate.templates.format.json_format import JSONFormat @pytest.mark.json class TestParsingMethods: def test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary(self): documentText = ''' { "Param1":"ParamValue1", "Param2": 1, "BlockParam1":{ "BlockParam1":1, "BlockParam2":0 }, "Param3": true } ''' blockContent = OrderedDict({"BlockParam1": 1, "BlockParam2": 0}) result = OrderedDict({'Param1': 'ParamValue1', 'Param2': 1, 'BlockParam1': blockContent, 'Param3': True}) jsonObject = JSONFormat(documentText) assert jsonObject._document_dictionary == result def test_joining_documents_1(self): with open('./tests/format/testfiles/json_original.json', 'r') as originalFile: originalText = originalFile.read() jsonOriginalObject = JSONFormat(originalText) with open('./tests/format/testfiles/json_template.json', 'r') as templateFile: templateText = templateFile.read() jsonTemplateObject = JSONFormat(templateText) jsonOriginalObject.join_template(jsonTemplateObject) with open('./tests/format/testfiles/json_result.json', 'r') as resultFile: resultText = resultFile.read() assert jsonOriginalObject.get_document_text() == resultText