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


Python MapperManager.save方法代码示例

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


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

示例1: MapperManagerTestSuite

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

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

示例3: test_save_without_command

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

示例4: CompositeMapperTestSuite

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

示例5: MapperWithCouchDbManagerInegrationTest

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


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