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


Python MapperManager.createMappers方法代码示例

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


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

示例1: MapperManagerTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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")
开发者ID:BwRy,项目名称:faraday,代码行数:27,代码来源:mapper.py

示例2: test_find

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [as 别名]
def test_find(get, url_endpoint, test_data, session):
    if 'api_result' in test_data:
        get.return_value = test_data['api_result']
    mappers_manager = MapperManager()
    pending_actions = Queue()
    controller = ModelController(mappers_manager, pending_actions)
    workspace = WorkspaceFactory.create()
    mappers_manager.createMappers(workspace.name)
    obj = test_data['factory'].create(workspace=workspace)
    session.add(obj)
    session.commit()
    result = controller.find(test_data['class_signature'], obj.id)
    assert get.called
    print(get.mock_calls[0][1][0])
    assert get.mock_calls[0][1][0].endswith(
        '/_api/v2/ws/{0}/{1}/{2}/'.format(workspace.name, url_endpoint, obj.id))
开发者ID:infobyte,项目名称:faraday,代码行数:18,代码来源:test_model_controller.py

示例3: test_update_with_command

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [as 别名]
    def test_update_with_command(self, many_test_data, monkeypatch, session):
        obj_class = many_test_data['class']
        if obj_class in [Command]:
            return
        workspace = WorkspaceFactory.create(name='test')
        command = CommandFactory.create(workspace=workspace)
        session.add(command)
        session.commit()
        mapper_manager = MapperManager()
        mapper_manager.createMappers(workspace.name)

        test_data = many_test_data
        raw_data = test_data['data']
        if test_data['parent']:
            parent = test_data['parent']['parent_factory'].create()
            session.add(parent)
            session.commit()
            test_data['data']['parent'] = parent.id
            test_data['data']['parent_type'] = test_data['parent']['parent_type']
            test_data['expected_payload']['parent'] = parent.id
            if obj_class in [Vuln, Credential]:
                test_data['expected_payload']['parent_type'] = test_data['parent']['parent_type']
        relational_model = test_data['factory'].create()
        session.add(relational_model)
        session.commit()
        def mock_server_put(put_url, update=False, expected_response=201, **params):
            assert put_url == '{0}/ws/test/{1}/{2}/?command_id={3}'.format(
                _create_server_api_url(),
                test_data['api_end_point'],
                test_data['id'],
                params['command_id'])
            assert expected_response == 200
            assert update == False
            return {
                'id': 1,
                'ok': True,
                'rev': ''
            }

        raw_data['id'] = relational_model.id
        test_data['id'] = relational_model.id
        monkeypatch.setattr(persistence.server.server, '_put', mock_server_put)
        obj = obj_class(raw_data, workspace.name)
        mapper_manager.update(obj, command.id)
开发者ID:infobyte,项目名称:faraday,代码行数:46,代码来源:test_managers_mapper_manager.py

示例4: test_update_without_command

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [as 别名]
    def test_update_without_command(self, many_test_data, monkeypatch, session):
        obj_class = many_test_data['class']
        workspace = WorkspaceFactory.create(name='test')
        mapper_manager = MapperManager()
        mapper_manager.createMappers(workspace.name)
        test_data = many_test_data
        relational_model = test_data['factory'].create()
        session.add(relational_model)
        session.commit()
        raw_data = test_data['data']
        if test_data['parent']:
            parent = test_data['parent']['parent_factory'].create()
            session.add(parent)
            session.commit()

            test_data['data']['parent'] = parent.id
            test_data['data']['parent_type'] = test_data['parent']['parent_type']
            if obj_class not in [Note, Command]:
                test_data['expected_payload']['parent'] = parent.id
            if obj_class in [Vuln, Credential]:
                test_data['expected_payload']['parent_type'] = test_data['parent']['parent_type']
        def mock_server_put(test_data, put_url, update=False, expected_response=201, **params):
            assert put_url == '{0}/ws/test/{1}/{2}/'.format(_create_server_api_url(), test_data['api_end_point'], test_data['id'])
            assert expected_response == 200
            assert update == False
            if obj_class not in [Command]:
                metadata = params.pop('metadata')
                assert metadata['owner'] == test_data['expected_payload']['owner']
            params.pop('command_id', None)
            test_data['expected_payload'].pop('command_id', None)
            assert params == test_data['expected_payload']

            return {
                'id': 1,
                'ok': True,
                'rev': ''
            }

        raw_data['id'] = relational_model.id
        test_data['id'] = relational_model.id
        monkeypatch.setattr(persistence.server.server, '_put', partial(mock_server_put, test_data))

        obj = obj_class(raw_data, workspace.name)
        mapper_manager.update(obj)
