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


Python WorkspaceManager.openWorkspace方法代码示例

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


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

示例1: PluginsToModelControllerIntegration

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]
class PluginsToModelControllerIntegration(unittest.TestCase):

    def setUp(self):
        """
        Generic test to verify that the object exists and can be
        instantiated without problems.
        """
        self.dbManager = mock()
        self.changesController = mock()
        self.reportManager = mock()

        self.dbManager = DbManager()
        self.mappersManager = MapperManager()

        self.model_controller = controller.ModelController(mock(), self.mappersManager)
        self.workspace_manager = WorkspaceManager(self.dbManager,
                                             self.mappersManager,
                                             self.changesController,
                                             self.reportManager)
        self.workspace_manager.createWorkspace('temp_workspace', 'desc', DBTYPE.FS)
        self.workspace_manager.openWorkspace('temp_workspace')

        self._plugin_controller = PluginControllerForApi("test", {"nmap": nmap_plugin.NmapPlugin(),
                                                                    "nessus": nessus_plugin.NessusPlugin()}, mock())

        api.setUpAPIs(self.model_controller, self.workspace_manager)

    def tearDown(self): 
        self.workspace_manager.removeWorkspace('temp_workspace')

    def test_nmap_scan_saves_host(self):
        output_file = open(os.path.join(os.getcwd(), 'test_cases/data/nmap_plugin_with_api.xml'))
        output = output_file.read()
        self._plugin_controller.processCommandInput("nmap localhost")
        self._plugin_controller.onCommandFinished("nmap localhost", output)
        self.model_controller.processAllPendingActions()
        self.assertEquals(len(self.model_controller.getAllHosts()), 1,
                "Not all hosts added to model")

        host = self.model_controller.getAllHosts()[0]
        self.assertEquals(len(host.getAllInterfaces()), 1,
            "Not all interfaces added to model")

        interface = host.getAllInterfaces()[0]
        self.assertEquals(len(interface.getAllServices()), 3,
            "Not all services added to model")

        services = interface.getAllServices()
        self.assertTrue(all( [ s.getStatus() == 'open' for s in services]),
                "Port status not saved correctly")


    def test_nessus_scan_saves_host(self):
        output_file = open(os.path.join(os.getcwd(), 'test_cases/data/nessus_plugin_with_api.nessus'))
        output = output_file.read() 
        self._plugin_controller.processCommandInput("./nessus report")
        self._plugin_controller.onCommandFinished("./nessus report", output)
        self.model_controller.processAllPendingActions()
        self.assertEquals(len(self.model_controller.getAllHosts()), 7,
                "Not all hosts added to model")
开发者ID:BecomingMore,项目名称:faraday,代码行数:62,代码来源:plugins_controller_integration.py

示例2: testOpenWorkspaceChangesAndReportManagerWatch

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]
    def testOpenWorkspaceChangesAndReportManagerWatch(self):
        reportManager = mock()

        dbManager = mock()
        mappersManager = mock()
        dbConnector = mock()
        mappers = mock()
        changesController = mock()
        workspaceMapper = mock()

        workspace = Workspace('test_workspace', 'a desc')

        when(dbManager).getAllDbNames().thenReturn(['test_workspace'])
        when(dbManager).getConnector('test_workspace').thenReturn(dbConnector)
        when(mappersManager).createMappers(dbConnector).thenReturn(True)
        when(mappersManager).getMapper(Workspace.__name__).thenReturn(workspaceMapper)
        when(workspaceMapper).find('test_workspace').thenReturn(workspace)

        workspace_manager = WorkspaceManager(dbManager,
                                mappersManager,
                                changesController,
                                reportManager)


        opened_workspace = workspace_manager.openWorkspace('test_workspace')

        verify(reportManager).watch('test_workspace')
        verify(changesController).watch(mappersManager, dbConnector)
        self.assertEquals(opened_workspace.getName(), 'test_workspace')
开发者ID:BecomingMore,项目名称:faraday,代码行数:31,代码来源:workspace_manager.py

