Source code for UseCases.libs.JSONData.branch_test.dict_item.CallCase
"""Append list element.
"""
from __future__ import absolute_import
import unittest
import os
import sys
# pre-set the base JSON libraries for 'jsondata' by PyUnit call
if 'ujson' in sys.argv:
import ujson as myjson
elif 'json' in sys.argv:
import json as myjson
else:
import json as myjson
import jsonschema
# import 'jsondata'
from jsondata.JSONDataSerializer import JSONDataSerializer as ConfigData
from jsondata.JSONDataSerializer import MODE_SCHEMA_DRAFT4
from jsondata.JSONDataExceptions import JSONDataKeyError,JSONDataNodeType
# name of application, used for several filenames as MODE_SCHEMA_DRAFT4
_APPNAME = "jsondc"
appname = _APPNAME
#
#######################
#
[docs]class CallUnits(unittest.TestCase):
"""Base branch_add.
"""
[docs] def testCase000(self):
"""Load initial main/master data, and validate it with standard draft4.
"""
global jval
global sval
global configdata
global appname
global schemafile
datafile = os.path.abspath(os.path.dirname(__file__))+os.sep+str('datafile.json')
schemafile = os.path.abspath(os.path.dirname(__file__))+os.sep+str('schema.jsd')
kargs = {}
kargs['datafile'] = datafile
kargs['schemafile'] = schemafile
kargs['nodefaultpath'] = True
kargs['nosubdata'] = True
kargs['pathlist'] = os.path.dirname(__file__)
kargs['validator'] = MODE_SCHEMA_DRAFT4
configdata = ConfigData(appname,**kargs)
assert repr(configdata.data) == "{u'phoneNumber': [{u'type': u'home', u'number': u'212 555-1234'}, {u'type': u'office', u'number': u'313 444-555'}, {u'type': u'mobile', u'number': u'777 666-555'}], u'address': {u'city': u'New York', u'streetAddress': u'21 2nd Street', u'houseNumber': 12}}"
pass
[docs] def testCase500(self):
"""Import another branch into memory and add the representation into the initial master data.
Use insertion point:
target = configdata.data['phoneNumber']
for file:
'branch1.json'
#---
{
"type":"home2",
"number":"222 222-333"
}
#---
Apply '$schema' key for branch/subtree of master schema.
"""
global jval
global sval
global configdata
global appname
global schemafile
# target container
target = configdata
ret = configdata.branch_test(target.data['phoneNumber'][0]['type'], 'home')
assert ret == True
pass
if __name__ == '__main__':
unittest.main()