예제 #1
0
  def test_it_moves(self):
    origin_pointer = Pointer(self.dictionary)
    pointer = origin_pointer.move('result').move('items').move(0).move('id')
    
    self.assertEqual(pointer.path(), '#.result.items[0].id')
    self.assertEqual(pointer.value(), self.dictionary['result']['items'][0]['id'])

    self.assertEqual(origin_pointer.path(), '#')
    self.assertEqual(origin_pointer.value(), self.dictionary)
예제 #2
0
    def test_it_moves(self):
        origin_pointer = Pointer(self.dictionary)
        pointer = origin_pointer.move('result').move('items').move(0).move(
            'id')

        self.assertEqual(pointer.path(), '#.result.items[0].id')
        self.assertEqual(pointer.value(),
                         self.dictionary['result']['items'][0]['id'])

        self.assertEqual(origin_pointer.path(), '#')
        self.assertEqual(origin_pointer.value(), self.dictionary)
예제 #3
0
  def test_it_returns_value(self):
    pointer = Pointer(self.dictionary)
    self.assertEqual(pointer.value(), self.dictionary)

    pointer = Pointer(self.dictionary, ['result'])
    self.assertEqual(pointer.value(), self.dictionary['result'])

    pointer = Pointer(self.dictionary, ['result', 'total'])
    self.assertEqual(pointer.value(), self.dictionary['result']['total'])

    pointer = Pointer(self.dictionary, ['result', 'items'])
    self.assertEqual(pointer.value(), self.dictionary['result']['items'])

    pointer = Pointer(self.dictionary, ['result', 'items', 0])
    self.assertEqual(pointer.value(), self.dictionary['result']['items'][0])

    pointer = Pointer(self.dictionary, ['result', 'items', 0, 'id'])
    self.assertEqual(pointer.value(), self.dictionary['result']['items'][0]['id'])
예제 #4
0
    def test_it_returns_value(self):
        pointer = Pointer(self.dictionary)
        self.assertEqual(pointer.value(), self.dictionary)

        pointer = Pointer(self.dictionary, ['result'])
        self.assertEqual(pointer.value(), self.dictionary['result'])

        pointer = Pointer(self.dictionary, ['result', 'total'])
        self.assertEqual(pointer.value(), self.dictionary['result']['total'])

        pointer = Pointer(self.dictionary, ['result', 'items'])
        self.assertEqual(pointer.value(), self.dictionary['result']['items'])

        pointer = Pointer(self.dictionary, ['result', 'items', 0])
        self.assertEqual(pointer.value(),
                         self.dictionary['result']['items'][0])

        pointer = Pointer(self.dictionary, ['result', 'items', 0, 'id'])
        self.assertEqual(pointer.value(),
                         self.dictionary['result']['items'][0]['id'])