Example #1
0
    def testCase900(self):
        """JSONPointers: "#"
        """
        jp = JSONPointer('#')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """{u'': 0, u' ': 7, u'c%d': 2, u'a/b': 1, u'k"l': 6, u'm~n': 8, u'g|h': 4, u'e^f': 3, u'foo': [u'bar', u'baz'], u'i\\\\j': 5}"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #2
0
    def testCase902(self):
        """JSONPointers: "#/foo/0"
        """
        jp = JSONPointer('#/foo/0')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """u'bar'"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #3
0
    def testCase909(self):
        """JSONPointers: "#i%5Cj"
        """
        jp = JSONPointer('#i%5Cj')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """5"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #4
0
    def testCase911(self):
        """JSONPointers: "#%20"
        """
        jp = JSONPointer('#%20')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """7"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #5
0
    def testCase906(self):
        """JSONPointers: "#e%5Ef"
        """
        jp = JSONPointer('#e%5Ef')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """3"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #6
0
    def testCase902(self):
        """JSONPointers: "//"
        """
        jp = JSONPointer('//')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """[u'doubleempty0', u'doubleempty1']"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #7
0
    def testCase901(self):
        """JSONPointers: "/"
        """
        jp = JSONPointer('/')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """{u'': {u'': [u'tripleempty0', u'tripleempty1']}}"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #8
0
    def testCase905(self):
        """JSONPointers: "#/c%25d"
        """
        jp = JSONPointer('#/c%25d')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """2"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #9
0
    def testCase012(self):

        data = {'a': {'b': {'c': 2}}}
        D = JSONData(data)
        n = JSONPointer("/a/b/c")
        n = n.get_node(D.data, True)
        D.branch_add(n, None, data)

        assert D.data == {'a': {'b': {'a': {'b': {}}}}}
        pass
Example #10
0
    def testCase905(self):
        """JSONPointers: "////1"
        """
        jp = JSONPointer('////1')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """u'tripleempty1'"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #11
0
    def testCase901(self):
        """JSONPointers: "/foo"
        """
        jp = JSONPointer('/foo')
        jdata=jp.get_node_or_value(configdata.data)
        jdoc = """[u'bar', u'baz']"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert  repr(jdata) == jdoc
Example #12
0
    def testCase908(self):
        """JSONPointers: "m~0n"
        """
        jp = JSONPointer('m~0n')
        jdata=jp.get_node_or_value(configdata.data)
        jdoc = """8"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert  repr(jdata) == jdoc
Example #13
0
    def testCase904(self):
        """JSONPointers: "/a~1b"
        """
        jp = JSONPointer('/a~1b')
        jdata=jp.get_node_or_value(configdata.data)
        jdoc = """1"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert  repr(jdata) == jdoc
Example #14
0
    def testCase900(self):
        """Add by radd.
        """
        jp = JSONPointer('/streetAddress')
        jp = '/address' + jp
        jp = JSONPointer(jp)

        # now in one line
        assert configdata.data["address"][
            "streetAddress"] == jp.get_node_or_value(configdata.data)
Example #15
0
    def testCase907(self):
        """JSONPointers: "#g%7Ch"
        """
        jp = JSONPointer('#g%7Ch')
        jdata = jp.get_node_or_value(configdata.data)
        jdoc = """4"""
        #print "<"+repr(jdata)+">"
        #print "<"+jdoc+">"

        assert repr(jdata) == jdoc
Example #16
0
    def testCase010(self):

        data = [[[2]]]
        target = {'A': {'A': [3]}}
        D = JSONData(data)
        n = JSONPointer("/0/0")
        n = n.get_node(D.data)
        D.branch_add(target['A']['A'], None, n)

        rdata = {'A': {'A': [2]}}
        assert target == rdata
        pass
Example #17
0
    def testCase901(self):
        """Access by constant references and by pointer.
        """
        global configdata

        # by pointer
        jsonptr = JSONPointer('/address/streetAddress')
        if not jsonptr:
            raise BaseException("Failed to create JSONPointer")
        jsonptrdata = jsonptr.get_node_or_value(configdata.data)
        jsx = str(jsonptrdata)
        assert jsx == configdata.data["address"]["streetAddress"]
