Пример #1
0
    def testCase001(self):
        """Create a new branch
        """
        global configdata
        global appname
        global jsonpatchlist

        #
        # create
        nbranch = configdata.branch_create(
            JSONPointer("/phoneNumber").get_node(configdata.data),
            JSONPointer("/-/skype/de/home"), u"000-111-222")

        # fetch pathlist
        pbranch = ConfigData.getPointerPath(nbranch, configdata.data)[0][:-1]

        # get value of pointed node by pathlist
        pdata = JSONPointer(pbranch).get_node_or_value(configdata.data)

        # value
        nrepr = """u'000-111-222'"""

        # target
        prepr = """{u'home': u'000-111-222'}"""

        # repr for config data
        crepr = """{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'skype': {u'de': {u'home': u'000-111-222'}}}], u'address': {u'city': u'New York', u'streetAddress': u'21 2nd Street', u'houseNumber': 12}}"""

        assert nrepr == repr(nbranch)
        assert prepr == repr(pdata)
        assert crepr == repr(configdata)
        assert crepr == repr(configdata.data)
Пример #2
0
    def patch_import(self, patchfile, schemafile=None, **kargs):
        """Imports a task list.

        Supports the formats:
            RFC6902

        Args:
            patchfile:
                JSON patch filename containing the list of patch operations.
            schemafile:
                JSON-Schema filename for validation of the patch list.
            **kargs:
                validator: [default, draft3, off, ]
                    Sets schema validator for the data file.
                    The values are: default=validate, draft3=Draft3Validator,
                    off=None.
                    default:= validate

        Returns:
            When successful returns 'True', else raises an exception.

        Raises:
            JSONPatchException:

        """
        appname = _appname
        kargs = {}
        kargs['datafile'] = patchfile
        kargs['schemafile'] = schemafile
        kargs['validator'] = MODE_SCHEMA_OFF
        for k,v in kargs.items():
            if k == 'nodefaultpath':
                kargs['nodefaultpath'] = True
            elif k == 'pathlist':
                kargs['pathlist'] = v
            elif k == 'validator':
                kargs['validator'] = v
            elif k == 'appname':
                appname = v
        patchdata = JSONDataSerializer(appname,**kargs)

        for pi in patchdata.data:
            self += JSONPatchItemRaw(pi)
        return True
Пример #3
0
    def setUp(self):
        """Create a configuration object, load by provided file list.
        """
        global appname

        _path = mypath + os.sep + 'datasets' + os.sep + 'basic' + os.sep + 'set00' + os.sep + 'testdata.json'

        kargs = {}
        kargs['filelist'] = [_path]
        kargs['nodefaultpath'] = True
        kargs['nosubdata'] = True
        kargs['pathlist'] = os.path.dirname(__file__)
        kargs['validator'] = MODE_SCHEMA_DRAFT4
        self.configdata = ConfigData(appname, **kargs)

        self.jval = None
        self.sval = None

        pass
Пример #4
0
class CallUnits(unittest.TestCase):
    def setUp(self):
        """Create a configuration object, load by provided file list.
        """
        global appname

        _path = mypath + os.sep + 'datasets' + os.sep + 'basic' + os.sep + 'set00' + os.sep + 'testdata.json'

        kargs = {}
        kargs['filelist'] = [_path]
        kargs['nodefaultpath'] = True
        kargs['nosubdata'] = True
        kargs['pathlist'] = os.path.dirname(__file__)
        kargs['validator'] = MODE_SCHEMA_DRAFT4
        self.configdata = ConfigData(appname, **kargs)

        self.jval = None
        self.sval = None

        pass

    def testCase200_printSchema_assert(self):
        """Print schema into a string and assert.
        """
        oout = sys.stdout
        sys.stdout = StringIO()
        self.configdata.printSchema()
        sout = sys.stdout.getvalue()
        sys.stdout = oout
        conf_out = """{
    "required": false, 
    "_comment": "This is a comment to be dropped by the initial scan:object(0)", 
    "_doc": "Concatenated for the same instance.:object(0)", 
    "$schema": "http://json-schema.org/draft-03/schema", 
    "type": "object", 
    "properties": {
        "phoneNumber": {
            "items": {
                "required": false, 
                "type": "object", 
                "properties": {
                    "type": {
                        "required": false, 
                        "type": "string"
                    }, 
                    "number": {
                        "required": false, 
                        "type": "string"
                    }
                }
            }, 
            "_comment": "This is a comment(1):array", 
            "required": false, 
            "type": "array"
        }, 
        "address": {
            "_comment": "This is a comment(0):address", 
            "required": true, 
            "type": "object", 
            "properties": {
                "city": {
                    "required": true, 
                    "type": "string"
                }, 
                "streetAddress": {
                    "required": true, 
                    "type": "string"
                }, 
                "houseNumber": {
                    "required": false, 
                    "type": "number"
                }
            }
        }
    }
}
"""
        #        print "sout<"+sout+">"
        #        print "conf_out<"+conf_out+">"

        assert conf_out == sout
Пример #5
0
    def setUp(self):
        self.schemaRef = {
            "required": False,
            "_comment":
            "This is a comment to be dropped by the initial scan:object(0)",
            "_doc": "Concatenated for the same instance.:object(0)",
            "$schema": "http://json-schema.org/draft-03/schema",
            "type": "object",
            "properties": {
                "phoneNumber": {
                    "items": {
                        "required": False,
                        "type": "object",
                        "properties": {
                            "type": {
                                "required": False,
                                "type": "string"
                            },
                            "number": {
                                "required": False,
                                "type": "string"
                            }
                        }
                    },
                    "_comment": "This is a comment(1):array",
                    "required": False,
                    "type": "array"
                },
                "address": {
                    "_comment": "This is a comment(0):address",
                    "required": True,
                    "type": "object",
                    "properties": {
                        "city": {
                            "required": True,
                            "type": "string"
                        },
                        "streetAddress": {
                            "required": True,
                            "type": "string"
                        },
                        "houseNumber": {
                            "required": False,
                            "type": "number"
                        }
                    }
                }
            }
        }

        #     def setUp(self):
        #         """Create a configuration object, load by provided file list.
        #         """
        global appname

        _path = mypath + os.sep + 'datasets' + os.sep + 'basic' + os.sep + 'set00' + os.sep + 'testdata.json'

        kargs = {}
        kargs['filelist'] = [_path]
        kargs['nodefaultpath'] = True
        kargs['nosubdata'] = True
        kargs['pathlist'] = os.path.dirname(__file__)
        kargs['validator'] = MODE_SCHEMA_DRAFT4
        self.configdata = ConfigData(appname, **kargs)

        self.jval = None
        self.sval = None

        pass