本文整理汇总了Python中managers.mapper_manager.MapperManager.getMapper方法的典型用法代码示例。如果您正苦于以下问题:Python MapperManager.getMapper方法的具体用法?Python MapperManager.getMapper怎么用?Python MapperManager.getMapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类managers.mapper_manager.MapperManager
的用法示例。
在下文中一共展示了MapperManager.getMapper方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandRunInformationMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class CommandRunInformationMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.mapper = self.mapper_manager.getMapper(CommandRunInformation.__name__)
def tearDown(self):
pass
def test_cmd_serialization(self):
import time
cmd = CommandRunInformation(**{
'workspace': 'fakews',
'itime': time.time(),
'command': "ping",
'params': "127.0.0.1"})
cmdserialized = self.mapper.serialize(cmd)
# if serialization fails, returns None
self.assertNotEqual(
cmdserialized,
None,
"Serialized cmd shouldn't be None")
# we check the cmd attributes
self.assertEquals(
cmdserialized.get("_id"),
cmd.getID(),
"Serialized ID is not the same as cmd ID")
self.assertEquals(
cmdserialized.get("command"),
cmd.__getattribute__("command"),
"Serialized name is not the same as cmd command")
self.assertEquals(
cmdserialized.get("params"),
cmd.__getattribute__("params"),
"Serialized name is not the same as cmd params")
def test_cmd_creation(self):
import time
cmd = CommandRunInformation(**{
'workspace': 'fakews',
'itime': time.time(),
'command': "ping",
'params': "127.0.0.1"})
self.mapper.save(cmd)
c = self.mapper.find(cmd.getID())
self.assertEquals(
c,
cmd,
"Cmd retrieved should be the same as persisted")
self.assertEquals(
c.getID(),
cmd.getID(),
"Cmd retrieved's Id should be the same as persisted's Id")
def test_load_nonexistent_cmd(self):
self.assertEquals(
self.mapper.load("1234"),
None,
"Nonexistent cmd should return None")
def test_find_not_loaded_cmd(self):
# we need to mock the persistence manager first,
# so we can return a simulated doc
doc = {
"_id": "1234",
"itime": 1409856507.891718,
"command": "ping",
"workspace": "fakews",
"duration": 0.6570961475372314,
"params": "127.0.0.1",
"type": "CommandRunInformation",
}
when(self.mapper.pmanager).getDocument("1234").thenReturn(doc)
cmd = self.mapper.find("1234")
self.assertNotEquals(
cmd,
None,
"Existent cmd shouldn't return None")
self.assertEquals(
cmd.__getattribute__("command"),
"ping",
"Cmd command should be ping")
def test_cmd_create_and_delete(self):
import time
cmd = CommandRunInformation(**{
'workspace': 'fakews',
'itime': time.time(),
'command': "ping",
'params': "127.0.0.1"})
self.mapper.save(cmd)
cmd_id = cmd.getID()
self.assertNotEquals(
self.mapper.load(cmd_id),
None,
#.........这里部分代码省略.........
示例2: WorkspaceMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class WorkspaceMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.wmapper = self.mapper_manager.getMapper(Workspace.__name__)
def tearDown(self):
pass
def test_workspace_serialization(self):
workspace = Workspace(name="workspace_test")
workspace.setDescription("Some description")
workspace.setCustomer("Infobyte")
wserialized = self.wmapper.serialize(workspace)
# if serialization fails, returns None
self.assertNotEqual(
wserialized,
None,
"Serialized workspace shouldn't be None")
# we check the host attributes
self.assertEquals(
wserialized.get("_id"),
workspace.getID(),
"Serialized ID is not the same as workspace ID")
self.assertEquals(
wserialized.get("name"),
workspace.getName(),
"Serialized name is not the same as workspace name")
self.assertEquals(
wserialized.get("description"),
workspace.getDescription(),
"Serialized description is not the same as workspace description")
self.assertEquals(
wserialized.get("customer"),
workspace.getCustomer(),
"Serialized customer is not the same as workspace customer")
def test_workspace_creation(self):
workspace = Workspace(name="workspace_test")
self.wmapper.save(workspace)
w = self.wmapper.find(workspace.getID())
self.assertEquals(
w,
workspace,
"Workspace retrieved should be the same as persisted")
self.assertEquals(
w.getID(),
workspace.getID(),
"Workspace retrieved's Id should be the same as persisted's Id")
def test_load_nonexistent_workspace(self):
self.assertEquals(
self.wmapper.load("Nonexistent"),
None,
"Nonexistent workspace should return None")
def test_find_not_loaded_workspace(self):
# we need to mock the persistence manager first,
# so we can return a simulated doc
doc = {
"type": "Workspace",
"_id": "workspace_test",
"name": "workspace_test",
"description": "some description",
"customer": "Infobyte",
"sdate": time(),
"fdate": time()
}
when(self.wmapper.pmanager).getDocument("workspace_test").thenReturn(doc)
workspace = self.wmapper.find("workspace_test")
self.assertNotEquals(
workspace,
None,
"Existent workspace shouldn't return None")
self.assertEquals(
workspace.getName(),
"workspace_test",
"Workspace name should be workspace_test")
self.assertEquals(
workspace.getCustomer(),
"Infobyte",
"Host os should be Infobyte")
def test_workspace_create_and_delete(self):
workspace = Workspace(name="workspace_test")
self.wmapper.save(workspace)
w_id = workspace.getID()
self.assertNotEquals(
self.wmapper.load(w_id),
None,
"Workspace should be saved")
self.wmapper.delete(w_id)
self.assertEquals(
self.wmapper.find(w_id),
#.........这里部分代码省略.........
示例3: ServiceMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class ServiceMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.smapper = self.mapper_manager.getMapper(Service.__name__)
def tearDown(self):
pass
def test_service_serialization(self):
srv = Service(name="http")
srv.setDescription("Some description")
srv.setOwned(True)
srv.setProtocol("tcp")
srv.setPorts(80)
srv.setStatus("open")
srv.setVersion("Apache 2.4")
sserialized = self.smapper.serialize(srv)
# if serialization fails, returns None
self.assertNotEqual(
sserialized,
None,
"Serialized service shouldn't be None")
# we check the service attributes
self.assertEquals(
sserialized.get("_id"),
srv.getID(),
"Serialized ID is not the same as Service ID")
self.assertEquals(
sserialized.get("name"),
srv.getName(),
"Serialized name is not the same as Service name")
self.assertEquals(
sserialized.get("protocol"),
srv.getProtocol(),
"Serialized protocol is not the same as Service protocol")
self.assertEquals(
sserialized.get("status"),
srv.getStatus(),
"Serialized status is not the same as Service status")
self.assertEquals(
sserialized.get("ports"),
srv.getPorts(),
"Serialized ports is not the same as Service ports")
self.assertEquals(
sserialized.get("description"),
srv.getDescription(),
"Serialized description is not the same as Interface description")
self.assertEquals(
sserialized.get("owned"),
srv.isOwned(),
"Serialized owned flag is not the same as Interface owned flag")
def test_service_creation(self):
srv = Service(name="http")
srv.setDescription("Some description")
srv.setOwned(True)
srv.setProtocol("tcp")
srv.setPorts(80)
srv.setStatus("open")
srv.setVersion("Apache 2.4")
self.smapper.save(srv)
s = self.smapper.find(srv.getID())
self.assertEquals(
s,
srv,
"Service retrieved should be the same as persisted")
self.assertEquals(
s.getID(),
srv.getID(),
"Service retrieved's Id should be the same as persisted's Id")
def test_load_nonexistent_service(self):
self.assertEquals(
self.smapper.load("1234"),
None,
"Nonexistent service should return None")
def test_find_not_loaded_service(self):
# we need to mock the persistence manager first,
# so we can return a simulated doc
doc = {
"type": "Service",
"_id": "1234",
"name": "http",
"owned": False,
"parent": None,
"owner": None,
"description": "some description",
"metadata": None,
"protocol": "tcp",
"status": "open",
"ports": [80],
"version": "Apache 2.4"
}
when(self.smapper.pmanager).getDocument("1234").thenReturn(doc)
srv = self.smapper.find("1234")
self.assertNotEquals(
#.........这里部分代码省略.........
示例4: HostMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class HostMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.hmapper = self.mapper_manager.getMapper(Host.__name__)
def tearDown(self):
pass
def test_host_serialization(self):
host = Host(name="pepito", os="linux")
host.setDescription("Some description")
host.setOwned(True)
hserialized = self.hmapper.serialize(host)
# if serialization fails, returns None
self.assertNotEqual(
hserialized,
None,
"Serialized host shouldn't be None")
# we check the host attributes
self.assertEquals(
hserialized.get("_id"),
host.getID(),
"Serialized ID is not the same as Host ID")
self.assertEquals(
hserialized.get("name"),
host.getName(),
"Serialized name is not the same as Host name")
self.assertEquals(
hserialized.get("os"),
host.getOS(),
"Serialized OS is not the same as Host OS")
self.assertEquals(
hserialized.get("description"),
host.getDescription(),
"Serialized description is not the same as Host description")
self.assertEquals(
hserialized.get("owned"),
host.isOwned(),
"Serialized owned flag is not the same as Host owned flag")
def test_host_creation(self):
host = Host(name="pepito", os="linux")
self.hmapper.save(host)
h = self.hmapper.find(host.getID())
self.assertEquals(
h,
host,
"Host retrieved should be the same as persisted")
self.assertEquals(
h.getID(),
host.getID(),
"Host retrieved's Id should be the same as persisted's Id")
def test_load_nonexistent_host(self):
self.assertEquals(
self.hmapper.load("1234"),
None,
"Nonexistent host should return None")
def test_find_not_loaded_host(self):
# we need to mock the persistence manager first,
# so we can return a simulated doc
doc = {
"type": "Host",
"_id": "1234",
"name": "pepito",
"owned": False,
"parent": None,
"owner": None,
"description": "some description",
"metadata": None,
"os": "linux",
"default_gateway": None
}
when(self.hmapper.pmanager).getDocument("1234").thenReturn(doc)
host = self.hmapper.find("1234")
self.assertNotEquals(
host,
None,
"Existent host shouldn't return None")
self.assertEquals(
host.getName(),
"pepito",
"Host name should be pepito")
self.assertEquals(
host.getOS(),
"linux",
"Host os should be linux")
def test_load_rubbish_host_doc(self):
# we need to mock the persistence manager first,
# so we can return an erroneous simulated doc
doc = {
"type": "RUBBISH",
"_id": "1234",
#.........这里部分代码省略.........
示例5: InterfaceMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class InterfaceMapperTestSuite(unittest.TestCase):
def setUp(self):
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.imapper = self.mapper_manager.getMapper(Interface.__name__)
def tearDown(self):
pass
def test_interface_serialization(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)
iserialized = self.imapper.serialize(iface)
# if serialization fails, returns None
self.assertNotEqual(
iserialized,
None,
"Serialized interface shouldn't be None")
# we check the interface attributes
self.assertEquals(
iserialized.get("_id"),
iface.getID(),
"Serialized ID is not the same as Interface ID")
self.assertEquals(
iserialized.get("name"),
iface.getName(),
"Serialized name is not the same as Interface name")
self.assertEquals(
iserialized.get("mac"),
iface.getMAC(),
"Serialized MAC is not the same as Interface MAC")
self.assertEquals(
iserialized.get("network_segment"),
iface.getNetworkSegment(),
"Serialized Network Segment is not the same as Interface Network Segment")
self.assertEquals(
iserialized.get("description"),
iface.getDescription(),
"Serialized description is not the same as Interface description")
self.assertEquals(
iserialized.get("owned"),
iface.isOwned(),
"Serialized owned flag is not the same as Interface owned flag")
def test_interface_creation(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)
self.imapper.save(iface)
i = self.imapper.find(iface.getID())
self.assertEquals(
i,
iface,
"Interface retrieved should be the same as persisted")
self.assertEquals(
i.getID(),
iface.getID(),
"Interface retrieved's Id should be the same as persisted's Id")
def test_load_nonexistent_interface(self):
self.assertEquals(
self.imapper.load("1234"),
None,
"Nonexistent interface should return None")
def test_find_not_loaded_interface(self):
# we need to mock the persistence manager first,
# so we can return a simulated doc
doc = {
"type": "Interface",
"_id": "1234",
"name": "192.168.10.168",
"owned": False,
"parent": None,
"owner": None,
"description": "some description",
"metadata": None,
"mac": "01:02:03:04:05:06",
#.........这里部分代码省略.........
示例6: MapperWithCouchDbManagerInegrationTest
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [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(
#.........这里部分代码省略.........
示例7: ModelObjectMapperTestSuite
# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import getMapper [as 别名]
class ModelObjectMapperTestSuite(unittest.TestCase):
def setUp(self):
Mappers[ModelObject.class_signature] = ModelObjectMapper
self.mapper_manager = MapperManager()
self.mapper_manager.createMappers(NullPersistenceManager())
self.mapper = self.mapper_manager.getMapper(ModelObject.__name__)
def tearDown(self):
pass
def test_metadata_deserialization(self):
import time
modelobject = ModelObject()
modelobject.updateID = lambda *args : 'ModelObjectID'
# {'create_time': 1417205460.253131,
# 'creator': 'ninja_owner',
# 'owner': 'ninja_owner',
# 'update_time': 1417205460.253132,
# 'update_user': 'ninja_owner'}
modelobjectserialized = {'name': '',
'parent': None,
'owner': '',
'_id': None,
'type': 'ModelObject',
'metadata': {'update_time': 1417207650.761777,
'update_user': '',
'update_action': 0,
'creator': '',
'create_time': 1417207650.761777,
'update_controller_action': 'No model controller call',
'owner': ''},
'owned': False,
'description': ''}
modelobject2 = self.mapper.unserialize(modelobject, modelobjectserialized)
metadata = modelobject2._metadata
metadataserialized = modelobjectserialized['metadata']
# if serialization fails, returns None
self.assertNotEqual(
modelobjectserialized,
None,
"Serialized ModelObejct shouldn't be None")
# we check the cmd attributes
self.assertEquals(
modelobjectserialized.get("_id"),
modelobject.getID(),
"Serialized ID is not the same as metadata ID")
import ipdb; ipdb.set_trace()
self.assertEquals(
metadataserialized.get("owner"),
metadata.__getattribute__("owner"),
"Serialized owner is not the same as metadata owner")
self.assertEquals(
metadataserialized.get("creator"),
metadata.__getattribute__("creator"),
"Serialized owner is not the same as metadata creator")
self.assertTrue(
isinstance(metadataserialized.get("create_time"), float),
"Serialized create_time is not int")
self.assertTrue(
isinstance(metadataserialized.get("update_time"), float),
"Serialized update_time is not int")
def test_metadata_serialization(self):
import time
modelobject = ModelObject()
modelobject.updateID = lambda *args : 'ModelObjectID'
metadata = Metadata('')
# {'create_time': 1417205460.253131,
# 'creator': 'ninja_owner',
# 'owner': 'ninja_owner',
# 'update_time': 1417205460.253132,
# 'update_user': 'ninja_owner'}
modelobjectserialized = self.mapper.serialize(modelobject)
metadataserialized = modelobjectserialized['metadata']
# if serialization fails, returns None
self.assertNotEqual(
modelobjectserialized,
None,
"Serialized ModelObejct shouldn't be None")
# we check the cmd attributes
self.assertEquals(
modelobjectserialized.get("_id"),
modelobject.getID(),
"Serialized ID is not the same as metadata ID")
self.assertEquals(
metadataserialized.get("creator"),
metadata.__getattribute__("creator"),
"Serialized owner is not the same as metadata creator")
self.assertEquals(
metadataserialized.get("owner"),
metadata.__getattribute__("owner"),
"Serialized owner is not the same as metadata owner")
self.assertTrue(
isinstance(metadataserialized.get("create_time"), float),
"Serialized create_time is not int")
self.assertTrue(
isinstance(metadataserialized.get("update_time"), float),
#.........这里部分代码省略.........