Exemplo n.º 1
0
 def transactional_setup_method(self):
     """
     Sets up the environment for running the tests;
     creates a `FigureController` and an operation
     """
     self.init()
     self.figure_c = FigureController()
     self.operation = TestFactory.create_operation(test_user=self.test_user,
                                                   test_project=self.test_project)
Exemplo n.º 2
0
def init_cherrypy(arguments=None):
    #### Mount static folders from modules marked for introspection
    arguments = arguments or []
    CONFIGUER = TvbProfile.current.web.CHERRYPY_CONFIGURATION
    for module in arguments:
        module_inst = importlib.import_module(str(module))
        module_path = os.path.dirname(os.path.abspath(module_inst.__file__))
        CONFIGUER["/static_" + str(module)] = {'tools.staticdir.on': True,
                                               'tools.staticdir.dir': '.',
                                               'tools.staticdir.root': module_path}

    #### Mount controllers, and specify the root URL for them.
    cherrypy.tree.mount(BaseController(), "/", config=CONFIGUER)
    cherrypy.tree.mount(UserController(), "/user/", config=CONFIGUER)
    cherrypy.tree.mount(ProjectController(), "/project/", config=CONFIGUER)
    cherrypy.tree.mount(FigureController(), "/project/figure/", config=CONFIGUER)
    cherrypy.tree.mount(FlowController(), "/flow/", config=CONFIGUER)
    cherrypy.tree.mount(SettingsController(), "/settings/", config=CONFIGUER)
    cherrypy.tree.mount(HelpController(), "/help/", config=CONFIGUER)
    cherrypy.tree.mount(SimulatorController(), "/burst/", config=CONFIGUER)
    cherrypy.tree.mount(ParameterExplorationController(), "/burst/explore/", config=CONFIGUER)
    cherrypy.tree.mount(DynamicModelController(), "/burst/dynamic/", config=CONFIGUER)
    cherrypy.tree.mount(SpatioTemporalController(), "/spatial/", config=CONFIGUER)
    cherrypy.tree.mount(RegionsModelParametersController(), "/burst/modelparameters/regions/", config=CONFIGUER)
    cherrypy.tree.mount(SurfaceModelParametersController(), "/spatial/modelparameters/surface/", config=CONFIGUER)
    cherrypy.tree.mount(RegionStimulusController(), "/spatial/stimulus/region/", config=CONFIGUER)
    cherrypy.tree.mount(SurfaceStimulusController(), "/spatial/stimulus/surface/", config=CONFIGUER)
    cherrypy.tree.mount(LocalConnectivityController(), "/spatial/localconnectivity/", config=CONFIGUER)
    cherrypy.tree.mount(NoiseConfigurationController(), "/burst/noise/", config=CONFIGUER)
    cherrypy.tree.mount(HPCController(), "/hpc/", config=CONFIGUER)

    cherrypy.config.update(CONFIGUER)

    # ----------------- Register additional request handlers -----------------
    # This tool checks for MAX upload size
    cherrypy.tools.upload = Tool('on_start_resource', RequestHandler.check_upload_size)
    # This tools clean up files on disk (mainly after export)
    cherrypy.tools.cleanup = Tool('on_end_request', RequestHandler.clean_files_on_disk)
    # ----------------- End register additional request handlers ----------------

    # Register housekeeping job
    if TvbProfile.current.hpc.IS_HPC_RUN and TvbProfile.current.hpc.CAN_RUN_HPC:
        cherrypy.engine.housekeeper = cherrypy.process.plugins.BackgroundTask(
            TvbProfile.current.hpc.BACKGROUND_JOB_INTERVAL, HPCOperationService.check_operations_job)
        cherrypy.engine.housekeeper.start()

    # HTTP Server is fired now ######
    cherrypy.engine.start()
Exemplo n.º 3
0
 def transactional_setup_method(self):
     self.init()
     self.figure_c = FigureController()
