当前位置: 首页>>代码示例>>Python>>正文


Python IndexManagementService.create_index方法代码示例

本文整理汇总了Python中ion.services.dm.inventory.index_management_service.IndexManagementService.create_index方法的典型用法代码示例。如果您正苦于以下问题:Python IndexManagementService.create_index方法的具体用法?Python IndexManagementService.create_index怎么用?Python IndexManagementService.create_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ion.services.dm.inventory.index_management_service.IndexManagementService的用法示例。

在下文中一共展示了IndexManagementService.create_index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: IndexManagementUnitTest

# 需要导入模块: from ion.services.dm.inventory.index_management_service import IndexManagementService [as 别名]
# 或者: from ion.services.dm.inventory.index_management_service.IndexManagementService import create_index [as 别名]
class IndexManagementUnitTest(PyonTestCase):
    def setUp(self):
        mock_clients = self._create_service_mock("index_management")
        self.index_management = IndexManagementService()
        self.index_management.clients = mock_clients

        self.rr_create = mock_clients.resource_registry.create
        self.rr_read = mock_clients.resource_registry.read
        self.rr_update = mock_clients.resource_registry.update
        self.rr_delete = mock_clients.resource_registry.delete
        self.rr_find_resources = mock_clients.resource_registry.find_resources
        self.rr_find_assocs = mock_clients.resource_registry.find_associations
        self.rr_find_subj = mock_clients.resource_registry.find_subjects
        self.rr_find_obj = mock_clients.resource_registry.find_objects
        self.rr_delete_assoc = mock_clients.resource_registry.delete_association

        self.get_datastore = Mock()
        self.db_create = Mock()

        self.get_datastore.return_value = DotDict({"datastore_name": "test_datastore"})
        self.index_management.container = DotDict({"datastore_manager": DotDict({"get_datastore": self.get_datastore})})
        self.index_management.elasticsearch_host = "notarealhost"
        self.index_management.elasticsearch_port = 9000
        self.index_name = "test_index"

    def test_create_index(self):
        """
        test_create_index
        Unit test for basic creation of an index
        """

        # Mocks
        self.rr_create.return_value = ("index_id", "rev")
        self.rr_find_resources.return_value = ([], [])

        retval = self.index_management.create_index(
            name="mock", content_type=IndexManagementService.ELASTICSEARCH_INDEX, options="ugh"
        )

        self.assertTrue(retval == "index_id", "invalid return value: %s" % retval)
        self.assertTrue(self.rr_create.called)

        retval = self.index_management.create_index(name="argh", content_type=IndexManagementService.COUCHDB_INDEX)

        self.assertTrue(retval == "index_id", "invalid return value: %s" % retval)

        with self.assertRaises(BadRequest):
            self.index_management.create_index(name="another", content_type="not_listed")

    def test_dup_index(self):
        # Mocks
        self.rr_find_resources.return_value = ([1], [1])

        # Execution
        with self.assertRaises(BadRequest):
            self.index_management.create_index("mock_index_id")

    def test_read_index(self):
        # mocks
        return_obj = dict(mock="mock")
        self.rr_read.return_value = return_obj

        # execution
        retval = self.index_management.read_index("mock_index_id")

        # assertions
        self.assertEquals(return_obj, retval, "The resource should be returned.")

    def test_update_index(self):
        with self.assertRaises(BadRequest):
            self.index_management.update_index()
        with self.assertRaises(BadRequest):
            self.index_management.update_index("hi")
        self.index_management.update_index(Index())

    def test_delete_index(self):

        self.index_management.delete_index("index_id")
        self.rr_delete.assert_called_with("index_id")

    def test_list_indexes(self):
        # Mocks
        self.rr_find_resources.return_value = (
            [
                DotDict({"_id": "1", "name": "1"}),
                DotDict({"_id": "2", "name": "2"}),
                DotDict({"_id": "3", "name": "3"}),
                DotDict({"_id": "4", "name": "4"}),
            ],
            [1, 2, 3, 4],
        )

        # Execution
        retval = self.index_management.list_indexes()

        # Assertions
        self.assertTrue(retval == {"1": "1", "2": "2", "3": "3", "4": "4"}, "Index mismatch")

    def test_find_indexes(self):
        self.index_management.list_indexes = Mock()
