本文整理汇总了Python中managers.mapper_manager.MapperManager.find方法的典型用法代码示例。如果您正苦于以下问题:Python MapperManager.find方法的具体用法?Python MapperManager.find怎么用?Python MapperManager.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类managers.mapper_manager.MapperManager
的用法示例。
在下文中一共展示了MapperManager.find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MapperManagerTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import find [as 别名]
class MapperManagerTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
def tearDown(self):
pass
def test_create_and_retrieve_host(self):
self.mapper_manager.createMappers(NullPersistenceManager())
host = Host(name="pepito", os="linux")
host.setDescription("Some description")
host.setOwned(True)
self.mapper_manager.save(host)
h = self.mapper_manager.find(host.getID())
self.assertNotEquals(
h,
None,
"Host retrieved shouldn't be None")
self.assertEquals(
host,
h,
"Host created should be the same as host retrieved")
示例2: test_find_obj_by_id
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import find [as 别名]
def test_find_obj_by_id(self, obj_class, many_test_data, session, monkeypatch):
for test_data in many_test_data:
persisted_obj = test_data['factory'].create()
session.add(persisted_obj)
session.commit()
mapper_manager = MapperManager()
mapper_manager.createMappers(persisted_obj.workspace.name)
def mock_unsafe_io_with_server(host, test_data, server_io_function, server_expected_response, server_url, **payload):
mocked_response = test_data['mocked_response']
assert '{0}/ws/{1}/{2}/{3}/'.format(
_create_server_api_url(),
persisted_obj.workspace.name,
test_data['api_end_point'],
persisted_obj.id) == server_url
return MockResponse(mocked_response, 200)
monkeypatch.setattr(persistence.server.server, '_unsafe_io_with_server', partial(mock_unsafe_io_with_server, persisted_obj, test_data))
found_obj = mapper_manager.find(obj_class.class_signature, persisted_obj.id)
serialized_obj = test_data['get_properties_function'](found_obj)
if obj_class not in [Command]:
metadata = serialized_obj.pop('metadata')
assert serialized_obj == test_data['serialized_expected_results']
示例3: CompositeMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import find [as 别名]
class CompositeMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
def tearDown(self):
pass
def create_host(self):
host = Host(name="pepito", os="linux")
host.setDescription("Some description")
host.setOwned(True)
return host
def create_interface(self):
iface = Interface(name="192.168.10.168", mac="01:02:03:04:05:06")
iface.setDescription("Some description")
iface.setOwned(True)
iface.addHostname("www.test.com")
iface.setIPv4({
"address": "192.168.10.168",
"mask": "255.255.255.0",
"gateway": "192.168.10.1",
"DNS": "192.168.10.1"
})
iface.setPortsOpened(2)
iface.setPortsClosed(3)
iface.setPortsFiltered(4)
return iface
def test_find_composite_host(self):
'''
We are going to create a host, then save it.
Next we create an interface and then add it
to the host, and finally save it.
'''
# add host
host = self.create_host()
self.mapper_manager.save(host)
# add inteface
interface = self.create_interface()
host.addChild(interface)
self.mapper_manager.save(interface)
h = self.mapper_manager.find(host.getID())
self.assertEquals(
h.getAllInterfaces(),
host.getAllInterfaces(),
"Interfaces from original host should be equals to retrieved host's interfaces")
def test_load_composite_one_host_one_interface(self):
'''
We are going to create a host, then save it.
Next we create an interface and then add it
to the host, and finally save it.
'''
doc_host = {
"type": "Host",
"_id": "1234",
"name": "pepito",
"owned": False,
"parent": None,
"owner": None,
"description": "some description",
"metadata": None,
"os": "linux",
"default_gateway": None
}
doc_interface = {
"type": "Interface",
"_id": "5678",
"name": "192.168.10.168",
"owned": False,
"parent": "1234",
"owner": None,
"description": "some description",
"metadata": None,
"mac": "01:02:03:04:05:06",
"network_segment": None,
"hostnames": ["www.test.com"],
"ipv4": {
"address": "192.168.10.168",
"mask": "255.255.255.0",
"gateway": "192.168.10.1",
"DNS": "192.168.10.1"
},
"ipv6": {},
"ports": {
"opened": 2,
"closed": 3,
"filtered": 4,
}
}
pmanager = mock(NullPersistenceManager)
when(pmanager).getDocument("1234").thenReturn(doc_host)
when(pmanager).getDocument("5678").thenReturn(doc_interface)
when(pmanager).getChildren(any(str)).thenReturn([])
#.........这里部分代码省略.........
示例4: MapperWithCouchDbManagerInegrationTest
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import find [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(
#.........这里部分代码省略.........
示例5: TestWorkspacesManagement
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import find [as 别名]
class TestWorkspacesManagement(unittest.TestCase):
def setUp(self):
self.couch_uri = CONF.getCouchURI()
# self.cdm = CouchdbManager(uri=self.couch_uri)
wpath = os.path.expanduser("~/.faraday/persistence/" )
# self.fsm = FSManager(wpath)
self.dbManager = DbManager()
self.mappersManager = MapperManager()
self.changesController = ChangeController(self.mappersManager)
self.wm = WorkspaceManager(self.dbManager, self.mappersManager,
self.changesController)
self._fs_workspaces = []
self._couchdb_workspaces = []
def tearDown(self):
self.cleanCouchDatabases()
self.cleanFSWorkspaces()
# pass
def new_random_workspace_name(self):
return ("aworkspace" + "".join(random.sample(
[chr(i) for i in range(65, 90)], 10))).lower()
def cleanFSWorkspaces(self):
import shutil
basepath = os.path.expanduser("~/.faraday/persistence/")
for d in self._fs_workspaces:
wpath = os.path.join(basepath, d)
if os.path.isdir(wpath):
shutil.rmtree(wpath)
def cleanCouchDatabases(self):
try:
for wname in self._couchdb_workspaces:
self.cdm.removeWorkspace(wname)
except Exception as e:
print e
def test_create_fs_workspace(self):
"""
Verifies the creation of a filesystem workspace
"""
wname = self.new_random_workspace_name()
self._fs_workspaces.append(wname)
self.wm.createWorkspace(wname, 'desc', DBTYPE.FS)
wpath = os.path.expanduser("~/.faraday/persistence/%s" % wname)
self.assertTrue(os.path.exists(wpath))
def test_create_couch_workspace(self):
"""
Verifies the creation of a couch workspace
"""
wname = self.new_random_workspace_name()
self._couchdb_workspaces.append(wname)
self.wm.createWorkspace(wname, 'a desc', DBTYPE.COUCHDB)
res_connector = self.dbManager.getConnector(wname)
self.assertTrue(res_connector)
self.assertEquals(res_connector.getType(), DBTYPE.COUCHDB)
self.assertTrue(self.mappersManager.find(wname), "Workspace document not found")
wpath = os.path.expanduser("~/.faraday/persistence/%s" % wname)
self.assertFalse(os.path.exists(wpath))
# self.assertEquals(WorkspaceOnCouch.__name__, self.wm.getWorkspaceType(wname))
def test_delete_couch_workspace(self):
"""
Verifies the deletion of a couch workspace
"""
wname = self.new_random_workspace_name()
self.wm.createWorkspace(wname, 'a desc', DBTYPE.COUCHDB)
self.assertTrue(self.mappersManager.find(wname), "Workspace document not found")
#Delete workspace
self.wm.removeWorkspace(wname)
self.assertIsNone(self.mappersManager.find(wname))
self.assertFalse(self.dbManager.connectorExists(wname))
def test_delete_fs_workspace(self):
"""
Verifies the deletion of a filesystem workspace
"""
wname = self.new_random_workspace_name()
self.wm.createWorkspace(wname, 'desc', DBTYPE.FS)
wpath = os.path.expanduser("~/.faraday/persistence/%s" % wname)
self.assertTrue(os.path.exists(wpath))
#Delete workspace
self.wm.removeWorkspace(wname)
self.assertFalse(os.path.exists(wpath))
def test_list_workspaces(self):
#.........这里部分代码省略.........