Example #1
0
    def test_create_project(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        organization = Mock(id=str(uuid.uuid4()))
        organization.name = "org"
        organizations = [organization]

        # and:
        project = Mock(organizationName="org")
        project.name = "proj"

        # when:
        swagger_client.api.listOrganizations.return_value.response = (
            BravadoResponseMock(
                result=organizations,
            )
        )
        swagger_client.api.createProject.return_value.response = BravadoResponseMock(
            result=project,
        )

        # then:
        self.assertEqual(
            "org/proj", create_project(name="org/proj", key="PRJ", api_token=API_TOKEN)
        )
Example #2
0
    def test_create_project_already_exists(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        organization = Mock(id=str(uuid.uuid4()))
        organization.name = "org"
        organizations = [organization]

        # when:
        swagger_client.api.listOrganizations.return_value.response = (
            BravadoResponseMock(
                result=organizations,
            )
        )
        swagger_client.api.createProject.side_effect = HTTPBadRequest(
            response=MagicMock(),
            swagger_result=MagicMock(
                code=None,
                errorType={"name": "validationError"},
                message=None,
                title="Validation Errors",
                type=None,
                validationErrors=[
                    {
                        "path": ["name"],
                        "errors": [{"errorCode": {"name": "ERR_NOT_UNIQUE"}}],
                    }
                ],
            ),
        )

        # then:
        with self.assertRaises(ProjectAlreadyExists):
            create_project(name="org/proj", key="PRJ", api_token=API_TOKEN)
Example #3
0
def test_bravado_response(mock_result):
    response_mock = BravadoResponseMock(mock_result)
    response = response_mock()

    assert response.result is mock_result
    assert isinstance(response.metadata, BravadoResponseMetadata)
    assert response.metadata._swagger_result is mock_result
def test_wes_run_workflow(mock_api_client):
    mock_run_id = {'run_id': 'foo'}

    mock_api_client.RunWorkflow.return_value.response = BravadoResponseMock(
        result=mock_run_id)
    client = wes_wrapper.WES(api_client=mock_api_client)
    test_run_id = client.run_workflow(request={})

    assert isinstance(test_run_id, dict)
    assert test_run_id == mock_run_id
def test_wes_get_run_status(mock_api_client):
    mock_run_status = {'run_id': 'foo', 'state': ''}

    mock_api_client.GetRunStatus.return_value.response = BravadoResponseMock(
        result=mock_run_status)
    client = wes_wrapper.WES(api_client=mock_api_client)
    test_run_status = client.get_run_status(id='foo')

    assert isinstance(test_run_status, dict)
    assert test_run_status == mock_run_status
def test_wes_list_runs(mock_api_client):
    mock_runs = ['foo', 'bar']

    mock_api_client.ListRuns.return_value.response = BravadoResponseMock(
        result=mock_runs)

    client = wes_wrapper.WES(api_client=mock_api_client)
    test_runs = client.list_runs()

    assert isinstance(test_runs, list)
    assert test_runs == mock_runs
def test_wes_get_service_info(mock_api_client):
    mock_service_info = {'workflow_type_versions': ['CWL', 'WDL']}

    mock_api_client.GetServiceInfo.return_value.response = BravadoResponseMock(
        result=mock_service_info)

    client = wes_wrapper.WES(api_client=mock_api_client)
    test_service_info = client.get_service_info()

    assert isinstance(test_service_info, dict)
    assert test_service_info == mock_service_info
Example #8
0
    def test_project_listing_empty(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        swagger_client.api.listProjects.return_value.response = BravadoResponseMock(
            result=Mock(entries=[])
        )

        # when:
        returned_projects = get_project_list(api_token=API_TOKEN)

        # then:
        self.assertEqual([], returned_projects)
Example #9
0
    def test_get_workflow_versions(self, mock_trs_client):
        mock_workflow_versions = [{'url': '', 'id': ''}, {'url': '', 'id': ''}]

        mock_response = BravadoResponseMock(result=mock_workflow_versions)
        operator = mock_trs_client.toolsIdVersionsGet
        operator.return_value.response = mock_response

        trs_instance = TRS(trs_id='mock_trs', api_client=mock_trs_client)
        test_workflow_versions = trs_instance.get_workflow_versions(
            id='mock_wf')

        assert isinstance(test_workflow_versions, list)
        assert test_workflow_versions == mock_workflow_versions
Example #10
0
    def test_get_workflow_descriptor_relative(self, mock_trs_client):
        mock_workflow_descriptor = {'content': '', 'url': ''}

        mock_response = BravadoResponseMock(result=mock_workflow_descriptor)
        operator = mock_trs_client.toolsIdVersionsVersionIdTypeDescriptorRelativePathGet
        operator.return_value.response = mock_response

        trs_instance = TRS(trs_id='mock_trs', api_client=mock_trs_client)
        test_workflow_descriptor = trs_instance.get_workflow_descriptor_relative(
            id='mock_wf', version_id='test', type='CWL', relative_path='')

        assert isinstance(test_workflow_descriptor, dict)
        assert test_workflow_descriptor == mock_workflow_descriptor
Example #11
0
    def test_get_workflow_files(self, mock_trs_client):
        mock_workflow_files = [{'path': '', 'file_type': ''}]

        mock_response = BravadoResponseMock(result=mock_workflow_files)
        operator = mock_trs_client.toolsIdVersionsVersionIdTypeFilesGet
        operator.return_value.response = mock_response

        trs_instance = TRS(trs_id='mock_trs', api_client=mock_trs_client)
        test_workflow_files = trs_instance.get_workflow_files(
            id='mock_wf', version_id='test', type='CWL')

        assert isinstance(test_workflow_files, list)
        assert test_workflow_files == mock_workflow_files
Example #12
0
    def test_get_metadata(self, mock_trs_client):
        mock_metadata = {
            'version': '1.0.0',
            'api_version': '1.0.0',
            'country': '',
            'friendly_name': 'mock_trs'
        }

        mock_response = BravadoResponseMock(result=mock_metadata)
        mock_trs_client.metadataGet.return_value.response = mock_response

        trs_instance = TRS(trs_id='mock_trs', api_client=mock_trs_client)
        test_metadata = trs_instance.get_metadata()

        assert isinstance(test_metadata, dict)
        assert test_metadata == mock_metadata
Example #13
0
    def test_project_members_empty(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        members = []
        swagger_client.api.listProjectMembers.return_value.response = (
            BravadoResponseMock(
                result=members,
            )
        )

        # when:
        returned_members = get_project_member_list(name="org/proj", api_token=API_TOKEN)

        # then:
        self.assertEqual({}, returned_members)
def test_wes_get_run(mock_api_client):
    mock_run_log = {
        'run_id': 'foo',
        'request': {},
        'state': '',
        'run_log': {},
        'task_logs': [],
        'outputs': {}
    }

    mock_api_client.GetRunLog.return_value.response = BravadoResponseMock(
        result=mock_run_log)
    client = wes_wrapper.WES(api_client=mock_api_client)
    test_run_log = client.get_run(id='foo')

    assert isinstance(test_run_log, dict)
    assert test_run_log == mock_run_log
Example #15
0
    def test_get_workflow(self, mock_trs_client):
        mock_workflow = {
            'url': '',
            'id': 'mock_wf',
            'organization': '',
            'author': '',
            'toolclass': {},
            'versions': []
        }

        mock_response = BravadoResponseMock(result=mock_workflow)
        mock_trs_client.toolsIdGet.return_value.response = mock_response

        trs_instance = TRS(trs_id='mock_trs', api_client=mock_trs_client)
        test_workflow = trs_instance.get_workflow('mock_wf')

        assert isinstance(test_workflow, dict)
        assert test_workflow == mock_workflow
Example #16
0
    def test_create_project_no_workspace(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        organization = Mock(id=str(uuid.uuid4()))
        organization.name = "org"
        organizations = [organization]

        # when:
        swagger_client.api.listOrganizations.return_value.response = (
            BravadoResponseMock(
                result=organizations,
            )
        )

        # then:
        with self.assertRaises(WorkspaceNotFound):
            create_project(name="not_an_org/proj", key="PRJ", api_token=API_TOKEN)
Example #17
0
    def test_project_listing(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        project1 = MagicMock(organizationName="org1")
        project1.name = "project1"
        project2 = MagicMock(organizationName="org2")
        project2.name = "project2"
        projects = Mock(entries=[project1, project2])
        swagger_client.api.listProjects.return_value.response = BravadoResponseMock(
            result=projects,
        )

        # when:
        returned_projects = get_project_list(api_token=API_TOKEN)

        # then:
        self.assertEqual(["org1/project1", "org2/project2"], returned_projects)
Example #18
0
    def test_workspace_members(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        members = [
            Mock(role="member", registeredMemberInfo=Mock(username="******")),
            Mock(role="owner", registeredMemberInfo=Mock(username="******")),
        ]
        swagger_client.api.listOrganizationMembers.return_value.response = (
            BravadoResponseMock(
                result=members,
            )
        )

        # when:
        returned_members = get_workspace_member_list(name="org2", api_token=API_TOKEN)

        # then:
        self.assertEqual({"tester1": "member", "tester2": "admin"}, returned_members)
Example #19
0
    def test_create_project_unknown_visibility(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        organization = Mock(id=str(uuid.uuid4()))
        organization.name = "org"
        organizations = [organization]

        # when:
        swagger_client.api.listOrganizations.return_value.response = (
            BravadoResponseMock(
                result=organizations,
            )
        )

        with self.assertRaises(UnsupportedValue):
            create_project(
                name="org/proj",
                key="PRJ",
                visibility="unknown_value",
                api_token=API_TOKEN,
            )
Example #20
0
    def test_project_members(self, swagger_client_factory):
        swagger_client = self._get_swagger_client_mock(swagger_client_factory)

        # given:
        members = [
            Mock(role="member", registeredMemberInfo=Mock(username="******")),
            Mock(role="manager", registeredMemberInfo=Mock(username="******")),
            Mock(role="viewer", registeredMemberInfo=Mock(username="******")),
        ]
        swagger_client.api.listProjectMembers.return_value.response = (
            BravadoResponseMock(
                result=members,
            )
        )

        # when:
        returned_members = get_project_member_list(name="org/proj", api_token=API_TOKEN)

        # then:
        self.assertEqual(
            {"tester1": "contributor", "tester2": "owner", "tester3": "viewer"},
            returned_members,
        )
Example #21
0
def test_bravado_response_custom_metadata(mock_result, mock_metadata):
    response_mock = BravadoResponseMock(mock_result, metadata=mock_metadata)
    response = response_mock()

    assert response.metadata is mock_metadata