开发者ID:infobyte,项目名称:faraday,代码行数:46,代码来源:test_managers_mapper_manager.py

示例5: test_save_with_command

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [as 别名]
    def test_save_with_command(self, many_test_data, monkeypatch, session):
        obj_class = many_test_data['class']
        if obj_class == Command:
            return
        workspace = WorkspaceFactory.create(name='test')
        command = CommandFactory.create(workspace=workspace)
        session.commit()
        mapper_manager = MapperManager()
        mapper_manager.createMappers(workspace.name)
        test_data = many_test_data
        raw_data = test_data['data']
        if test_data['parent']:
            parent = test_data['parent']['parent_factory'].create()
            session.commit()

            test_data['data']['parent'] = parent.id
            test_data['data']['parent_type'] = test_data['parent']['parent_type']
            if obj_class not in [Note]:
                test_data['expected_payload']['parent'] = parent.id
            if obj_class in [Vuln, Credential]:
                test_data['expected_payload']['parent_type'] = test_data['parent']['parent_type']
        def mock_server_post(test_data, post_url, update=False, expected_response=201, **params):
            assert post_url == '{0}/ws/test/{1}/?command_id={2}'.format(_create_server_api_url(), test_data['api_end_point'], params['command_id'])
            assert expected_response == 201
            assert update == False
            metadata = params.pop('metadata')
            assert metadata['owner'] == test_data['expected_payload']['owner']
            params.pop('command_id')
            test_data['expected_payload'].pop('command_id')
            assert params == test_data['expected_payload']
            return {
                'id': 1,
                'ok': True,
                'rev': ''
            }

        monkeypatch.setattr(persistence.server.server, '_post', partial(mock_server_post, test_data))
        obj = obj_class(raw_data, workspace.name)
        mapper_manager.save(obj, command.id)
开发者ID:infobyte,项目名称:faraday,代码行数:41,代码来源:test_managers_mapper_manager.py

示例6: test_save_without_command

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [as 别名]
    def test_save_without_command(self, obj_class, many_test_data, monkeypatch, session):
        """
            This test verifies that the request made to the api are the expected ones
        """
        workspace = WorkspaceFactory.create(name='test')
        session.commit()
        mapper_manager = MapperManager()
        mapper_manager.createMappers(workspace.name)

        for test_data in many_test_data:
            raw_data = test_data['data']
            if test_data['parent']:
                parent = test_data['parent']['parent_factory'].create()
                session.commit()
                test_data['data']['parent'] = parent.id
                test_data['data']['parent_type'] = test_data['parent']['parent_type']
                if obj_class not in [Note, Command]:
                    test_data['expected_payload']['parent'] = parent.id
                if obj_class in [Vuln, Credential]:
                    test_data['expected_payload']['parent_type'] = test_data['parent']['parent_type']
            def mock_server_post(test_data, post_url, update=False, expected_response=201, **params):
                assert post_url == '{0}/ws/test/{1}/'.format(
                    _create_server_api_url(), test_data['api_end_point'])
                assert expected_response == 201
                assert update == False
                if obj_class not in [Command]:
                    metadata = params.pop('metadata')
                    assert metadata['owner'] == test_data['expected_payload']['owner']
                assert params == test_data['expected_payload']
                return {
                    'id': 1,
                    'ok': True,
                    'rev': ''
                }

            monkeypatch.setattr(persistence.server.server, '_post', partial(mock_server_post, test_data))
            obj = obj_class(raw_data, workspace.name)
            mapper_manager.save(obj)
开发者ID:perplext,项目名称:faraday,代码行数:40,代码来源:test_managers_mapper_manager.py

示例7: test_find_obj_by_id

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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']
开发者ID:perplext,项目名称:faraday,代码行数:25,代码来源:test_managers_mapper_manager.py

示例8: CompositeMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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([])
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例9: WorkspaceMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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),
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例10: CommandRunInformationMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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,
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例11: ServiceMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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(
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例12: HostMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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",
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例13: InterfaceMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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",
#.........这里部分代码省略.........
开发者ID:BwRy,项目名称:faraday,代码行数:103,代码来源:mapper.py

示例14: MapperWithCouchDbManagerInegrationTest

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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

示例15: ModelObjectMapperTestSuite

# 需要导入模块: from managers.mapper_manager import MapperManager [as 别名]
# 或者: from managers.mapper_manager.MapperManager import createMappers [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),
#.........这里部分代码省略.........
开发者ID:BecomingMore,项目名称:faraday,代码行数:103,代码来源:mapper.py


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