Example #18
0
    def testCase010(self):

        data = {'a': {'b': {'c': 2}}}
        target = {'A': {'A': 'x'}}
        D = JSONData(data)
        n = JSONPointer("/a/b/c")
        n = n.get_node(D.data, True)
        D.branch_add(target['A'], None, n)

        rdata = {'A': {'c': 2}}
        assert target == rdata
        pass
Example #19
0
    def testCase702(self):
        """Import a branch into initial main/master data, and validate it with branch schema.

        Apply '$schema' key for branch/subtree of master schema.
        """
        global jval
        global sval
        global configdata
        global appname
        global schemafile

        # branch to be loaded
        datafile = os.path.abspath(
            os.path.dirname(__file__)) + os.sep + str('branch2.json')

        # partial schema for branch, use here a subtree of main schema,
        # the entry:
        #    "$schema": "http://json-schema.org/draft-03/schema",
        # seems not to be required,
        #
        # but here just check it
        schema = {
            "$schema": "http://json-schema.org/draft-03/schema",
            'phoneNumber': configdata.schema['properties']['phoneNumber']
        }

        # import settings
        kargs = {}
        kargs['schema'] = schema
        kargs['nodefaultpath'] = True
        kargs['nosubdata'] = True
        kargs['pathlist'] = os.path.dirname(__file__)
        kargs['validator'] = MODE_SCHEMA_DRAFT4

        # do it...
        target = JSONPointer("/phoneNumber/1").get_node(configdata.data)
        ret = configdata.json_import(target, None, datafile, None, **kargs)
        assert ret == True

        # do it...
        target = JSONPointer("/phoneNumber/2").get_node(configdata.data)
        ret = configdata.json_import(target, None, datafile, None, **kargs)
        assert ret == True

        # expected - after branch_add_only the same state as before
        conf_dat = repr(configdata.data)
        conf_dat = """{u'phoneNumber': [{u'type': u'home1', u'number': u'111 222-333'}, {u'type': u'home2', u'number': u'222 222-333'}, {u'type': u'home2', u'number': u'222 222-333'}, {u'type': u'home0', u'number': u'000 222-333'}, {u'type': u'home0', u'number': u'000 222-333'}], u'address': {u'city': u'New York', u'streetAddress': u'21 2nd Street', u'houseNumber': 12}}"""
        assert repr(configdata.data) == conf_dat
Example #20
0
 def testCase902(self):
     """Access by constant references and by pointer.
     """
     global configdata
     # now in one line
     assert configdata.data["address"]["streetAddress"] == JSONPointer(
         '/address/streetAddress').get_node_or_value(configdata.data)
Example #21
0
    def testCase902(self):
        """Access by constant references and by pointer.
        """
        assert configdata.data["phoneNumber"][0]["type"] == "home0"

        jp = JSONPointer('/phoneNumber') + 0 + 'type'
        assert jp >= '/phoneNumber/0/type'
Example #22
0
 def testCase900(self):
     """Access by constant references and by pointer.
     """
     jp = JSONPointer('/address')
     jp = jp + 'streetAddress'
     # now in one line
     assert jp >= '/address/streetAddress'
