Beispiel #1
0
 def test_single_node_store(self):
     new_node = {"key1": 1}
     state = graph_reducer([], add_node('http://example.com/node1',
                                        new_node))
     self.assertEqual(len(state), 1)
     self.assertEqual(state[0]['id'], 'http://example.com/node1')
     self.assertEqual(state[0]['key1'], 1)
Beispiel #2
0
 def test_store_nested(self):
     new_node = {"key1": 1, "nested1": {"key2": 2}}
     state = graph_reducer([], add_node('http://example.com/node1',
                                        new_node))
     self.assertEqual(len(state), 1)
     first_node = [
         node for node in state if node['id'] == 'http://example.com/node1'
     ][0]
     self.assertEqual(first_node['key1'], 1)
     nested_node = first_node['nested1']
     self.assertEqual(nested_node['key2'], 2)
     self.assertIsNone(nested_node.get('id'))
Beispiel #3
0
    def test_store_lists(self):
        new_node = {"key1": 1, "b_list": ["b", {"c": 3}]}

        state = graph_reducer([], add_node('http://example.com/node1',
                                           new_node))
        self.assertEqual(len(state), 1)
        root_node = get_node_by_id({'graph': state},
                                   'http://example.com/node1')
        self.assertEqual(root_node['id'], 'http://example.com/node1')
        self.assertEqual(root_node['key1'], 1)

        nested_node = root_node['b_list'][1]
        self.assertEqual(nested_node['c'], 3)
Beispiel #4
0
 def new_node_successfully_appends_to_state(self):
     new_node = {"key1": 1}
     state = graph_reducer([{
         "id": "_:b9000"
     }], add_node('http://example.com/node1', new_node))
     self.assertEqual(len(state), 2)