當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。