Example #23
0
    def testCase022(self):
        c0 = [4]

        n0 = [[{'c0': 'c0'}, {'c3': [3]}, ['c0']]]
        n1 = [[{'c0': c0}, {'c3': [3]}, ['c0']]]
        n2 = [[{'c0': 'c0'}, {'c3': [3]}, [c0]]]

        n3 = [[{'c0': c0}, {'c3': [3]}, [c0]]]
        n4 = {'x0': [[[3], {'c0': c0}, [c0]]]}
        n6 = [[[[n4]]]]
        n7 = [[n4]]
        n8 = {'x': {'c0': c0}}

        sl = [
            n0,
            n1,
            n2,
            n3,
            n6,
            n4,
            n7,
            n8,
        ]

        p0 = JSONData.getPointerPath(c0, sl, JSONData.ALL)
        resx = [[1, 0, 0, 'c0'], [2, 0, 2, 0], [3, 0, 0, 'c0'], [3, 0, 2, 0],
                [4, 0, 0, 0, 0, 'x0', 0, 1, 'c0'],
                [4, 0, 0, 0, 0, 'x0', 0, 2, 0], [5, 'x0', 0, 1, 'c0'],
                [5, 'x0', 0, 2, 0], [6, 0, 0, 'x0', 0, 1, 'c0'],
                [6, 0, 0, 'x0', 0, 2, 0], [7, 'x', 'c0']]
        assert p0 == resx

        pathlst = []
        for rx in resx:
            pathlst.append(JSONPointer(rx).get_pointer())
        pathx = [
            u'/1/0/0/c0', u'/2/0/2/0', u'/3/0/0/c0', u'/3/0/2/0',
            u'/4/0/0/0/0/x0/0/1/c0', u'/4/0/0/0/0/x0/0/2/0', u'/5/x0/0/1/c0',
            u'/5/x0/0/2/0', u'/6/0/0/x0/0/1/c0', u'/6/0/0/x0/0/2/0', u'/7/x/c0'
        ]
        assert pathlst == pathx

        vallst = []
        for rx in resx:
            vallst.append(JSONPointer(rx).get_node_or_value(sl))
        vallstx = [[4], [4], [4], [4], [4], [4], [4], [4], [4], [4], [4]]
        assert vallst == vallstx
Example #24
0
    def testCase100(self):
        data = {'a': {'b': {'c': 2}}}
        D = JSONData([])
        n = JSONPointer('').get_node(D.data)
        D.branch_add(n, '-', data)
        #         D.branch_add(n,None,data)

        assert D.data == [data]
        pass
Example #25
0
    def testCase920(self):
        """Access some entries by dynamic references from raw data file read.
        """
        global configdata

        #print "#---------------a"
        for l in ['domestic','abroad',]:
            for n in [0,1,]:
                cdata = configdata.data["customers"][l][n]["name"]
                jdata = jval["customers"][l][n]["name"]
                assert cdata == jdata
                
                #now pointer
                assert configdata.data["customers"][l][n]["name"] == JSONPointer('/customers/'+str(l)+'/'+str(n)+'/name').get_node_or_value(configdata.data)
        
                cdata = configdata.data["customers"][l][n]["industries"]
                jdata = configdata.data["customers"][l][n]["industries"]
                assert cdata == jdata 

                #now pointer
                assert configdata.data["customers"][l][n]["industries"] == JSONPointer('/customers/'+str(l)+'/'+str(n)+'/industries').get_node_or_value(configdata.data)
        
                for p in [0,1,]:
                    cdata = configdata.data["customers"][l][n]["products"][p]["name"]
                    jdata = configdata.data["customers"][l][n]["products"][p]["name"]
                    assert cdata == jdata 

                    #now pointer
                    assert configdata.data["customers"][l][n]["products"][p]["name"] == JSONPointer('/customers/'+str(l)+'/'+str(n)+'/products/'+str(p)+'/name').get_node_or_value(configdata.data)
             
                    cdata = configdata.data["customers"][l][n]["products"][p]["quantities"]
                    jdata = configdata.data["customers"][l][n]["products"][p]["quantities"]
                    assert cdata == jdata 

                    #now pointer
                    assert configdata.data["customers"][l][n]["products"][p]["quantities"] == JSONPointer('/customers/'+str(l)+'/'+str(n)+'/products/'+str(p)+'/quantities').get_node_or_value(configdata.data)
             
                    cdata = configdata.data["customers"][l][n]["products"][p]["priority"]
                    jdata = configdata.data["customers"][l][n]["products"][p]["priority"]
                    assert cdata == jdata 

                    #now pointer
                    assert configdata.data["customers"][l][n]["products"][p]["priority"] == JSONPointer('/customers/'+str(l)+'/'+str(n)+'/products/'+str(p)+'/priority').get_node_or_value(configdata.data)