Exemplo n.º 4
0
class TestFigureController(BaseTransactionalControllerTest):
    """ Unit tests for FigureController """
    def transactional_setup_method(self):
        self.init()
        self.figure_c = FigureController()

    def transactional_teardown_method(self):
        """ Cleans the testing environment """
        self.cleanup()

    def test_displayresultfigures(self):
        """
        Tests result dictionary for the expected key/value
        """
        figure1 = TestFactory.create_figure(self.test_user.id,
                                            self.test_project.id,
                                            name="figure1",
                                            path="path-to-figure1",
                                            session_name="test")
        figure2 = TestFactory.create_figure(self.test_user.id,
                                            self.test_project.id,
                                            name="figure2",
                                            path="path-to-figure2",
                                            session_name="test")

        result_dict = self.figure_c.displayresultfigures()
        figures = result_dict['selected_sessions_data']['test']
        assert set([fig.id for fig in figures]) == {figure1.id, figure2.id}

    def test_editresultfigures_remove_fig(self):
        """
        Tests call to `editresultfigures` correctly redirects to '/project/figure/displayresultfigures'
        on figure removal
        """
        cherrypy.request.method = 'POST'
        figure1 = TestFactory.create_figure(self.test_user.id,
                                            self.test_project.id,
                                            name="figure1",
                                            path="path-to-figure1",
                                            session_name="test42")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test42")
        assert len(figs['test42']) == 1
        data = {'figure_id': figure1.id}

        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              remove_figure=True,
                              **data)

        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test42")
        assert len(figs['test42']) == 0

    def test_editresultfigures_rename_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session renaming
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.test_user.id,
                                  self.test_project.id,
                                  name="figure1",
                                  path="path-to-figure1",
                                  session_name="test")
        TestFactory.create_figure(self.test_user.id,
                                  self.test_project.id,
                                  name="figure2",
                                  path="path-to-figure2",
                                  session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test")
        assert len(figs['test']) == 2
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              rename_session=True,
                              **data)
        figs, previews = dao.get_previews(self.test_project.id,
                                          self.test_user.id, "test")
        assert len(figs['test']) == 0
        assert previews['test_renamed'] == 2

    def test_editresultfigures_remove_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session removal
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.test_user.id,
                                  self.test_project.id,
                                  name="figure1",
                                  path="path-to-figure1",
                                  session_name="test")
        TestFactory.create_figure(self.test_user.id,
                                  self.test_project.id,
                                  name="figure2",
                                  path="path-to-figure2",
                                  session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test")
        assert len(figs['test']) == 2
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              remove_session=True,
                              **data)
        figs, previews = dao.get_previews(self.test_project.id,
                                          self.test_user.id, "test")
        assert len(figs['test']) == 0
        assert previews == {}
class TestFigureController(BaseTransactionalControllerTest):
    """ Unit tests for FigureController """


    def transactional_setup_method(self):
        """
        Sets up the environment for running the tests;
        creates a `FigureController` and an operation
        """
        self.init()
        self.figure_c = FigureController()
        self.operation = TestFactory.create_operation(test_user=self.test_user,
                                                      test_project=self.test_project)
            
            
    def transactional_teardown_method(self):
        """ Cleans the testing environment """
        self.cleanup()


    def test_displayresultfigures(self):
        """
        Tests result dictionary for the expected key/value
        """
        figure1 = TestFactory.create_figure(self.operation.id, self.test_user.id, 
                                            self.test_project.id, name="figure1", 
                                            path="path-to-figure1", session_name="test")
        figure2 = TestFactory.create_figure(self.operation.id, self.test_user.id, 
                                            self.test_project.id, name="figure2", 
                                            path="path-to-figure2", session_name="test")

        result_dict = self.figure_c.displayresultfigures()
        figures = result_dict['selected_sessions_data']['test']
        assert set([fig.id for fig in figures]) == {figure1.id, figure2.id}
        
        
    def test_editresultfigures_remove_fig(self):
        """
        Tests call to `editresultfigures` correctly redirects to '/project/figure/displayresultfigures'
        on figure removal
        """
        cherrypy.request.method = 'POST'
        figure1 = TestFactory.create_figure(self.operation.id, self.test_user.id, 
                                            self.test_project.id, name="figure1", 
                                            path="path-to-figure1", session_name="test")
        figs = dao.get_figures_for_operation(self.operation.id)
        assert len(figs) == 1
        data = {'figure_id': figure1.id}
        self._expect_redirect('/project/figure/displayresultfigures', self.figure_c.editresultfigures,
                              remove_figure=True, **data)
        figs = dao.get_figures_for_operation(self.operation.id)
        assert len(figs) == 0
        
        
    def test_editresultfigures_rename_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session renaming
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.operation.id, self.test_user.id, self.test_project.id, name="figure1",
                                  path="path-to-figure1", session_name="test")
        TestFactory.create_figure(self.operation.id, self.test_user.id, self.test_project.id, name="figure2",
                                  path="path-to-figure2", session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id, "test")  
        assert len(figs['test']) == 2
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures', self.figure_c.editresultfigures,
                              rename_session=True, **data)
        figs, previews = dao.get_previews(self.test_project.id, self.test_user.id, "test")
        assert len(figs['test']) == 0
        assert previews['test_renamed'] == 2
            
            
    def test_editresultfigures_remove_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session removal
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.operation.id, self.test_user.id, self.test_project.id, name="figure1",
                                  path="path-to-figure1", session_name="test")
        TestFactory.create_figure(self.operation.id, self.test_user.id, self.test_project.id, name="figure2",
                                  path="path-to-figure2", session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id, "test")  
        assert len(figs['test']) == 2
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures', self.figure_c.editresultfigures,
                              remove_session=True, **data)
        figs, previews = dao.get_previews(self.test_project.id, self.test_user.id, "test")
        assert len(figs['test']) == 0
        assert previews == {}
