Пример #1
0
class CatalogManagementIntTest(IonIntegrationTestCase):
    def setUp(self):
        super(CatalogManagementIntTest,self).setUp()

        self._start_container()
        self.container.start_rel_from_url('res/deploy/r2dm.yml')

        self.cms_cli = CatalogManagementServiceClient()
        self.rr_cli  = ResourceRegistryServiceClient()

    def test_create_catalog(self):
        #-------------------------------------
        # Tests basic catalog creation
        #-------------------------------------

        index1 = Index(name='index1')
        index1.options.attribute_match = ['common']
        index_id, _ = self.rr_cli.create(index1)

        catalog_id = self.cms_cli.create_catalog('common_catalog', ['common'])
        self.assertTrue(index_id in self.cms_cli.list_indexes(catalog_id))

    def test_create_catalog_matching(self):
        #-------------------------------------------
        # Tests catalog creation and index matching
        #-------------------------------------------

        indexes = [
            Index(name='index1'),
            Index(name='index2'),
            Index(name='index3')
        ]
        indexes[0].options = SearchOptions(**{ # Devices
            'attribute_match' : ['name','model','serial'],
            'geo_fields'      : ['nominal_location']
        })
        indexes[1].options = SearchOptions(**{ # BankAccount
            'attribute_match' : ['name','description','owner'],
            'range_fields'    : ['cash_balance']
        })
        indexes[2].options = SearchOptions(**{ # Hybrid
            'attribute_match' : ['name'],
            'range_fields'    : ['arc'],
            'geo_fields'      : ['nominal_location']
        })

        index_ids = list([ self.rr_cli.create(i)[0] for i in indexes])

        devices_catalog_id = self.cms_cli.create_catalog('devices_catalog', ['model'])
        self.assertTrue(index_ids[0] in self.cms_cli.list_indexes(devices_catalog_id), 'The catalog did\'nt match the correct index.')

        accounts_catalog_id = self.cms_cli.create_catalog('accounts_catalog', ['cash_balance'])
        self.assertTrue(index_ids[1] in self.cms_cli.list_indexes(accounts_catalog_id), 'The catalog did\'nt match the correct index.')
        
        geo_catalog_id = self.cms_cli.create_catalog('geo_catalog', ['nominal_location'])
        self.assertTrue(index_ids[2] in self.cms_cli.list_indexes(geo_catalog_id), 'The catalog did\'nt match the correct index.')

        names_catalog_id = self.cms_cli.create_catalog('names_catalog', ['name'])
        names_list = self.cms_cli.list_indexes(names_catalog_id)
        self.assertTrue(set(index_ids) == set(names_list), 'The catalog did\'nt match the correct index.')

    def test_catalog_field_exclusion(self):
        half_match = Index(name='half_match', options=SearchOptions(attribute_match=['one']))
        full_match = Index(name='full_match', options=SearchOptions(attribute_match=['one','two']))

        half_match_id, _ = self.rr_cli.create(half_match)
        full_match_id, _ = self.rr_cli.create(full_match)

        catalog_id = self.cms_cli.create_catalog('test_cat', keywords=['one','two'])
        index_list = self.cms_cli.list_indexes(catalog_id, id_only=True)
        self.assertTrue(index_list == [full_match_id])



    def test_update_catalog(self):
        empty_catalog_id = self.cms_cli.create_catalog('empty_catalog')

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        empty_catalog.description = 'testing update'
        self.cms_cli.update_catalog(empty_catalog)

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        self.assertTrue(empty_catalog.description == 'testing update')

    def test_read_catalog(self):
        catalog_res = Catalog(name='fake_catalog')
        catalog_id, _ = self.rr_cli.create(catalog_res)
        
        cat = self.cms_cli.read_catalog(catalog_id)
        self.assertTrue(cat.name == 'fake_catalog')

    def test_delete_catalog(self):
        empty_catalog_id, _ = self.rr_cli.create(Catalog(name='empty_catalog'))

        self.rr_cli.read(empty_catalog_id) # Throws exception if it doesn't exist

        self.cms_cli.delete_catalog(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.rr_cli.read(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.cms_cli.read_catalog(empty_catalog_id)
class CatalogManagementIntTest(IonIntegrationTestCase):
    def setUp(self):
        super(CatalogManagementIntTest,self).setUp()

        self._start_container()
        self.container.start_rel_from_url('res/deploy/r2dm.yml')

        self.cms_cli = CatalogManagementServiceClient()
        self.rr_cli  = ResourceRegistryServiceClient()

    def test_create_catalog(self):
        #-------------------------------------
        # Tests basic catalog creation
        #-------------------------------------

        index1 = Index(name='index1')
        index1.options.attribute_match = ['common']
        index_id, _ = self.rr_cli.create(index1)

        catalog_id = self.cms_cli.create_catalog('common_catalog', ['common'])
        self.assertTrue(index_id in self.cms_cli.list_indexes(catalog_id))

    def test_create_catalog_matching(self):
        #-------------------------------------------
        # Tests catalog creation and index matching
        #-------------------------------------------

        indexes = [
            Index(name='index1'),
            Index(name='index2'),
            Index(name='index3')
        ]
        indexes[0].options = SearchOptions(**{ # Devices
            'attribute_match' : ['name','model','serial'],
            'geo_fields'      : ['nominal_location']
        })
        indexes[1].options = SearchOptions(**{ # BankAccount
            'attribute_match' : ['name','description','owner'],
            'range_fields'    : ['cash_balance']
        })
        indexes[2].options = SearchOptions(**{ # Hybrid
            'attribute_match' : ['name'],
            'range_fields'    : ['arc'],
            'geo_fields'      : ['nominal_location']
        })

        index_ids = list([ self.rr_cli.create(i)[0] for i in indexes])

        devices_catalog_id = self.cms_cli.create_catalog('devices_catalog', ['model'])
        self.assertTrue(index_ids[0] in self.cms_cli.list_indexes(devices_catalog_id), 'The catalog did\'nt match the correct index.')

        accounts_catalog_id = self.cms_cli.create_catalog('accounts_catalog', ['cash_balance'])
        self.assertTrue(index_ids[1] in self.cms_cli.list_indexes(accounts_catalog_id), 'The catalog did\'nt match the correct index.')
        
        geo_catalog_id = self.cms_cli.create_catalog('geo_catalog', ['nominal_location'])
        self.assertTrue(index_ids[2] in self.cms_cli.list_indexes(geo_catalog_id), 'The catalog did\'nt match the correct index.')

        names_catalog_id = self.cms_cli.create_catalog('names_catalog', ['name'])
        names_list = self.cms_cli.list_indexes(names_catalog_id)
        for i in index_ids:
            self.assertIn(i,names_list)

    def test_catalog_field_exclusion(self):
        half_match = Index(name='half_match', options=SearchOptions(attribute_match=['one']))
        full_match = Index(name='full_match', options=SearchOptions(attribute_match=['one','two']))

        half_match_id, _ = self.rr_cli.create(half_match)
        full_match_id, _ = self.rr_cli.create(full_match)

        catalog_id = self.cms_cli.create_catalog('test_cat', keywords=['one','two'])
        index_list = self.cms_cli.list_indexes(catalog_id, id_only=True)
        self.assertTrue(index_list == [full_match_id])



    def test_update_catalog(self):
        empty_catalog_id = self.cms_cli.create_catalog('empty_catalog')

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        empty_catalog.description = 'testing update'
        self.cms_cli.update_catalog(empty_catalog)

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        self.assertTrue(empty_catalog.description == 'testing update')

    def test_read_catalog(self):
        catalog_res = Catalog(name='fake_catalog')
        catalog_id, _ = self.rr_cli.create(catalog_res)
        
        cat = self.cms_cli.read_catalog(catalog_id)
        self.assertTrue(cat.name == 'fake_catalog')

    def test_delete_catalog(self):
        empty_catalog_id, _ = self.rr_cli.create(Catalog(name='empty_catalog'))

        self.rr_cli.read(empty_catalog_id) # Throws exception if it doesn't exist

        self.cms_cli.delete_catalog(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.rr_cli.read(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.cms_cli.read_catalog(empty_catalog_id)
class CatalogManagementIntTest(IonIntegrationTestCase):
    def setUp(self):
        super(CatalogManagementIntTest, self).setUp()

        self._start_container()
        self.container.start_rel_from_url("res/deploy/r2dm.yml")

        self.cms_cli = CatalogManagementServiceClient()
        self.rr_cli = ResourceRegistryServiceClient()

    def test_create_catalog(self):
        # -------------------------------------
        # Tests basic catalog creation
        # -------------------------------------

        index1 = Index(name="index1")
        index1.options.attribute_match = ["common"]
        index_id, _ = self.rr_cli.create(index1)

        catalog_id = self.cms_cli.create_catalog("common_catalog", ["common"])
        self.assertTrue(index_id in self.cms_cli.list_indexes(catalog_id))

    def test_create_catalog_matching(self):
        # -------------------------------------------
        # Tests catalog creation and index matching
        # -------------------------------------------

        indexes = [Index(name="index1"), Index(name="index2"), Index(name="index3")]
        indexes[0].options = SearchOptions(
            **{"attribute_match": ["name", "model", "serial"], "geo_fields": ["nominal_location"]}  # Devices
        )
        indexes[1].options = SearchOptions(
            **{"attribute_match": ["name", "description", "owner"], "range_fields": ["cash_balance"]}  # BankAccount
        )
        indexes[2].options = SearchOptions(
            **{"attribute_match": ["name"], "range_fields": ["arc"], "geo_fields": ["nominal_location"]}  # Hybrid
        )

        index_ids = list([self.rr_cli.create(i)[0] for i in indexes])

        devices_catalog_id = self.cms_cli.create_catalog("devices_catalog", ["model"])
        self.assertTrue(
            index_ids[0] in self.cms_cli.list_indexes(devices_catalog_id), "The catalog did'nt match the correct index."
        )

        accounts_catalog_id = self.cms_cli.create_catalog("accounts_catalog", ["cash_balance"])
        self.assertTrue(
            index_ids[1] in self.cms_cli.list_indexes(accounts_catalog_id),
            "The catalog did'nt match the correct index.",
        )

        geo_catalog_id = self.cms_cli.create_catalog("geo_catalog", ["nominal_location"])
        self.assertTrue(
            index_ids[2] in self.cms_cli.list_indexes(geo_catalog_id), "The catalog did'nt match the correct index."
        )

        names_catalog_id = self.cms_cli.create_catalog("names_catalog", ["name"])
        names_list = self.cms_cli.list_indexes(names_catalog_id)
        self.assertTrue(set(index_ids) == set(names_list), "The catalog did'nt match the correct index.")

    def test_catalog_field_exclusion(self):
        half_match = Index(name="half_match", options=SearchOptions(attribute_match=["one"]))
        full_match = Index(name="full_match", options=SearchOptions(attribute_match=["one", "two"]))

        half_match_id, _ = self.rr_cli.create(half_match)
        full_match_id, _ = self.rr_cli.create(full_match)

        catalog_id = self.cms_cli.create_catalog("test_cat", keywords=["one", "two"])
        index_list = self.cms_cli.list_indexes(catalog_id, id_only=True)
        self.assertTrue(index_list == [full_match_id])

    def test_update_catalog(self):
        empty_catalog_id = self.cms_cli.create_catalog("empty_catalog")

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        empty_catalog.description = "testing update"
        self.cms_cli.update_catalog(empty_catalog)

        empty_catalog = self.rr_cli.read(empty_catalog_id)
        self.assertTrue(empty_catalog.description == "testing update")

    def test_read_catalog(self):
        catalog_res = Catalog(name="fake_catalog")
        catalog_id, _ = self.rr_cli.create(catalog_res)

        cat = self.cms_cli.read_catalog(catalog_id)
        self.assertTrue(cat.name == "fake_catalog")

    def test_delete_catalog(self):
        empty_catalog_id, _ = self.rr_cli.create(Catalog(name="empty_catalog"))

        self.rr_cli.read(empty_catalog_id)  # Throws exception if it doesn't exist

        self.cms_cli.delete_catalog(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.rr_cli.read(empty_catalog_id)

        with self.assertRaises(NotFound):
            self.cms_cli.read_catalog(empty_catalog_id)