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': {}}
def test_move_array_element(self): obj = { 'foo': ['all', 'grass', 'cows', 'eat'] } assert move(obj, '/foo/3', '/foo/1') == { 'foo': ['all', 'cows', 'eat', 'grass'] }
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' } }
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))
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' } }
def test_move_array_element(self): obj = {'foo': ['all', 'grass', 'cows', 'eat']} assert move(obj, '/foo/3', '/foo/1') == { 'foo': ['all', 'cows', 'eat', 'grass'] }