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


Python MapperManager.remove方法代码示例

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


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

示例1: CompositeMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import remove [as 别名]

#.........这里部分代码省略.........
        doc_service2 = {
            "type": "Service",
            "_id": "efgh",
            "name": "ssh",
            "owned": False,
            "parent": "5678",
            "owner": None,
            "description": "some description",
            "metadata": None,
            "protocol": "tcp",
            "status": "open",
            "ports": [22],
            "version": "OpenSSH"
        }

        self.pmanager = mock(NullPersistenceManager)
        when(self.pmanager).getDocument("1234").thenReturn(doc_host)
        when(self.pmanager).getDocument("5678").thenReturn(doc_interface)
        when(self.pmanager).getDocument("abcd").thenReturn(doc_service1)
        when(self.pmanager).getDocument("efgh").thenReturn(doc_service2)
        when(self.pmanager).getChildren(any(str)).thenReturn([])
        when(self.pmanager).getChildren("1234").thenReturn([{'_id': "5678", 'type': "Interface"}])
        when(self.pmanager).getChildren("5678").thenReturn([{'_id': "abcd", 'type': "Service"}, {'_id': "efgh", 'type': "Service"}])

        self.mapper_manager.createMappers(self.pmanager)

        # load the host first
        host = self.mapper_manager.find("1234")

        #then remove the interface
        iface_id = host.getInterface("5678").getID()
        host.deleteChild(iface_id)

        def fake_remove(id):
            when(self.pmanager).getDocument(id).thenReturn(None)
        when(self.pmanager).remove("5678").thenReturn(fake_remove("5678"))
        when(self.pmanager).remove("abcd").thenReturn(fake_remove("abcd"))
        when(self.pmanager).remove("efgh").thenReturn(fake_remove("efgh"))
        self.mapper_manager.remove(iface_id)

        # now we make sure that we have removed the interface
        # and the services

        self.assertEquals(
            len(host.getAllInterfaces()),
            0,
            "Host should have no interfaces")

        self.assertEquals(
            self.mapper_manager.find("5678"),
            None,
            "Service abcd shouldn't exist anymore")


        self.assertEquals(
            self.mapper_manager.find("abcd"),
            None,
            "Service abcd shouldn't exist anymore")

        self.assertEquals(
            self.mapper_manager.find("efgh"),
            None,
            "Service efgh shouldn't exist anymore")

    def test_load_composite_one_workspace_two_hosts(self):
开发者ID:BwRy,项目名称:faraday,代码行数:69,代码来源:mapper.py

示例2: MapperWithCouchDbManagerInegrationTest

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import remove [as 别名]
class MapperWithCouchDbManagerInegrationTest(unittest.TestCase):
    def setUp(self):
        self.db_name = self.new_random_workspace_name()

        self.couchdbmanager = CouchDbManager(CONF.getCouchURI())

        self.connector = self.couchdbmanager.createDb(self.db_name)
        self.mapper_manager = MapperManager()
        self.mapper_manager.createMappers(self.connector)

    def new_random_workspace_name(self):
        return ("aworkspace" + "".join(random.sample(
            [chr(i) for i in range(65, 90)], 10))).lower()

    def tearDown(self):
        self.couchdbmanager.deleteDb(self.db_name)
        time.sleep(3)

    def test_host_saving(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        self.assertNotEquals(
            self.connector.getDocument(host.getID()),
            None,
            "Document shouldn't be None")

        self.assertEquals(
            self.connector.getDocument(host.getID()).get("name"),
            host.getName(),
            "Document should have the same host name")

    def test_load_nonexistent_host_using_manager_find(self):
        self.assertEquals(
            self.connector.getDocument("1234"),
            None,
            "Nonexistent host should return None document")

        self.assertEquals(
            self.mapper_manager.find("1234"),
            None,
            "Nonexistent host should return None object")

    def test_load_nonexistent_host_using_mapper_find(self):
        self.assertEquals(
            self.connector.getDocument("1234"),
            None,
            "Nonexistent host should return None document")

        self.assertEquals(
            self.mapper_manager.getMapper(Host.__name__).find("1234"),
            None,
            "Nonexistent host should return None object")

    def test_find_not_loaded_host(self):
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)

        #create a set of mappers, so we have a clean map
        self.mapper_manager = MapperManager()
        self.mapper_manager.createMappers(self.connector)

        h = self.mapper_manager.find(host.getID())
        self.assertNotEquals(
            h,
            None,
            "Existent host shouldn't return None")

        self.assertEquals(
            h.getName(),
            "pepito",
            "Host name should be pepito")

        self.assertEquals(
            h.getOS(),
            "linux",
            "Host os should be linux")

    def test_host_create_and_delete(self):
        host = Host(name="coquito")
        self.mapper_manager.save(host)
        h_id = host.getID()

        self.assertNotEquals(
            self.mapper_manager.find(h_id),
            None,
            "Host should be in the mapper")

        self.assertNotEquals(
            self.connector.getDocument(h_id),
            None,
            "Host should be in the db")

        self.mapper_manager.remove(h_id)

        self.assertEquals(
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper_integration.py


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