You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
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/templates/format/testfiles/json_original.json', 'r') as originalFile:
|
|
originalText = originalFile.read()
|
|
jsonOriginalObject = JSONFormat(originalText)
|
|
|
|
with open('./tests/templates/format/testfiles/json_template.json', 'r') as templateFile:
|
|
templateText = templateFile.read()
|
|
jsonTemplateObject = JSONFormat(templateText)
|
|
|
|
jsonOriginalObject.join_template(jsonTemplateObject)
|
|
|
|
with open('./tests/templates/format/testfiles/json_result.json', 'r') as resultFile:
|
|
resultText = resultFile.read()
|
|
|
|
assert jsonOriginalObject.document_text == resultText
|
|
|
|
def test_make_template(self):
|
|
document_1 = '''
|
|
{
|
|
"Param1":"ParamValue1",
|
|
"Param2": 1,
|
|
"BlockParam1":{
|
|
"BlockParam1":1,
|
|
"BlockParam2":0
|
|
},
|
|
"BlockParam2":{
|
|
"BlockParam1":"value",
|
|
"BlockParam2":false,
|
|
"BlockParam4":"other value"
|
|
},
|
|
"Param3": true
|
|
}
|
|
'''
|
|
|
|
document_2 = '''{
|
|
"Param1": "ParamValue1",
|
|
"BlockParam1": {
|
|
"BlockParam1": 12,
|
|
"BlockParam3": true
|
|
},
|
|
"BlockParam2": {
|
|
"BlockParam2": true,
|
|
"BlockParam4": "other value",
|
|
"BlockParam3": 12
|
|
},
|
|
"Param3": false,
|
|
"Param4": 12.3
|
|
}'''
|
|
|
|
document_1_object = JSONFormat(document_1)
|
|
document_2_object = JSONFormat(document_2)
|
|
template = document_1_object.make_template(document_2_object)
|
|
document_1_object.join_template(template)
|
|
assert document_1_object.document_text == document_2
|