Ejemplo n.º 1
0
 def transactional_setup_method(self):
     """
     Sets up the environment for testing;
     creates a `LocalConnectivityController`
     """
     self.init()
     self.local_p_c = LocalConnectivityController()
 def setUp(self):
     """
     Sets up the environment for testing;
     creates a `LolcalConnectivityController`
     """
     self.init()
     self.local_p_c = LocalConnectivityController()
class LocalConnectivityControllerTest(BaseTransactionalControllerTest):
    """ Unit tests for LocalConnectivityController """
    def setUp(self):
        """
        Sets up the environment for testing;
        creates a `LolcalConnectivityController`
        """
        self.init()
        self.local_p_c = LocalConnectivityController()

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

    def _default_checks(self, result_dict):
        """
        Check for some info that should be true for all steps from the
        local connectivity controller.
        """
        self.assertEqual(result_dict['data'], {})
        self.assertTrue(
            isinstance(result_dict['existentEntitiesInputList'], list))

    def test_step_1(self):
        """
        Test that the dictionary returned by the controller for the LC Workflow first step is correct.
        """
        result_dict = self.local_p_c.step_1(1)
        self._default_checks(result_dict)
        self.assertEqual(result_dict['equationViewerUrl'],
                         '/spatial/localconnectivity/get_equation_chart')
        self.assertTrue(isinstance(result_dict['inputList'], list))
        self.assertEqual(result_dict['mainContent'],
                         'spatial/local_connectivity_step1_main')
        self.assertEqual(result_dict['next_step_url'],
                         '/spatial/localconnectivity/step_2')
        self.assertEqual(
            result_dict['resetToDefaultUrl'],
            '/spatial/localconnectivity/reset_local_connectivity')
        self.assertEqual(
            result_dict['submit_parameters_url'],
            '/spatial/localconnectivity/create_local_connectivity')
        self.assertEqual(
            result_dict['resetToDefaultUrl'],
            '/spatial/localconnectivity/reset_local_connectivity')

    def test_step_2(self):
        """
        Test that the dictionary returned by the controller for the LC Workflow second step is correct.
        """
        context = ContextLocalConnectivity()
        cherrypy.session[KEY_LCONN_CONTEXT] = context
        result_dict = self.local_p_c.step_2()
        self._default_checks(result_dict)
        self.assertEqual(result_dict['loadExistentEntityUrl'],
                         '/spatial/localconnectivity/load_local_connectivity')
        self.assertEqual(result_dict['mainContent'],
                         'spatial/local_connectivity_step2_main')
        self.assertEqual(result_dict['next_step_url'],
                         '/spatial/localconnectivity/step_1')
class TestLocalConnectivityController(BaseTransactionalControllerTest):
    """ Unit tests for LocalConnectivityController """
    def transactional_setup_method(self):
        """
        Sets up the environment for testing;
        creates a `LocalConnectivityController`
        """
        self.init()
        self.local_p_c = LocalConnectivityController()

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

    @staticmethod
    def _default_checks(result_dict):
        """
        Check for some info that should be true for all steps from the
        local connectivity controller.
        """
        assert result_dict['data'] == {}
        assert isinstance(result_dict['existentEntitiesInputList'], dict)

    def test_step_1(self):
        """
        Test that the dictionary returned by the controller for the LC Workflow first step is correct.
        """
        result_dict = self.local_p_c.step_1(1)
        self._default_checks(result_dict)
        assert result_dict['baseUrl'] == '/spatial/localconnectivity'
        assert isinstance(result_dict['inputList'], dict)
        assert result_dict[
            'mainContent'] == 'spatial/local_connectivity_step1_main'
        assert result_dict[
            'next_step_url'] == '/spatial/localconnectivity/step_2'
        assert result_dict[
            'resetToDefaultUrl'] == '/spatial/localconnectivity/reset_local_connectivity'
        assert result_dict[
            'submit_parameters_url'] == '/spatial/localconnectivity/create_local_connectivity'
        assert result_dict[
            'resetToDefaultUrl'] == '/spatial/localconnectivity/reset_local_connectivity'

    def test_step_2(self, local_connectivity_index_factory):
        """
        Test that the dictionary returned by the controller for the LC Workflow second step is correct.
        """
        lconn_index, lconn = local_connectivity_index_factory()
        cherrypy.session[KEY_LCONN] = lconn
        result_dict = self.local_p_c.step_2()
        self._default_checks(result_dict)
        assert result_dict[
            'loadExistentEntityUrl'] == '/spatial/localconnectivity/load_local_connectivity'
        assert result_dict[
            'mainContent'] == 'spatial/local_connectivity_step2_main'
        assert result_dict[
            'next_step_url'] == '/spatial/localconnectivity/step_1'
class LocalConnectivityControllerTest(BaseTransactionalControllerTest):
    """ Unit tests for LocalConnectivityController """
    
    def setUp(self):
        """
        Sets up the environment for testing;
        creates a `LolcalConnectivityController`
        """
        self.init()
        self.local_p_c = LocalConnectivityController()


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

            
    def _default_checks(self, result_dict):
        """
        Check for some info that should be true for all steps from the
        local connectivity controller.
        """
        self.assertEqual(result_dict['data'], {})
        self.assertTrue(isinstance(result_dict['existentEntitiesInputList'], list))
    
    
    def test_step_1(self):
        """
        Test that the dictionary returned by the controller for the LC Workflow first step is correct.
        """
        result_dict = self.local_p_c.step_1(1)
        self._default_checks(result_dict)
        self.assertEqual(result_dict['equationViewerUrl'], 
                         '/spatial/localconnectivity/get_equation_chart')
        self.assertTrue(isinstance(result_dict['inputList'], list))
        self.assertEqual(result_dict['mainContent'], 'spatial/local_connectivity_step1_main')
        self.assertEqual(result_dict['next_step_url'], '/spatial/localconnectivity/step_2')
        self.assertEqual(result_dict['resetToDefaultUrl'], 
                         '/spatial/localconnectivity/reset_local_connectivity')
        self.assertEqual(result_dict['submit_parameters_url'], 
                         '/spatial/localconnectivity/create_local_connectivity')
        self.assertEqual(result_dict['resetToDefaultUrl'], 
                         '/spatial/localconnectivity/reset_local_connectivity')
        
        
    def test_step_2(self):
        """
        Test that the dictionary returned by the controller for the LC Workflow second step is correct.
        """
        context = ContextLocalConnectivity()
        cherrypy.session[KEY_LCONN_CONTEXT] = context
        result_dict = self.local_p_c.step_2()
        self._default_checks(result_dict)
        self.assertEqual(result_dict['loadExistentEntityUrl'], '/spatial/localconnectivity/load_local_connectivity')
        self.assertEqual(result_dict['mainContent'], 'spatial/local_connectivity_step2_main')
        self.assertEqual(result_dict['next_step_url'], '/spatial/localconnectivity/step_1')
 def setUp(self):
     """
     Sets up the environment for testing;
     creates a `LolcalConnectivityController`
     """
     self.init()
     self.local_p_c = LocalConnectivityController()
 def transactional_setup_method(self):
     """
     Sets up the environment for testing;
     creates a `LocalConnectivityController`
     """
     self.init()
     self.local_p_c = LocalConnectivityController()
Ejemplo n.º 8
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()