Пример #1
0
    def test_move(self):
        obj = {'foo': 42}
        response = move(obj, '/bar', '/foo')
        assert response == {'bar': 42}
        assert response != obj

        obj = {'foo': {'bar': 'baz'}}
        response = move(obj, '/bar', '/foo/bar')
        assert response == {'bar': 'baz', 'foo': {}}
Пример #2
0
    def test_move(self):
        obj = {'foo': 42}
        response = move(obj, '/bar', '/foo')
        assert response == {'bar': 42}
        assert response != obj

        obj = {'foo': {'bar': 'baz'}}
        response = move(obj, '/bar', '/foo/bar')
        assert response == {'bar': 'baz', 'foo': {}}
Пример #3
0
 def test_move_array_element(self):
     obj = {
         'foo': ['all', 'grass', 'cows', 'eat']
     }
     assert move(obj, '/foo/3', '/foo/1') == {
         'foo': ['all', 'cows', 'eat', 'grass']
     }
Пример #4
0
def test_move_value():
    obj = {'foo': {'bar': 'baz', 'waldo': 'fred'}, 'qux': {'corge': 'grault'}}
    assert move(obj, '/qux/thud', '/foo/waldo') == {
        'foo': {
            'bar': 'baz'
        },
        'qux': {
            'corge': 'grault',
            'thud': 'fred'
        }
    }
Пример #5
0
    def run(self, args):
        parse_pointer(args)
        parse_target(args)
        parse_document(args)

        from jsonspec.operations import move, Error
        from jsonspec.pointer import ParseError

        try:
            response = move(args.document, args.target, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #6
0
    def run(self, args):
        parse_pointer(args)
        parse_target(args)
        parse_document(args)

        from jsonspec.operations import move, Error
        from jsonspec.pointer import ParseError

        try:
            response = move(args.document, args.target, args.pointer)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #7
0
 def test_move_value(self):
     obj = {
         'foo': {
             'bar': 'baz',
             'waldo': 'fred'
         },
         'qux': {
             'corge': 'grault'
         }
     }
     assert move(obj, '/qux/thud', '/foo/waldo') == {
         'foo': {
             'bar': 'baz'
         },
         'qux': {
             'corge': 'grault',
             'thud': 'fred'
         }
     }
Пример #8
0
 def test_move_array_element(self):
     obj = {'foo': ['all', 'grass', 'cows', 'eat']}
     assert move(obj, '/foo/3', '/foo/1') == {
         'foo': ['all', 'cows', 'eat', 'grass']
     }