Skip to content

Commit

Permalink
finalize PR
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg committed Oct 26, 2020
2 parents 65b1dfd + 7e4464c commit 1deb833
Show file tree
Hide file tree
Showing 2 changed files with 484 additions and 30 deletions.
155 changes: 151 additions & 4 deletions tests/test_client.py
Expand Up @@ -37,6 +37,20 @@
MOCK_DESCRIPTOR = "CWL"
MOCK_RESPONSE_INVALID = {"not": "valid"}
MOCK_DIR = "/mock/directory"
MOCK_SERVICE_INFO = {
"id": "TEMPID1",
"name": "TEMP_STUB",
"type": {
"group": "TEMP_GROUP",
"artifact": "TEMP_ARTIFACT",
"version": "v1"
},
"organization": {
"name": "Parent organization",
"url": "https://parent.abc"
},
"version": "0.0.0"
}
MOCK_ERROR = {
"code": 400,
"message": "BadRequest",
Expand Down Expand Up @@ -194,6 +208,49 @@ def test_trs_uri_http(self):
assert cli.uri == f"http://{MOCK_DOMAIN}:80/ga4gh/trs/v2"


class TestPostServiceInfo:
"""Test poster for service info."""

cli = TRSClient(
uri=MOCK_TRS_URI,
token=MOCK_TOKEN,
)
endpoint = (
f"{cli.uri}/service-info"
)

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.post(self.endpoint)
r = self.cli.post_service_info(
payload=MOCK_SERVICE_INFO
)
assert r is None

def test_success_ValidationError(self):
"""Raises validation error when incorrect input is provided"""
with pytest.raises(ValidationError):
self.cli.post_service_info(
payload=MOCK_RESPONSE_INVALID
)


class TestGetServiceInfo:
"""Test getter for service with a given id."""

cli = TRSClient(
uri=MOCK_TRS_URI,
token=MOCK_TOKEN,
)
endpoint = f"{cli.uri}/service-info"

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.get(self.endpoint, json=MOCK_SERVICE_INFO)
r = self.cli.get_service_info()
assert r.dict()['id'] == MOCK_SERVICE_INFO['id']


class TestPostToolClass:
"""Test poster for tool classes."""

Expand Down Expand Up @@ -221,6 +278,35 @@ def test_success_ValidationError(self):
)


class TestPutToolClass:
"""Test putter for tool classes."""

cli = TRSClient(
uri=MOCK_TRS_URI,
token=MOCK_TOKEN,
)
endpoint = (
f"{cli.uri}/toolClasses/{MOCK_ID}"
)

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.put(self.endpoint, json=MOCK_ID)
r = self.cli.put_tool_class(
id=MOCK_ID,
payload=MOCK_TOOL_CLASS_POST
)
assert r == MOCK_ID

def test_success_ValidationError(self):
"""Raises validation error when incorrect input is provided"""
with pytest.raises(ValidationError):
self.cli.put_tool_class(
id=MOCK_ID,
payload=MOCK_RESPONSE_INVALID
)


class TestDeleteToolClass:
"""Test delete for tool classes."""

Expand Down Expand Up @@ -268,6 +354,35 @@ def test_success_ValidationError(self):
)


class TestPutTool:
"""Test putter for tools."""

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

def test_success(self, requests_mock):
"""Returns 200 response."""
requests_mock.put(self.endpoint, json=MOCK_ID)
r = self.cli.put_tool(
id=MOCK_ID,
payload=MOCK_TOOL_POST
)
assert r == MOCK_ID

def test_success_ValidationError(self):
"""Raises validation error when incorrect input is provided"""
with pytest.raises(ValidationError):
self.cli.put_tool(
id=MOCK_ID,
payload=MOCK_RESPONSE_INVALID
)


class TestDeleteTool:
"""Test delete for tool."""

Expand All @@ -288,7 +403,7 @@ def test_success(self, requests_mock):
assert r == MOCK_ID


class TestPostToolVersion:
class TestPostVersion:
"""Test poster for tool versions."""

cli = TRSClient(
Expand Down Expand Up @@ -348,6 +463,27 @@ def test_success_ValidationError(self):
)


class TestDeleteVersion:
"""Test delete for tool version."""

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

def test_success(self, monkeypatch, requests_mock):
"""Returns 200 response."""
requests_mock.delete(self.endpoint, json=MOCK_ID)
r = self.cli.delete_version(
id=MOCK_ID,
version_id=MOCK_ID
)
assert r == MOCK_ID


class TestGetToolClasses:
"""Test getter for tool classes."""

Expand Down Expand Up @@ -927,15 +1063,25 @@ def test_get_str_validation(self, requests_mock):
requests_mock.get(self.endpoint, json=MOCK_ID)
response = self.cli._send_request_and_validate_response(
url=MOCK_API,
validation_class_ok=str,
)
assert response == MOCK_ID

def test_get_none_validation(self, requests_mock):
"""Test for getter with `None` response."""
requests_mock.get(self.endpoint, json=MOCK_ID)
response = self.cli._send_request_and_validate_response(
url=MOCK_API,
validation_class_ok=None,
)
assert response is None

def test_get_model_validation(self, requests_mock):
"""Test for getter with model response."""
requests_mock.get(self.endpoint, json=MOCK_TOOL)
response = self.cli._send_request_and_validate_response(
url=MOCK_API,
validation_class_200=Tool,
validation_class_ok=Tool,
)
assert response == MOCK_TOOL

Expand All @@ -944,7 +1090,7 @@ def test_get_list_validation(self, requests_mock):
requests_mock.get(self.endpoint, json=[MOCK_TOOL])
response = self.cli._send_request_and_validate_response(
url=MOCK_API,
validation_class_200=(Tool, ),
validation_class_ok=(Tool, ),
)
assert response == [MOCK_TOOL]

Expand All @@ -955,6 +1101,7 @@ def test_post_validation(self, requests_mock):
url=MOCK_API,
method='post',
payload=self.payload,
validation_class_ok=str,
)
assert response == MOCK_ID

Expand All @@ -964,7 +1111,7 @@ def test_get_success_invalid(self, requests_mock):
with pytest.raises(InvalidResponseError):
self.cli._send_request_and_validate_response(
url=MOCK_API,
validation_class_200=Error,
validation_class_ok=Error,
)

def test_error_response(self, requests_mock):
Expand Down

0 comments on commit 1deb833

Please sign in to comment.