Exemplo n.º 1
0
 def transactional_setup_method(self):
     """
     Sets up the environment for testing;
     creates a `ProjectController`
     """
     self.init()
     self.project_c = ProjectController()
 def setUp(self):
     """
     Sets up the environment for testing;
     creates a `ProjectController`
     """
     self.init()
     self.project_c = ProjectController()
 def setUp(self):
     """
     Sets up the environment for testing;
     creates a `ProjectController`
     """
     self.init()
     self.project_c = ProjectController()
 def transactional_setup_method(self):
     """
     Sets up the environment for testing;
     creates a `ProjectController`
     """
     self.init()
     self.project_c = ProjectController()
Exemplo n.º 5
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.º 6
0
class TestProjectController(BaseTransactionalControllerTest):
    """ Unit tests for ProjectController """
    def transactional_setup_method(self):
        """
        Sets up the environment for testing;
        creates a `ProjectController`
        """
        self.init()
        self.project_c = ProjectController()

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

    def test_index_no_project(self):
        """
        Index with no project selected should redirect to viewall page.
        """
        del cherrypy.session[common.KEY_PROJECT]
        self._expect_redirect('/project/viewall', self.project_c.index)

    def test_index(self):
        """
        Verifies that result dictionary has the expected keys / values
        """
        result = self.project_c.index()
        assert result['mainContent'] == "project/project_submenu"
        assert result[common.KEY_PROJECT].id == self.test_project.id
        assert result['subsection_name'] == 'project'
        assert result[common.KEY_USER].id == self.test_user.id

    def test_viewall_valid_data(self):
        """
        Create a bunch of projects and check that they are returned correctly.
        """
        project1 = TestFactory.create_project(self.test_user, 'prj1')
        TestFactory.create_project(self.test_user, 'prj2')
        TestFactory.create_project(self.test_user, 'prj3')
        result = self.project_c.viewall(selected_project_id=project1.id)
        projects_list = result['projectsList']
        ## Use this old version of SET builder, otherwise it will fain on Python 2.6
        assert set([prj.name for prj in projects_list
                    ]) == {'prj1', 'prj2', 'prj3', 'Test'}
        assert result['page_number'] == 1
        assert result[common.KEY_PROJECT].name == 'prj1'

    def test_viewall_invalid_projectid(self):
        """
        Try to pass on an invalid id for the selected project.
        """
        result = self.project_c.viewall(selected_project_id='invalid')
        assert result[common.KEY_MESSAGE_TYPE] == common.TYPE_ERROR
        assert result[common.KEY_PROJECT].id == self.test_project.id

    def test_viewall_post_create(self):
        """
        Test that you are redirected to edit project page in case of correct post.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/editone',
                              self.project_c.viewall,
                              create=True)

    def test_editone_cancel(self):
        """
        Test that cancel redirects to appropriate page.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project', self.project_c.editone, cancel=True)

    def test_editone_remove(self):
        """
        Test that a project is indeed deleted.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/viewall',
                              self.project_c.editone,
                              self.test_project.id,
                              delete=True)
        with pytest.raises(NoResultFound):
            dao.get_project_by_id(self.test_project.id)

    def test_editone_create(self):
        """
        Create a new project using the editone page.
        """
        data = dict(name="newly_created",
                    description="Some test descript.",
                    users=[],
                    administrator=self.test_user.username,
                    visited_pages=None)
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/viewall',
                              self.project_c.editone,
                              save=True,
                              **data)
        projects = dao.get_projects_for_user(self.test_user.id)
        assert len(projects) == 2

    def test_getmemberspage(self):
        """
        Get the first page of the members page.
        """
        users_count = dao.get_all_users(is_count=True)
        user = TestFactory.create_user('usr', 'display', 'pass')
        test_project = TestFactory.create_project(user, 'new_name')
        result = self.project_c.getmemberspage(1, test_project.id)
        assert result['usersMembers'] == [user.id]
        # Same users as before should be available since we created new one
        # as owned for the project.
        assert len(result['usersList']) == users_count

    def test_set_visibility_datatype(self, dummy_datatype_index_factory):
        """
        Set datatype visibility to true and false and check results are updated.
        """
        datatype = dummy_datatype_index_factory()
        assert datatype.visible
        self.project_c.set_visibility('datatype', datatype.gid, 'False')
        datatype = dao.get_datatype_by_gid(datatype.gid)
        assert not datatype.visible
        self.project_c.set_visibility('datatype', datatype.gid, 'True')
        datatype = dao.get_datatype_by_gid(datatype.gid)
        assert datatype.visible

    def test_set_visibility_operation(self, operation_factory):
        """
        Same flow of operations as per test_set_visibilty_datatype just for
        operation entity.
        """
        operation = operation_factory()
        assert operation.visible
        self.project_c.set_visibility('operation', operation.gid, 'False')
        operation = dao.get_operation_by_gid(operation.gid)
        assert not operation.visible
        self.project_c.set_visibility('operation', operation.gid, 'True')
        operation = dao.get_operation_by_gid(operation.gid)
        assert operation.visible

    def test_viewoperations(self, operation_factory):
        """ 
        Test the viewoperations from projectcontroller.
        """
        operation = operation_factory(test_user=self.test_user,
                                      test_project=self.test_project)
        result_dict = self.project_c.viewoperations(self.test_project.id)
        operation_list = result_dict['operationsList']
        assert len(operation_list) == 1
        assert operation_list[0]['id'] == str(operation.id)
        assert 'no_filter_selected' in result_dict
        assert 'total_op_count' in result_dict

    def test_get_datatype_details(self, dummy_datatype_index_factory):
        """
        Check for various field in the datatype details dictionary.
        """
        datatype = dummy_datatype_index_factory()
        dt_details = self.project_c.get_datatype_details(datatype.gid)
        assert dt_details['datatype_id'] == datatype.id
        assert dt_details['entity_gid'] == datatype.gid
        assert not dt_details['isGroup']
        assert dt_details['isRelevant']
        assert len(dt_details['overlay_indexes']) == len(
            dt_details['overlay_tabs_horizontal'])

    def test_get_linkable_projects(self, dummy_datatype_index_factory):
        """
        Test get linkable project, no projects linked so should just return none.
        """
        datatype = dummy_datatype_index_factory()
        result_dict = self.project_c.get_linkable_projects(
            datatype.id, False, False)
        assert result_dict['projectslinked'] is None
        assert result_dict['datatype_id'] == datatype.id

    def test_get_operation_details(self, operation_factory):
        """
        Verifies result dictionary has the expected keys / values after call to
        `get_operation_details(...`
        """
        operation = operation_factory(test_user=self.test_user,
                                      test_project=self.test_project,
                                      parameters='{"test" : "test"}')
        result_dict = self.project_c.get_operation_details(operation.gid)
        assert result_dict['entity_gid'] == operation.gid
        assert result_dict['nodeType'] == 'operation'
        operation_dict = result_dict['nodeFields'][1]
        assert operation_dict['burst_name']['value'] == ''
        assert operation_dict['count']['value'] == 1
        assert operation_dict['gid']['value'] == operation.gid
        assert operation_dict['operation_id']['value'] == operation.id

    def test_editstructure_invalid_proj(self):
        self._expect_redirect('/project', self.project_c.editstructure, None)

    def test_editproject_valid(self):
        """
        Pass valid project to edit structure and check some entries from result dict.
        """
        result_dict = self.project_c.editstructure(self.test_project.id)
        assert result_dict['mainContent'] == 'project/structure'
        assert result_dict['firstLevelSelection'] == 'Data_State'
        assert result_dict['secondLevelSelection'] == 'Data_Subject'
class ProjectControllerTest(BaseTransactionalControllerTest):
    """ Unit tests for ProjectController """


    def setUp(self):
        """
        Sets up the environment for testing;
        creates a `ProjectController`
        """
        self.init()
        self.project_c = ProjectController()


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


    def test_index_no_project(self):
        """
        Index with no project selected should redirect to viewall page.
        """
        del cherrypy.session[common.KEY_PROJECT]
        self._expect_redirect('/project/viewall', self.project_c.index)


    def test_index(self):
        """
        Verifies that result dictionary has the expected keys / values
        """
        result = self.project_c.index()
        self.assertEqual(result['mainContent'], "project_submenu")
        self.assertEqual(result[common.KEY_PROJECT].id, self.test_project.id)
        self.assertEqual(result['subsection_name'], 'project')
        self.assertEqual(result[common.KEY_USER].id, self.test_user.id)


    def test_viewall_valid_data(self):
        """
        Create a bunch of projects and check that they are returned correctly.
        """
        project1 = TestFactory.create_project(self.test_user, 'prj1')
        TestFactory.create_project(self.test_user, 'prj2')
        TestFactory.create_project(self.test_user, 'prj3')
        result = self.project_c.viewall(selected_project_id=project1.id)
        projects_list = result['projectsList']
        ## Use this old version of SET builder, otherwise it will fain on Python 2.6
        self.assertEqual(set([prj.name for prj in projects_list]), {'prj1', 'prj2', 'prj3', 'Test'})
        self.assertEqual(result['page_number'], 1)
        self.assertEqual(result[common.KEY_PROJECT].name, 'prj1')


    def test_viewall_invalid_projectid(self):
        """
        Try to pass on an invalid id for the selected project.
        """
        result = self.project_c.viewall(selected_project_id='invalid')
        self.assertEqual(result[common.KEY_MESSAGE_TYPE], common.TYPE_ERROR)
        self.assertEqual(result[common.KEY_PROJECT].id, self.test_project.id)


    def test_viewall_post_create(self):
        """
        Test that you are redirected to edit project page in case of correct post.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/editone', self.project_c.viewall, create=True)


    def test_editone_cancel(self):
        """
        Test that cancel redirects to appropriate page.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project', self.project_c.editone, cancel=True)


    def test_editone_remove(self):
        """
        Test that a project is indeed deleted.
        """
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/viewall', self.project_c.editone,
                              self.test_project.id, delete=True)
        self.assertRaises(NoResultFound, dao.get_project_by_id, self.test_project.id)


    def test_editone_create(self):
        """
        Create a new project using the editone page.
        """
        data = dict(name="newly_created",
                    description="Some test descript.",
                    users=[],
                    administrator=self.test_user.username,
                    visited_pages=None)
        cherrypy.request.method = "POST"
        self._expect_redirect('/project/viewall', self.project_c.editone, save=True, **data)
        projects = dao.get_projects_for_user(self.test_user.id)
        self.assertEqual(len(projects), 2)


    def test_getmemberspage(self):
        """
        Get the first page of the members page.
        """
        users_count = dao.get_all_users(is_count=True)
        user = TestFactory.create_user('usr', 'pass')
        test_project = TestFactory.create_project(user, 'new_name')
        result = self.project_c.getmemberspage(0, test_project.id)
        self.assertEqual(result['usersMembers'], [])
        # Same users as before should be available since we created new one
        # as owned for the project.
        self.assertEqual(len(result['usersList']), users_count)


    def test_set_visibility_datatype(self):
        """
        Set datatype visibility to true and false and check results are updated.
        """
        datatype = DatatypesFactory().create_datatype_with_storage()
        self.assertTrue(datatype.visible)
        self.project_c.set_visibility('datatype', datatype.gid, 'False')
        datatype = dao.get_datatype_by_gid(datatype.gid)
        self.assertFalse(datatype.visible)
        self.project_c.set_visibility('datatype', datatype.gid, 'True')
        datatype = dao.get_datatype_by_gid(datatype.gid)
        self.assertTrue(datatype.visible)


    def test_set_visibility_operation(self):
        """
        Same flow of operations as per test_set_visibilty_datatype just for
        operation entity.
        """
        dt_factory = DatatypesFactory()
        operation = dt_factory.operation
        self.assertTrue(operation.visible)
        self.project_c.set_visibility('operation', operation.gid, 'False')
        operation = dao.get_operation_by_gid(operation.gid)
        self.assertFalse(operation.visible)
        self.project_c.set_visibility('operation', operation.gid, 'True')
        operation = dao.get_operation_by_gid(operation.gid)
        self.assertTrue(operation.visible)


    def test_viewoperations(self):
        """ 
        Test the viewoperations from projectcontroller.
        """
        operation = TestFactory.create_operation(test_user=self.test_user,
                                                 test_project=self.test_project)
        result_dict = self.project_c.viewoperations(self.test_project.id)
        operation_list = result_dict['operationsList']
        self.assertEqual(len(operation_list), 1)
        self.assertEqual(operation_list[0]['id'], str(operation.id))
        self.assertTrue('no_filter_selected' in result_dict)
        self.assertTrue('total_op_count' in result_dict)


    def test_get_datatype_details(self):
        """
        Check for various field in the datatype details dictionary.
        """
        datatype = DatatypesFactory().create_datatype_with_storage()
        dt_details = self.project_c.get_datatype_details(datatype.gid)
        self.assertEqual(dt_details['datatype_id'], datatype.id)
        self.assertEqual(dt_details['entity_gid'], datatype.gid)
        self.assertFalse(dt_details['isGroup'])
        self.assertTrue(dt_details['isRelevant'])
        self.assertEqual(len(dt_details['overlay_indexes']), len(dt_details['overlay_tabs_horizontal']))


    def test_get_linkable_projects(self):
        """
        Test get linkable project, no projects linked so should just return none.
        """
        datatype = DatatypesFactory().create_datatype_with_storage()
        result_dict = self.project_c.get_linkable_projects(datatype.id, False, False)
        self.assertTrue(result_dict['projectslinked'] is None)
        self.assertEqual(result_dict['datatype_id'], datatype.id)


    def test_get_operation_details(self):
        """
        Verifies result dictionary has the expected keys / values after call to
        `get_operation_details(...`
        """
        operation = TestFactory.create_operation(test_user=self.test_user,
                                                 test_project=self.test_project,
                                                 parameters='{"test" : "test"}')
        result_dict = self.project_c.get_operation_details(operation.gid)
        self.assertEqual(result_dict['entity_gid'], operation.gid)
        self.assertEqual(result_dict['nodeType'], 'operation')
        operation_dict = result_dict['nodeFields'][0]
        self.assertEqual(operation_dict['burst_name']['value'], '')
        self.assertEqual(operation_dict['count']['value'], 1)
        self.assertEqual(operation_dict['gid']['value'], operation.gid)
        self.assertEqual(operation_dict['operation_id']['value'], operation.id)


    def test_editstructure_invalid_proj(self):
        self._expect_redirect('/project', self.project_c.editstructure, None)


    def test_editproject_valid(self):
        """
        Pass valid project to edit structure and check some entries from result dict.
        """
        result_dict = self.project_c.editstructure(self.test_project.id)
        self.assertEqual(result_dict['mainContent'], 'project/structure')
        self.assertEqual(result_dict['firstLevelSelection'], 'Data_State')
        self.assertEqual(result_dict['secondLevelSelection'], 'Data_Subject')
Exemplo n.º 8
0
 def __init__(self):
     ProjectController.__init__(self)
     self.storage_interface = StorageInterface()
     self.figure_service = FigureService()
Exemplo n.º 9
0
 def __init__(self):
     ProjectController.__init__(self)
     self.files_helper = FilesHelper()
     self.figure_service = FigureService()
Exemplo n.º 10
0
 def __init__(self):
     ProjectController.__init__(self)
     self.files_helper = FilesHelper()
     self.figure_service = FigureService()