Ejemplo n.º 1
0
    def test_piecewise_add(self):
        er = ExternalResources('terms')

        # this is the term the user wants to use. They will need to specify this
        key = er._add_key('mouse')

        resource1 = er._add_resource(resource='resource0', uri='resource_uri0')
        # the user will have to supply this info as well. This is the information
        # needed to retrieve info about the controled term
        er._add_entity(key, resource1, '10090', 'uri')

        # The user can also pass in the container or it can be wrapped up under NWBFILE
        obj = er._add_object('object', 'species')

        # This could also be wrapped up under NWBFile
        er._add_object_key(obj, key)

        self.assertEqual(er.keys.data, [('mouse', )])
        self.assertEqual(er.entities.data, [(0, 0, '10090', 'uri')])
        self.assertEqual(er.objects.data, [('object', 'species')])
Ejemplo n.º 2
0
class TestExternalResourcesGetKey(TestCase):
    def setUp(self):
        self.er = ExternalResources('terms')

    def test_get_key(self):
        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key='key1',
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url21')

        keys = self.er.get_key('key1', 'uuid2', '')
        self.assertIsInstance(keys, Key)
        self.assertEqual(keys.idx, 1)

    def test_get_key_bad_arg(self):
        self.er._add_key('key2')
        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        with self.assertRaises(ValueError):
            self.er.get_key('key2', 'uuid1', '')

    @unittest.skip('Outdated do to privatization')
    def test_get_key_without_container(self):
        self.er = ExternalResources('terms')
        self.er._add_key('key1')
        keys = self.er.get_key('key1')
        self.assertIsInstance(keys, Key)

    def test_get_key_w_object_info(self):
        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key='key1',
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url21')
        keys = self.er.get_key('key1', 'uuid1', '')
        self.assertIsInstance(keys, Key)
        self.assertEqual(keys.key, 'key1')

    def test_get_key_w_bad_object_info(self):
        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key='key1',
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url21')

        with self.assertRaisesRegex(ValueError, "No key 'key2'"):
            self.er.get_key('key2', 'uuid1', '')

    def test_get_key_doesnt_exist(self):
        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key='key1',
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url21')
        with self.assertRaisesRegex(ValueError,
                                    "key 'bad_key' does not exist"):
            self.er.get_key('bad_key')

    @unittest.skip('Outdated do to privatization')
    def test_get_key_same_keyname_all(self):
        self.er = ExternalResources('terms')
        key1 = self.er._add_key('key1')
        key2 = self.er._add_key('key1')
        self.er.add_ref('uuid1',
                        key=key1,
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key=key2,
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url12')
        self.er.add_ref('uuid1',
                        key=self.er.get_key('key1', 'uuid1', ''),
                        resource_name='resource3',
                        resource_uri='resource_uri3',
                        entity_id="id13",
                        entity_uri='url13')

        keys = self.er.get_key('key1')

        self.assertIsInstance(keys, Key)
        self.assertEqual(keys[0].key, 'key1')
        self.assertEqual(keys[1].key, 'key1')

    def test_get_key_same_keyname_specific(self):
        self.er = ExternalResources('terms')

        self.er.add_ref('uuid1',
                        key='key1',
                        resource_name='resource1',
                        resource_uri='resource_uri1',
                        entity_id="id11",
                        entity_uri='url11')
        self.er.add_ref('uuid2',
                        key='key2',
                        resource_name='resource2',
                        resource_uri='resource_uri2',
                        entity_id="id12",
                        entity_uri='url12')
        self.er.add_ref('uuid1',
                        key=self.er.get_key('key1', 'uuid1', ''),
                        resource_name='resource3',
                        resource_uri='resource_uri3',
                        entity_id="id13",
                        entity_uri='url13')

        keys = self.er.get_key('key1', 'uuid1', '')
        self.assertIsInstance(keys, Key)
        self.assertEqual(keys.key, 'key1')
        self.assertEqual(self.er.keys.data, [('key1', ), ('key2', )])