示例3: testOpenWorkspaceNoneExisting

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]
    def testOpenWorkspaceNoneExisting(self):
        dbManager = mock()
        mappersManager = mock()
        dbConnector = mock()
        mappers = mock()
        changesController = mock()

        workspace = Workspace('test_workspace', 'a desc') 
        when(dbManager).getAllDbNames().thenReturn([])

        workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock())
        opened_workspace = workspace_manager.openWorkspace('test_workspace')


        verify(mappersManager, times=0).createMappers(dbConnector)
        verify(mappersManager, times=0).find('test_workspace')
        self.assertFalse(opened_workspace, 'Workspace retrieved but non existing')
开发者ID:BecomingMore,项目名称:faraday,代码行数:19,代码来源:workspace_manager.py

示例4: testOpenWorkspaceSetsChangesCallback

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]
    def testOpenWorkspaceSetsChangesCallback(self):
        dbManager = mock()
        mappersManager = mock()
        dbConnector = mock()
        mappers = mock()
        changesController = mock()
        workspaceMapper = mock()

        workspace = Workspace('test_workspace', 'a desc')

        when(dbManager).getConnector('test_workspace').thenReturn(dbConnector)
        when(mappersManager).getMapper(Workspace.__name__).thenReturn(workspaceMapper)
        when(dbManager).getAllDbNames().thenReturn(['test_workspace'])
        when(mappersManager).createMappers(dbConnector).thenReturn(True)
        when(workspaceMapper).find('test_workspace').thenReturn(workspace)

        workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock())

        opened_workspace = workspace_manager.openWorkspace('test_workspace')

        verify(changesController).watch(mappersManager, dbConnector)
开发者ID:BecomingMore,项目名称:faraday,代码行数:23,代码来源:workspace_manager.py

示例5: MainApplication

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]
class MainApplication(object):
    """
    """

    def __init__(self, args):
        self._original_excepthook = sys.excepthook

        self._configuration = CONF

        self._security_manager = SecurityManager()
        self._mappers_manager = MapperManager()
        self._changes_controller = ChangeController()
        self._db_manager = DbManager()

        self._model_controller = ModelController(self._security_manager, self._mappers_manager)

        self._plugin_manager = PluginManager(os.path.join(CONF.getConfigPath(), "plugins"), self._mappers_manager)

        self._reports_manager = ReportManager(10, self._plugin_manager.createController("ReportManager"))

        self._workspace_manager = WorkspaceManager(
            self._db_manager, self._mappers_manager, self._changes_controller, self._reports_manager
        )

        self.gui_app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, args.gui)

        self.gui_app.setSplashImage(os.path.join(CONF.getImagePath(), "splash2.png"))

        self.timer = TimerClass()
        self.timer.start()

    def enableExceptHook(self):
        sys.excepthook = exception_handler
        installThreadExcepthook()

    def disableLogin(self):
        CONF.setAuth(sys.disablelogin)

    def start(self):
        try:

            self.gui_app.startSplashScreen()
            self.gui_app.splashMessage("Starting Faraday")

            signal.signal(signal.SIGINT, self.ctrlC)

            logged = True

            while True:

                username, password = "usuario", "password"

                if username is None and password is None:
                    break
                result = self._security_manager.authenticateUser(username, password)
                if result == codes.successfulLogin:
                    logged = True
                    break

            if logged:
                model.api.devlog("Starting application...")
                model.api.devlog("Setting up remote API's...")
                # We need to create the last used workspace (or the default
                # workspace) before we start the model controller and the
                # report manager

                last_workspace = CONF.getLastWorkspace()
                try:
                    if not self._workspace_manager.workspaceExists(last_workspace):
                        getLogger(self).info(
                            "Your last workspace ("
                            + str(last_workspace)
                            + ") wasn't accessible, check configuration..."
                        )
                        self._workspace_manager.openDefaultWorkspace()
                        # self._workspace_manager.createWorkspace(last_workspace, 'default workspace, probably created already in couchb')
                    else:
                        self._workspace_manager.openWorkspace(last_workspace)
                except restkit.errors.Unauthorized:
                    print "You are trying to enter CouchDB with authentication"
                    print "Add your credentials to your user configuration file in $HOME/.faraday/config/user.xml"
                    print "For example: <couch_uri>http://john:[email protected]:5984</couch_uri>"
                    return

                model.api.setUpAPIs(
                    self._model_controller, self._workspace_manager, CONF.getApiConInfoHost(), CONF.getApiConInfoPort()
                )
                model.guiapi.setUpGUIAPIs(self._model_controller)

                model.api.devlog("Starting model controller daemon...")

                self._model_controller.start()
                model.api.startAPIServer()
                restapi.startAPIs(
                    self._plugin_manager,
                    self._model_controller,
                    self._mappers_manager,
                    CONF.getApiConInfoHost(),
                    CONF.getApiRestfulConInfoPort(),
                )
