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


Python mapper_manager.MapperManager类代码示例

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


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

示例1: MapperManagerTestSuite

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,代码行数:25,代码来源:mapper.py

示例2: test_find_not_loaded_host

    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")
开发者ID:BwRy,项目名称:faraday,代码行数:25,代码来源:mapper_integration.py

示例3: test_find

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,代码行数:16,代码来源:test_model_controller.py

示例4: setUp

    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)
开发者ID:BwRy,项目名称:faraday,代码行数:8,代码来源:mapper_integration.py

示例5: test_update_with_command

    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,代码行数:44,代码来源:test_managers_mapper_manager.py

示例6: test_update_without_command

    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,代码行数:44,代码来源:test_managers_mapper_manager.py

示例7: test_save_with_command

    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,代码行数:39,代码来源:test_managers_mapper_manager.py

示例8: test_save_without_command

    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,代码行数:38,代码来源:test_managers_mapper_manager.py

示例9: test_find_obj_by_id

    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,代码行数:23,代码来源:test_managers_mapper_manager.py

示例10: setUp

    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 = []
开发者ID:BwRy,项目名称:faraday,代码行数:14,代码来源:workspace.py

示例11: test_load_not_loaded_composite_host

    def test_load_not_loaded_composite_host(self):
        # add host
        host = Host(name="pepito", os="linux")
        host.setDescription("Some description")
        host.setOwned(True)
        self.mapper_manager.save(host)
        # add inteface
        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)
        host.addChild(iface)
        self.mapper_manager.save(iface)

        #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.assertEquals(
            len(h.getAllInterfaces()),
            len(host.getAllInterfaces()),
            "Interfaces from original host should be equals to retrieved host's interfaces")

        i = self.mapper_manager.find(h.getAllInterfaces()[0].getID())
        self.assertEquals(
            i.getID(),
            iface.getID(),
            "Interface's id' from original host should be equals to retrieved host's interface's id")
开发者ID:BwRy,项目名称:faraday,代码行数:38,代码来源:mapper_integration.py

示例12: CommandRunInformationMapperTestSuite

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,代码行数:101,代码来源:mapper.py

示例13: setUp

 def setUp(self):
     self.mapper_manager = MapperManager()
     self.mapper_manager.createMappers(NullPersistenceManager())
开发者ID:BwRy,项目名称:faraday,代码行数:3,代码来源:mapper.py

示例14: CompositeMapperTestSuite

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,代码行数:101,代码来源:mapper.py

示例15: setUp

 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__)
开发者ID:BecomingMore,项目名称:faraday,代码行数:5,代码来源:mapper.py


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