예제 #1
0
 def setUp(self):
     """
     Sets up the environment for testing;
     creates a `ProjectController`
     """
     BaseControllersTest.init(self)
     self.project_c = ProjectController()
예제 #2
0
class ProjectContollerTest(TransactionalTestCase, BaseControllersTest):
    """ Unit tests for burstcontroller """


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


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


    def test_index_no_project(self):
        """
        Index with no project selected should redirect to viewall page.
        """
        del cherrypy.session[b_c.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[b_c.KEY_PROJECT].id, self.test_project.id)
        self.assertEqual(result['subsection_name'], 'project')
        self.assertEqual(result[b_c.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']
        self.assertEqual(set([prj.name for prj in projects_list]), set(['prj1', 'prj2', 'prj3', 'Test']))
        self.assertEqual(result['page_number'], 1)
        self.assertEqual(result[b_c.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[b_c.KEY_MESSAGE_TYPE], b_c.TYPE_ERROR)
        self.assertEqual(result[b_c.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']))


    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')


    def test_readprojectsforlink(self):
        """
        Check that the dictionary of linkable projects is returned properly.
        """
        dt_factory = DatatypesFactory()
        cherrypy.session[b_c.KEY_USER] = dt_factory.user
        datatype = dt_factory.create_datatype_with_storage()
        result = self.project_c.readprojectsforlink(datatype.id)
        self.assertTrue(result is None)     # No projects to link into
        new_project = TestFactory.create_project(dt_factory.user)
        result = self.project_c.readprojectsforlink(datatype.id)
        self.assertEqual(result, '{"%s": "%s"}' % (new_project.id, new_project.name))
예제 #3
0
 def __init__(self):
     ProjectController.__init__(self)
     self.files_helper = FilesHelper()
     self.figure_service = FigureService()
예제 #4
0
def init_cherrypy(arguments=None):
    #### Mount static folders from modules marked for introspection
    arguments = arguments or []
    CONFIGUER = TVBSettings.CHERRYPY_CONFIGURATION
    for module in arguments:
        module_inst = __import__(str(module), globals(), locals(),
                                 ["__init__"])
        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(DTIPipelineController(),
                        "/pipeline/",
                        config=CONFIGUER)
    cherrypy.tree.mount(HelpController(), "/help/", config=CONFIGUER)
    cherrypy.tree.mount(BurstController(), "/burst/", config=CONFIGUER)
    cherrypy.tree.mount(ParameterExplorationController(),
                        "/burst/explore/",
                        config=CONFIGUER)
    cherrypy.tree.mount(SpatioTemporalController(),
                        "/spatial/",
                        config=CONFIGUER)
    cherrypy.tree.mount(RegionsModelParametersController(),
                        "/spatial/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.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 ----------------

    #### HTTP Server is fired now ######
    cherrypy.engine.start()
 def setUp(self):
     BaseControllersTest.init(self)
     self.project_c = ProjectController()