本文整理汇总了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):
示例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(
#.........这里部分代码省略.........