Exemplo n.º 6
0
class FigureControllerTest(BaseTransactionalControllerTest):
    """ Unit tests for FigureController """
    def setUp(self):
        """
        Sets up the environment for running the tests;
        creates a `FigureController` and an operation
        """
        self.init()
        self.figure_c = FigureController()
        self.operation = TestFactory.create_operation(
            test_user=self.test_user, test_project=self.test_project)

    def tearDown(self):
        """ Cleans the testing environment """
        self.cleanup()

    def test_displayresultfigures(self):
        """
        Tests result dictionary for the expected key/value
        """
        figure1 = TestFactory.create_figure(self.operation.id,
                                            self.test_user.id,
                                            self.test_project.id,
                                            name="figure1",
                                            path="path-to-figure1",
                                            session_name="test")
        figure2 = TestFactory.create_figure(self.operation.id,
                                            self.test_user.id,
                                            self.test_project.id,
                                            name="figure2",
                                            path="path-to-figure2",
                                            session_name="test")

        result_dict = self.figure_c.displayresultfigures()
        figures = result_dict['selected_sessions_data']['test']
        self.assertEqual(set([fig.id for fig in figures]),
                         {figure1.id, figure2.id})

    def test_editresultfigures_remove_fig(self):
        """
        Tests call to `editresultfigures` correctly redirects to '/project/figure/displayresultfigures'
        on figure removal
        """
        cherrypy.request.method = 'POST'
        figure1 = TestFactory.create_figure(self.operation.id,
                                            self.test_user.id,
                                            self.test_project.id,
                                            name="figure1",
                                            path="path-to-figure1",
                                            session_name="test")
        figs = dao.get_figures_for_operation(self.operation.id)
        self.assertEqual(len(figs), 1)
        data = {'figure_id': figure1.id}
        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              remove_figure=True,
                              **data)
        figs = dao.get_figures_for_operation(self.operation.id)
        self.assertEqual(len(figs), 0)

    def test_editresultfigures_rename_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session renaming
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.operation.id,
                                  self.test_user.id,
                                  self.test_project.id,
                                  name="figure1",
                                  path="path-to-figure1",
                                  session_name="test")
        TestFactory.create_figure(self.operation.id,
                                  self.test_user.id,
                                  self.test_project.id,
                                  name="figure2",
                                  path="path-to-figure2",
                                  session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test")
        self.assertEqual(len(figs['test']), 2)
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              rename_session=True,
                              **data)
        figs, previews = dao.get_previews(self.test_project.id,
                                          self.test_user.id, "test")
        self.assertEqual(len(figs['test']), 0)
        self.assertEqual(previews['test_renamed'], 2)

    def test_editresultfigures_remove_session(self):
        """
        Tests result dictionary has the expected keys / values and call to `editresultfigures`
        correctly redirects to '/project/figure/displayresultfigures' on session removal
        """
        cherrypy.request.method = 'POST'
        TestFactory.create_figure(self.operation.id,
                                  self.test_user.id,
                                  self.test_project.id,
                                  name="figure1",
                                  path="path-to-figure1",
                                  session_name="test")
        TestFactory.create_figure(self.operation.id,
                                  self.test_user.id,
                                  self.test_project.id,
                                  name="figure2",
                                  path="path-to-figure2",
                                  session_name="test")
        figs, _ = dao.get_previews(self.test_project.id, self.test_user.id,
                                   "test")
        self.assertEqual(len(figs['test']), 2)
        data = {'old_session_name': 'test', 'new_session_name': 'test_renamed'}
        self._expect_redirect('/project/figure/displayresultfigures',
                              self.figure_c.editresultfigures,
                              remove_session=True,
                              **data)
        figs, previews = dao.get_previews(self.test_project.id,
                                          self.test_user.id, "test")
        self.assertEqual(len(figs['test']), 0)
        self.assertEqual(previews, {})