#.........这里部分代码省略.........
开发者ID:ooici-eoi,项目名称:coi-services,代码行数:103,代码来源:index_management_test.py


示例2: IndexManagementUnitTest

# 需要导入模块: from ion.services.dm.inventory.index_management_service import IndexManagementService [as 别名]
# 或者: from ion.services.dm.inventory.index_management_service.IndexManagementService import create_index [as 别名]
class IndexManagementUnitTest(PyonTestCase):
    def setUp(self):
        mock_clients = self._create_service_mock('index_management')
        self.index_management = IndexManagementService()
        self.index_management.clients = mock_clients

        self.rr_create = mock_clients.resource_registry.create
        self.rr_read   = mock_clients.resource_registry.read
        self.rr_update = mock_clients.resource_registry.update
        self.rr_delete = mock_clients.resource_registry.delete
        self.rr_find_resources = mock_clients.resource_registry.find_resources
        self.rr_find_assocs    = mock_clients.resource_registry.find_associations
        self.rr_find_subj      = mock_clients.resource_registry.find_subjects
        self.rr_find_obj       = mock_clients.resource_registry.find_objects
        self.rr_delete_assoc   = mock_clients.resource_registry.delete_association

        self.get_datastore = Mock()
        self.db_create = Mock()

        self.get_datastore.return_value = DotDict({'datastore_name':'test_datastore'})
        self.index_management.container = DotDict({
            'datastore_manager':DotDict({
                'get_datastore' : self.get_datastore
            })
        })
        self.index_management.elasticsearch_host = 'notarealhost'
        self.index_management.elasticsearch_port = 9000
        self.index_name = 'test_index'

    def test_create_index(self):
        '''
        test_create_index
        Unit test for basic creation of an index
        '''

        # Mocks
        self.rr_create.return_value = ('index_id','rev')
        self.rr_find_resources.return_value = ([],[])

        retval = self.index_management.create_index(name='mock', content_type=IndexManagementService.ELASTICSEARCH_INDEX, options='ugh')

        self.assertTrue(retval=='index_id','invalid return value: %s' % retval)
        self.assertTrue(self.rr_create.called)

        retval = self.index_management.create_index(name='argh', content_type=IndexManagementService.COUCHDB_INDEX)

        self.assertTrue(retval=='index_id','invalid return value: %s' % retval)

        with self.assertRaises(BadRequest):
            self.index_management.create_index(name='another', content_type='not_listed')

    def test_dup_index(self):
        # Mocks
        self.rr_find_resources.return_value = ([1],[1])

        # Execution
        with self.assertRaises(BadRequest):
            self.index_management.create_index('mock_index_id')


    def test_read_index(self):
        # mocks
        return_obj = dict(mock='mock')
        self.rr_read.return_value = return_obj

        # execution
        retval = self.index_management.read_index('mock_index_id')

        # assertions
        self.assertEquals(return_obj, retval, 'The resource should be returned.')


    def test_update_index(self):
        with self.assertRaises(BadRequest):
            self.index_management.update_index()
        with self.assertRaises(BadRequest):
            self.index_management.update_index('hi')
        self.index_management.update_index(Index())



    def test_delete_index(self):

        self.index_management.delete_index('index_id')
        self.rr_delete.assert_called_with('index_id')



    def test_list_indexes(self):
        # Mocks
        self.rr_find_resources.return_value = ([
                DotDict({'_id':'1','name':'1'}),
                DotDict({'_id':'2','name':'2'}),
                DotDict({'_id':'3','name':'3'}),
                DotDict({'_id':'4','name':'4'})
            ],[1,2,3,4])

        # Execution
        retval = self.index_management.list_indexes()

#.........这里部分代码省略.........
开发者ID:Bobfrat,项目名称:coi-services,代码行数:103,代码来源:index_management_test.py



注:本文中的ion.services.dm.inventory.index_management_service.IndexManagementService.create_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。