Exemplo n.º 1
0
 def transactional_setup_method(self):
     self.test_user = TestFactory.create_user('Rest_User')
     self.test_project = TestFactory.create_project(
         self.test_user, 'Rest_Project', users=[self.test_user.id])
     self.retrieve_resource = RetrieveDatatypeResource()
     self.get_operations_resource = GetOperationsForDatatypeResource()
     self.get_data_in_project_resource = GetDataInProjectResource()
Exemplo n.º 2
0
class TestDatatypeResource(RestResourceTest):
    def transactional_setup_method(self):
        self.test_user = TestFactory.create_user('Rest_User')
        self.test_project = TestFactory.create_project(
            self.test_user, 'Rest_Project', users=[self.test_user.id])
        self.retrieve_resource = RetrieveDatatypeResource()
        self.get_operations_resource = GetOperationsForDatatypeResource()
        self.get_data_in_project_resource = GetDataInProjectResource()

    def test_server_retrieve_datatype_inexistent_gid(self, mocker):
        self._mock_user(mocker)
        datatype_gid = "inexistent-gid"
        with pytest.raises(InvalidIdentifierException):
            self.retrieve_resource.get(datatype_gid=datatype_gid)

    def test_server_retrieve_datatype(self, mocker):
        self._mock_user(mocker)
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_96.zip')
        TestFactory.import_zip_connectivity(self.test_user, self.test_project,
                                            zip_path)

        datatypes_in_project = self.get_data_in_project_resource.get(
            project_gid=self.test_project.gid)
        assert type(datatypes_in_project) is list
        assert len(datatypes_in_project) == 1
        assert datatypes_in_project[0].type == ConnectivityIndex().display_type

        def send_file_dummy(path, as_attachment, attachment_filename):
            return (path, as_attachment, attachment_filename)

        # Mock flask.send_file to behave like send_file_dummy
        mocker.patch('flask.send_file', send_file_dummy)
        result = self.retrieve_resource.get(
            datatype_gid=datatypes_in_project[0].gid)

        assert type(result) is tuple
        assert result[1] is True
        assert os.path.basename(result[0]) == os.path.basename(result[2])

    def test_server_get_operations_for_datatype(self, mocker):
        self._mock_user(mocker)
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_96.zip')
        TestFactory.import_zip_connectivity(self.test_user, self.test_project,
                                            zip_path)

        datatypes_in_project = self.get_data_in_project_resource.get(
            project_gid=self.test_project.gid)
        assert type(datatypes_in_project) is list
        assert len(datatypes_in_project) == 1
        assert datatypes_in_project[0].type == ConnectivityIndex().display_type

        result = self.get_operations_resource.get(
            datatype_gid=datatypes_in_project[0].gid)
        assert type(result) is list
        assert len(result) > 3

    def transactional_teardown_method(self):
        FilesHelper().remove_project_structure(self.test_project.name)
Exemplo n.º 3
0
 def transactional_setup_method(self):
     self.data_resource = GetDataInProjectResource()
     self.operations_resource = GetOperationsInProjectResource()
     self.test_user = TestFactory.create_user('Rest_User')
     self.test_project_without_data = TestFactory.create_project(self.test_user, 'Rest_Project', users=[self.test_user.id])
     self.test_project_with_data = TestFactory.create_project(self.test_user, 'Rest_Project2', users=[self.test_user.id])
     zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_96.zip')
     TestFactory.import_zip_connectivity(self.test_user, self.test_project_with_data, zip_path)
