Skip to content

Commit

Permalink
finalize PR
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg committed Oct 27, 2020
1 parent 1685c5e commit 475ac42
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 114 deletions.
52 changes: 26 additions & 26 deletions tests/test_client.py
Expand Up @@ -711,6 +711,32 @@ def test_success_trs_uri_zip(self, requests_mock):
assert r[0].path == MOCK_TOOL_FILE['path']


class TestGetTests:
"""Test getter for tests."""

cli = TRSClient(
uri=MOCK_TRS_URI,
token=MOCK_TOKEN,
)
endpoint = (
f"{cli.uri}/tools/{MOCK_ID}/versions/{MOCK_ID}/{MOCK_DESCRIPTOR}/tests"
)

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.get(
self.endpoint,
json=[MOCK_FILE_WRAPPER, MOCK_FILE_WRAPPER],
)
r = self.cli.get_tests(
id=MOCK_ID,
type=MOCK_DESCRIPTOR,
version_id=MOCK_ID,
)
if not isinstance(r, Error):
assert r == [MOCK_FILE_WRAPPER, MOCK_FILE_WRAPPER]


class TestRetrieveFiles:
"""Test retrieving files of a given descriptor type."""

Expand Down Expand Up @@ -1163,29 +1189,3 @@ def test_invalid_http_method(self, requests_mock):
method='non_existing',
payload=self.payload,
)


class TestGetTests:
"""Test getter for tests."""