Example #26
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"), {u"home": u"000-111-222"})

        nrepr = """{u'home': u'000-111-222'}"""

        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 crepr == repr(configdata)
        assert crepr == repr(configdata.data)
Example #27
0
    def __init__(self,op,target,param=None):
        """Create an entry for the patch list.

        Args:
            op: Operation: add, copy, move, remove, replace, test

            target: Target node.
                    
            param: Parameter specific for the operation:
                value: add,replace, test
                src: copy, move
                param:=None for 'remove'

        Returns:
            When successful returns 'True', else returns either 'False', or
            raises an exception.
            Success is the complete addition only, thus one failure returns
            False.

        Raises:
            JSONDataSerializerError:
        
        """
        self.value = None
        self.src = None

        self.op = getOp(op)
        self.target = JSONPointer(target)
        
        if self.op in (RFC6902_ADD,RFC6902_REPLACE,RFC6902_TEST):
            self.value = param

        elif self.op is RFC6902_REMOVE:
            pass

        elif self.op in (RFC6902_COPY,RFC6902_MOVE):
            self.op = op
            self.src = param

        else:
            raise JSONPatchItemException("Unknown operation.")
Example #28
0
    def testCase001(self):
        """Test a new branch
        """
        global configdata
        global appname
        global jsonpatchlist

        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'address': {u'city': u'New York', u'streetAddress': u'21 2nd Street', u'houseNumber': 12}}"""
        assert crepr == repr(configdata.data)

        a = JSONPointer("/phoneNumber/0/type")

        #variant A
        A = a.get_node(configdata.data, True)
        ret = configdata.branch_test(A['type'], 'home')
        assert ret == True

        #variant B
        B = a.get_node_or_value(configdata.data)
        ret = B == 'home'
        assert ret == True
Example #29
0
    def testCase901(self):
        """Access by constant references and by pointer.
        """
        global configdata

        # by pointer
        jsonptr = JSONPointer('/address')
        if not jsonptr:
            raise BaseException("Failed to create JSONPointer")
        jsonptr += 'streetAddress'

        assert jsonptr == u'/address/streetAddress'
Example #30
0
    def testCase100(self):
        c0 = [4]

        n3 = [[{'c0': c0}, {'c3': [3]}, [c0]]]
        n4 = {'x0': [[[3], {'c0': c0}, [c0]]]}
        n6 = [[[[n4]]]]
        n7 = [[n4]]
        n8 = {'x': {'c0': c0}}

        sl6 = [
            n3,
            n6,
            n4,
            n7,
            n8,
        ]

        p0 = JSONData.getPointerPath(n4['x0'][0][2][0], sl6, JSONData.ALL)
        resx = [[0, 0, 0, 'c0'], [0, 0, 2, 0],
                [1, 0, 0, 0, 0, 'x0', 0, 1, 'c0'],
                [1, 0, 0, 0, 0, 'x0', 0, 2, 0], [2, 'x0', 0, 1, 'c0'],
                [2, 'x0', 0, 2, 0], [3, 0, 0, 'x0', 0, 1, 'c0'],
                [3, 0, 0, 'x0', 0, 2, 0], [4, 'x', 'c0']]
        assert p0 == resx

        pathlst = []
        for rx in resx:
            pathlst.append(JSONPointer(rx).get_pointer())
        pathx = [
            u'/0/0/0/c0', u'/0/0/2/0', u'/1/0/0/0/0/x0/0/1/c0',
            u'/1/0/0/0/0/x0/0/2/0', u'/2/x0/0/1/c0', u'/2/x0/0/2/0',
            u'/3/0/0/x0/0/1/c0', u'/3/0/0/x0/0/2/0', u'/4/x/c0'
        ]
        assert pathlst == pathx

        vallst = []
        for rx in resx:
            vallst.append(JSONPointer(rx).get_node_or_value(sl6))
        vallstx = [[4], [4], [4], [4], [4], [4], [4], [4], [4]]
        assert vallst == vallstx