class TestProjectResource(TransactionalTestCase):
    def transactional_setup_method(self):
        self.data_resource = GetDataInProjectResource()
        self.operations_resource = GetOperationsInProjectResource()
        self.test_user = TestFactory.create_user('Rest_User')
        self.test_project_without_data = TestFactory.create_project(
            self.test_user, 'Rest_Project')
        self.test_project_with_data = TestFactory.create_project(
            self.test_user, 'Rest_Project2')
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_96.zip')
        TestFactory.import_zip_connectivity(self.test_user,
                                            self.test_project_with_data,
                                            zip_path)

    def test_server_get_data_in_project_inexistent_gid(self):
        project_gid = "inexistent-gid"
        with pytest.raises(InvalidIdentifierException):
            self.data_resource.get(project_gid)

    def test_server_get_data_in_project_empty(self):
        project_gid = self.test_project_without_data.gid
        result = self.data_resource.get(project_gid)
        assert type(result) is list
        assert len(result) == 0

    def test_get_data_in_project(self):
        project_gid = self.test_project_with_data.gid

        result = self.data_resource.get(project_gid)
        assert type(result) is list
        assert len(result) > 0

    def test_server_get_operations_in_project_inexistent_gid(self):
        project_gid = "inexistent-gid"
        with pytest.raises(InvalidIdentifierException):
            self.operations_resource.get(project_gid)

    def test_server_get_operations_in_project_empty(self):
        project_gid = self.test_project_without_data.gid
        result = self.operations_resource.get(project_gid)
        assert type(result) is list
        assert len(result) == 0

    def test_get_operations_in_project(self):
        project_gid = self.test_project_with_data.gid
        result = self.operations_resource.get(project_gid)
        assert type(result) is list
        assert len(result) > 0

    def transactional_teardown_method(self):
        FilesHelper().remove_project_structure(
            self.test_project_with_data.name)
        FilesHelper().remove_project_structure(
            self.test_project_without_data.name)
Exemplo n.º 5
0
class TestProjectResource(RestResourceTest):
    def transactional_setup_method(self):
        self.data_resource = GetDataInProjectResource()
        self.operations_resource = GetOperationsInProjectResource()
        self.test_user = TestFactory.create_user('Rest_User')
        self.test_project_without_data = TestFactory.create_project(
            self.test_user, 'Rest_Project', users=[self.test_user.id])
        self.test_project_with_data = TestFactory.create_project(
            self.test_user, 'Rest_Project2', users=[self.test_user.id])
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_96.zip')
        TestFactory.import_zip_connectivity(self.test_user,
                                            self.test_project_with_data,
                                            zip_path)

    def test_server_get_data_in_project_inexistent_gid(self, mocker):
        self._mock_user(mocker)
        project_gid = "inexistent-gid"
        with pytest.raises(InvalidIdentifierException):
            self.data_resource.get(project_gid=project_gid)

    def test_server_get_data_in_project_empty(self, mocker):
        self._mock_user(mocker)
        project_gid = self.test_project_without_data.gid
        result = self.data_resource.get(project_gid=project_gid)
        assert type(result) is list
        assert len(result) == 0

    def test_get_data_in_project(self, mocker):
        self._mock_user(mocker)
        project_gid = self.test_project_with_data.gid

        result = self.data_resource.get(project_gid=project_gid)
        assert type(result) is list
        assert len(result) > 0

    def test_server_get_operations_in_project_inexistent_gid(self, mocker):
        self._mock_user(mocker)
        project_gid = "inexistent-gid"

        request_mock = mocker.patch.object(flask, 'request')
        request_mock.args = {Strings.PAGE_NUMBER: '1'}

        with pytest.raises(InvalidIdentifierException):
            self.operations_resource.get(project_gid=project_gid)

    def test_server_get_operations_in_project_empty(self, mocker):
        self._mock_user(mocker)
        project_gid = self.test_project_without_data.gid

        request_mock = mocker.patch.object(flask, 'request')
        request_mock.args = {Strings.PAGE_NUMBER: '1'}

        result = self.operations_resource.get(project_gid=project_gid)
        assert type(result) is dict
        assert len(result['operations']) == 0

    def test_get_operations_in_project(self, mocker):
        self._mock_user(mocker)
        project_gid = self.test_project_with_data.gid

        request_mock = mocker.patch.object(flask, 'request')
        request_mock.args = {Strings.PAGE_NUMBER: '1'}

        result = self.operations_resource.get(project_gid=project_gid)
        assert type(result) is dict
        assert len(result['operations']) > 0

    def transactional_teardown_method(self):
        storage_interface = StorageInterface()
        storage_interface.remove_project_structure(
            self.test_project_with_data.name)
        storage_interface.remove_project_structure(
            self.test_project_without_data.name)