cli = TRSClient(
uri=MOCK_TRS_URI,
token=MOCK_TOKEN,
)
endpoint = (
f"{cli.uri}/tools/{MOCK_ID}/versions/{MOCK_ID}/{MOCK_DESCRIPTOR}/tests"
)

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.get(
self.endpoint,
json=[MOCK_FILE_WRAPPER, MOCK_FILE_WRAPPER],
)
r = self.cli.get_tests(
id=MOCK_ID,
type=MOCK_DESCRIPTOR,
version_id=MOCK_ID,
)
if not isinstance(r, Error):
assert r == [MOCK_FILE_WRAPPER, MOCK_FILE_WRAPPER]
176 changes: 88 additions & 88 deletions trs_cli/client.py
Expand Up @@ -1082,9 +1082,9 @@ def get_containerfiles(
if expired.
Returns:
Unmarshalled TRS response as either an instance of `FileWrapper` in
case of a `200` response, or an instance of `Error` for all other
JSON reponses.
Unmarshalled TRS response as either a list of `FileWrapper`
instances in case of a `200` response, or an instance of `Error`
for all other JSON reponses.
Raises:
requests.exceptions.ConnectionError: A connection to the provided
Expand Down Expand Up @@ -1139,9 +1139,9 @@ def get_descriptor(
Arguments:
type: The output type of the descriptor. Plain types return
the bare descriptor while the "non-plain" types return a
descriptor wrapped with metadata. Allowable values include
"CWL", "WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL",
"PLAIN_NFL", "PLAIN_GALAXY".
descriptor wrapped with metadata. Allowed values include "CWL",
"WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL", "PLAIN_NFL",
"PLAIN_GALAXY".
id: A unique identifier of the tool, scoped to this registry OR
a TRS URI. If a TRS URI is passed and includes the version
identifier, passing a `version_id` is optional. For more
Expand Down Expand Up @@ -1216,9 +1216,9 @@ def get_descriptor_by_path(
Arguments:
type: The output type of the descriptor. Plain types return
the bare descriptor while the "non-plain" types return a
descriptor wrapped with metadata. Allowable values include
"CWL", "WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL",
"PLAIN_NFL", "PLAIN_GALAXY".
descriptor wrapped with metadata. Allowed values include "CWL",
"WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL", "PLAIN_NFL",
"PLAIN_GALAXY".
path: Path, including filename, of descriptor or associated file
relative to the primary descriptor file.
id: A unique identifier of the tool, scoped to this registry OR
Expand Down Expand Up @@ -1295,9 +1295,9 @@ def get_files(
Arguments:
type: The output type of the descriptor. Plain types return
the bare descriptor while the "non-plain" types return a
descriptor wrapped with metadata. Allowable values include
"CWL", "WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL",
"PLAIN_NFL", "PLAIN_GALAXY".
descriptor wrapped with metadata. Allowed values include "CWL",
"WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL", "PLAIN_NFL",
"PLAIN_GALAXY".
id: A unique identifier of the tool, scoped to this registry OR
a hostname-based TRS URI. If TRS URIs include the version
information, passing a `version_id` is optional.
Expand Down Expand Up @@ -1362,6 +1362,81 @@ def get_files(
)
return response # type: ignore

def get_tests(
self,
type: str,
id: str,
version_id: Optional[str] = None,
accept: str = 'application/json',
token: Optional[str] = None
) -> Union[List[FileWrapper], Error]:
"""Retrieve the file wrappers for all tests associated with a
specified tool version and descriptor type.
Arguments:
type: The output type of the descriptor. Plain types return
the bare descriptor while the "non-plain" types return a
descriptor wrapped with metadata. Allowed values include "CWL",
"WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL", "PLAIN_NFL",
"PLAIN_GALAXY".
id: A unique identifier of the tool, scoped to this registry OR
a TRS URI. If a TRS URI is passed and includes the version
identifier, passing a `version_id` is optional. For more
information on TRS URIs, cf.
https://ga4gh.github.io/tool-registry-service-schemas/DataModel/#trs_uris
version_id: Identifier of the tool version, scoped to this
registry. It is optional if a TRS URI is passed and includes
version information. If provided nevertheless, then the
`version_id` retrieved from the TRS URI is overridden.
accept: Requested content type.
token: Bearer token for authentication. Set if required by TRS
implementation and if not provided when instatiating client or
if expired.
Returns:
Unmarshalled TRS response as either a list of `FileWrapper`
instances in case of a `200` response, or an instance of `Error`
for all other JSON reponses.
Raises:
requests.exceptions.ConnectionError: A connection to the provided
TRS instance could not be established.
trs_cli.errors.InvalidResponseError: The response could not be
validated against the API schema.
"""
# validate requested content type and get request headers
self._validate_content_type(
requested_type=accept,
available_types=['application/json', 'text/plain'],
)
self._get_headers(
content_accept=accept,
token=token,
)

# get/sanitize tool and version identifiers
_id, _version_id = self._get_tool_id_version_id(
tool_id=id,
version_id=version_id,
)

# build request URL
url = (
f"{self.uri}/tools/{_id}/versions/{_version_id}/{type}/"
"tests"
)
logger.info(f"Connecting to '{url}'...")

# send request
response = self._send_request_and_validate_response(
url=url,
validation_class_ok=(FileWrapper, ),
)
logger.info(
"Retrieved tests"
)
return response # type: ignore

def retrieve_files(
self,
out_dir: Union[str, Path],
Expand All @@ -1379,7 +1454,7 @@ def retrieve_files(
to create if it does not exist.
type: The output type of the descriptor. Plain types return
the bare descriptor while the "non-plain" types return a
descriptor wrapped with metadata. Allowable values include
descriptor wrapped with metadata. Allowed values include
"CWL", "WDL", "NFL", "GALAXY", "PLAIN_CWL", "PLAIN_WDL",
"PLAIN_NFL", "PLAIN_GALAXY".
id: A unique identifier of the tool, scoped to this registry OR
Expand Down Expand Up @@ -1454,81 +1529,6 @@ def retrieve_files(

return paths_by_type

def get_tests(
self,
id: str,
type: str,
version_id: Optional[str] = None,
accept: str = 'application/json',
token: Optional[str] = None
) -> Union[List[FileWrapper], Error]:
"""Retrieve the file wrappers for all tests associated with a
specified tool version.
Arguments:
id: A unique identifier of the tool, scoped to this registry OR
a TRS URI. If a TRS URI is passed and includes the version
identifier, passing a `version_id` is optional. For more
information on TRS URIs, cf.
https://ga4gh.github.io/tool-registry-service-schemas/DataModel/#trs_uris
type: The type of the underlying descriptor. Allowable values
include "CWL", "WDL", "NFL", "GALAXY", "PLAIN_CWL",
"PLAIN_WDL", "PLAIN_NFL", "PLAIN_GALAXY". For example, "CWL"
would return a list of ToolTests objects while "PLAIN_CWL"
would return a bare JSON list with the content of the tests.
version_id: Identifier of the tool version, scoped to this
registry. It is optional if a TRS URI is passed and includes
version information. If provided nevertheless, then the
`version_id` retrieved from the TRS URI is overridden.
accept: Requested content type.
token: Bearer token for authentication. Set if required by TRS
implementation and if not provided when instatiating client or
if expired.
Returns:
Unmarshalled TRS response as either an instance of `FileWrapper` in
case of a `200` response, or an instance of `Error` for all other
JSON reponses.
Raises:
requests.exceptions.ConnectionError: A connection to the provided
TRS instance could not be established.
trs_cli.errors.InvalidResponseError: The response could not be
validated against the API schema.
"""
# validate requested content type and get request headers
self._validate_content_type(
requested_type=accept,
available_types=['application/json', 'text/plain'],
)
self._get_headers(
content_accept=accept,
token=token,
)

# get/sanitize tool and version identifiers
_id, _version_id = self._get_tool_id_version_id(
tool_id=id,
version_id=version_id,
)

# build request URL
url = (
f"{self.uri}/tools/{_id}/versions/{_version_id}/{type}/"
"tests"
)
logger.info(f"Connecting to '{url}'...")

# send request
response = self._send_request_and_validate_response(
url=url,
validation_class_ok=(FileWrapper, ),
)
logger.info(
"Retrieved tests"
)
return response # type: ignore

def _get_host(
self,
uri: str,
Expand Down

0 comments on commit 475ac42

Please sign in to comment.