#.........这里部分代码省略.........
开发者ID:diokhancze,项目名称:faraday,代码行数:103,代码来源:application.py

示例6: TestWorkspacesManagement

# 需要导入模块: from managers.model_managers import WorkspaceManager [as 别名]
# 或者: from managers.model_managers.WorkspaceManager import openWorkspace [as 别名]

#.........这里部分代码省略.........
        self.wm.createWorkspace(wname, 'desc', DBTYPE.FS)

        wpath = os.path.expanduser("~/.faraday/persistence/%s" % wname)
        self.assertTrue(os.path.exists(wpath))

        #Delete workspace
        self.wm.removeWorkspace(wname)
        self.assertFalse(os.path.exists(wpath))

    def test_list_workspaces(self):
        """ Lists FS workspaces and Couch workspaces """
        # First create workspaces manually 
        wnamefs = self.new_random_workspace_name()
        wnamecouch = self.new_random_workspace_name() 
        # FS
        self.wm.createWorkspace(wnamefs, 'a desc', DBTYPE.FS)
        # Couch
        self.wm.createWorkspace(wnamecouch, 'a desc', DBTYPE.COUCHDB)

        self.assertIn(wnamefs, self.wm.getWorkspacesNames(), 'FS Workspace not loaded')
        self.assertIn(wnamecouch, self.wm.getWorkspacesNames(), 'Couch Workspace not loaded')

        self.assertEquals(self.wm.getWorkspaceType(wnamecouch), 'CouchDB', 'Workspace type bad defined' )
        self.assertEquals(self.wm.getWorkspaceType(wnamefs), 'FS', 'Workspace type bad defined') 


    def test_get_workspace(self):
        """ Create a workspace, now ask for it """
        
        # When
        wname = self.new_random_workspace_name()
        workspace = self.wm.createWorkspace(wname, 'a desc', DBTYPE.FS)

        added_workspace = self.wm.openWorkspace(wname)

        # Then
        self.assertIsNotNone(workspace, 'Workspace added should not be none')
        self.assertEquals(workspace, added_workspace, 'Workspace created and added diffier')

    def _test_get_existent_couch_workspace(self): # Deprecate
        """ Create a workspace in the backend, now ask for it """
        
        # When
        wname = self.new_random_workspace_name()
        workspace = self.cdm.addWorkspace(wname)

        added_workspace = self.wm.getWorkspace(wname)

        # Then
        self.assertIsNotNone(added_workspace, 'Workspace added should not be none')

    def _test_get_existent_fs_workspace(self): # Deprecate
        """ Create a workspace in the backend, now ask for it """
        
        # When
        wname = self.new_random_workspace_name()
        workspace = self.fsm.addWorkspace(wname)
        self.wm.loadWorkspaces()

        added_workspace = self.wm.getWorkspace(wname)

        # Then
        self.assertIsNotNone(added_workspace, 'Workspace added should not be none')

    def test_get_non_existent_workspace(self):
        """ Retrieve a non existent workspace """
开发者ID:BwRy,项目名称:faraday,代码行数:70,代码来源:workspace.py


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