Пример #1
0
    def test_can_scrub_revocationlist_from_graph(self):
        assertion_data = {
            'id': 'urn:uuid:339e3b02-8b45-4948-b8d9-3589ec0f75d4',
            'type': 'Assertion',
            'badge': 'urn:uuid:6cd431ae-3155-4a81-b404-3bdc4d64b10d'
        }
        badgeclass_data = {
            'id': assertion_data['badge'],
            'type': 'BadgeClass',
            'issuer': 'http://example.org/issuer'
        }
        issuer_data = {
            'id': 'http://example.org/issuer',
            'type': 'Issuer',
            'revocationList': 'http://example.org/revocations'
        }
        revocation_list = {
            'id': 'http://example.org/revocations',
            'revokedAssertions': [
                'urn:uuid:1fac23b6-f1f7-46bd-9247-b1a94c3f8aaa',
                'urn:uuid:486590d2-89ec-4f71-9c1e-63d1be796a95',
                {'uid': 'abc123'}
            ]
        }
        graph = [assertion_data, badgeclass_data, issuer_data, revocation_list]

        action = patch_node(revocation_list['id'], {'revokedAssertions': []})
        new_graph = graph_reducer(graph, action)

        self.assertEqual(len(new_graph), 4)
        rev_list = [n for n in new_graph if n['id'] == revocation_list['id']][0]
        self.assertEqual(rev_list['revokedAssertions'], [])
Пример #2
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)
Пример #3
0
    def test_update_node_reference(self):
        first_node = {'id': '_:b0', 'badge': 'http://example.org/old'}
        graph_state = [first_node]
        new_id = 'http://example.org/new'
        action = patch_node_reference([first_node['id'], 'badge'], new_id)

        graph_state = graph_reducer(graph_state, action)
        self.assertEqual(graph_state[0]['badge'], new_id)
Пример #4
0
    def test_patch_node(self):
        first_node = {'id': '_:b0', 'name': 'One'}
        second_node = {'id': '_:b1', 'name': 'Two'}

        action = patch_node(first_node['id'], {'name': 'New One'})
        state = graph_reducer([first_node, second_node], action)

        self.assertEqual(len(state), 2)
        updated_node = get_node_by_id({'graph': state}, first_node['id'])
        self.assertEqual(updated_node['name'], 'New One')
Пример #5
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'))
Пример #6
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)
Пример #7
0
    def test_reduce_compacted_output(self):
        self.setUpContextCache()

        data = {
            "@context": {
                "thing_we_call_you_by": "http://schema.org/name"
            },
            "thing_we_call_you_by": "Test Data"
        }

        task = add_task(JSONLD_COMPACT_DATA,
                        data=json.dumps(data),
                        node_id='_:b100')

        result, message, actions = jsonld_compact_data({}, task)

        state = graph_reducer([], actions[0])
        self.assertEqual(len(state), 1, "Node should be added to graph")
        self.assertEqual(state[0]['name'], data['thing_we_call_you_by'])
        self.assertEqual(state[0].get('id'), '_:b100',
                         "Node should have a blank id assigned")
Пример #8
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)