Esempio n. 1
0
def load():
    filename = raw_input('filename > ')
    print 'Importing', filename
    with open(filename) as f:
        cat = CatalogAPI(zport)
        for connection in json.load(f):
            cat.add_connection(Connection(**connection))
    commit()
Esempio n. 2
0
class TestCatalogAPI(BaseTestCase):
    def afterSetUp(self):
        super(TestCatalogAPI, self).afterSetUp()
        self.cat = CatalogAPI(self.app.zport, name="test_l2")
        self.cat.clear()
        self.connection = fake_connection('test_id')

    def test_catalog_is_empty(self):
        self.assertEqual(len(self.cat.search()), 0)

    def test_connection_is_added_to_catalog(self):
        self.cat.add_connection(self.connection)
        brains = self.cat.search()

        self.assertEqual(len(brains), 3)
        self.assertTrue('test_id' in [x.entity_id for x in brains])
        self.assertEqual(brains[0].layers, ('layer1', 'layer2', 'layer1'))

    def test_remove_connection(self):
        self.cat.add_connection(self.connection)
        self.cat.remove_connection(self.connection)
        brains = self.cat.search()

        self.assertEqual(len(brains), 0)

    def test_validate_connection(self):
        self.assertEqual(self.cat.validate_connection(self.connection),
                         self.connection)

    def test_search(self):
        self.cat.add_connection(self.connection)
        self.assertEqual(len(self.cat.search(entity_id='test_id')), 1)
        self.assertEqual(len(self.cat.search(entity_id='incorrect_id')), 0)

    def test_add_remove_node(self):
        cp = fake_connections_provider(self.dmd)
        self.assertEqual(len(self.cat.search()), 0)
        self.cat.add_node(cp)
        self.assertEqual(len(self.cat.search(entity_id='connection_id')), 1)
        self.cat.remove_node(cp)
        self.assertEqual(len(self.cat.search(entity_id='connection_id')), 0)

    def test_get_directly_connected(self):
        self.cat.add_node(fake_connections_provider(self.dmd))
        self.assertTrue(
            list(self.cat.get_directly_connected('connection_id')) ==
            ['connected_to1', 'connected_to2'])

    def test_get_reverse_connected(self):
        self.cat.add_node(fake_connections_provider(self.dmd))
        self.assertTrue(
            list(self.cat.get_reverse_connected('connected_to1')) ==
            ['connection_id'])

    def test_get_existing_layers(self):
        self.cat.add_node(fake_connections_provider(self.dmd))
        self.assertEqual(len(self.cat.get_existing_layers()), 2)

    def test_clear(self):
        self.cat.add_node(fake_connections_provider(self.dmd, 'con_id1'))
        self.cat.add_node(fake_connections_provider(self.dmd, 'con_id2'))
        self.cat.add_node(fake_connections_provider(self.dmd, 'con_id3'))
        self.cat.add_node(fake_connections_provider(self.dmd, 'con_id4'))
        self.cat.add_node(fake_connections_provider(self.dmd, 'con_id5'))
        self.assertEqual(len(self.cat.search()), 15)  # 5*3
        self.cat.clear()
        self.assertEqual(len(self.cat.search()), 0)