Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 1695 testing concept #15

Merged
merged 12 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- main
pull_request:
types:
- closed
branches:
- main

Expand Down
189 changes: 104 additions & 85 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
httpx = "<0.27.0"
httpx = "^0.27.0"
pydantic = "<2.0"
python-jose = "<3.3.0"
provena-interfaces = "^2.6.0"
Expand All @@ -18,6 +18,7 @@ cloudpathlib = { extras = ["s3"], version = "0.15.1" }
[tool.poetry.dev-dependencies]
mypy = "<1.9.0"
pytest = "<8.1.1"
pytest-httpx = "*"
python-semantic-release = "<9.4.0"
pytest-cov = "<5.0.0"
myst-nb = "^1.0.0"
Expand All @@ -35,7 +36,7 @@ changelog_file = "CHANGELOG.md" # changelog file
build_command = "pip install poetry && poetry install && poetry build"
dist_path = "dist/"
upload_to_release = true
upload_to_pypi = false
upload_to_pypi = true
remove_dist = false
patch_without_tag = true

Expand Down
47 changes: 24 additions & 23 deletions src/provenaclient/clients/client_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from provenaclient.utils.config import Config
from provenaclient.utils.helpers import *
from provenaclient.utils.http_client import HttpClient
from typing import Dict, Optional
from typing import Dict, Mapping, Optional
from provenaclient.utils.exceptions import CustomTimeoutException


class ClientService(ABC):
Expand All @@ -31,7 +32,7 @@ class ClientService(ABC):
_config: Config


async def parsed_get_request_with_status(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_get_request_with_status(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -46,7 +47,7 @@ async def parsed_get_request_with_status(client: ClientService, params: Optional

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make GET request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -78,7 +79,7 @@ async def parsed_get_request_with_status(client: ClientService, params: Optional
return data


async def parsed_get_request(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_get_request(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -93,7 +94,7 @@ async def parsed_get_request(client: ClientService, params: Optional[Dict[str, O

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make GET request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -125,7 +126,7 @@ async def parsed_get_request(client: ClientService, params: Optional[Dict[str, O
return data


async def parsed_post_request(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_post_request(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -140,7 +141,7 @@ async def parsed_post_request(client: ClientService, params: Optional[Dict[str,

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -172,7 +173,7 @@ async def parsed_post_request(client: ClientService, params: Optional[Dict[str,

return data

async def parsed_post_request_with_status(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType], files: Optional[HttpxFileUpload] = None) -> BaseModelType:
async def parsed_post_request_with_status(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType], files: Optional[HttpxFileUpload] = None) -> BaseModelType:
"""

High level helper function which
Expand All @@ -187,7 +188,7 @@ async def parsed_post_request_with_status(client: ClientService, params: Optiona

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -224,7 +225,7 @@ async def parsed_post_request_with_status(client: ClientService, params: Optiona
return data


async def parsed_delete_request_with_status(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_delete_request_with_status(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -239,7 +240,7 @@ async def parsed_delete_request_with_status(client: ClientService, params: Optio

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -272,7 +273,7 @@ async def parsed_delete_request_with_status(client: ClientService, params: Optio
return data


async def parsed_delete_request(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_delete_request(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -287,7 +288,7 @@ async def parsed_delete_request(client: ClientService, params: Optional[Dict[str

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -320,7 +321,7 @@ async def parsed_delete_request(client: ClientService, params: Optional[Dict[str
return data


async def parsed_put_request(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_put_request(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -335,7 +336,7 @@ async def parsed_put_request(client: ClientService, params: Optional[Dict[str, O

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make put request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -368,7 +369,7 @@ async def parsed_put_request(client: ClientService, params: Optional[Dict[str, O
return data


async def parsed_put_request_with_status(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
async def parsed_put_request_with_status(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str, model: Type[BaseModelType]) -> BaseModelType:
"""

High level helper function which
Expand All @@ -383,7 +384,7 @@ async def parsed_put_request_with_status(client: ClientService, params: Optional

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make put request to
error_message (str): The error message to embed in other exceptions
model (Type[BaseModelType]): Model to parse for response JSON
Expand Down Expand Up @@ -417,7 +418,7 @@ async def parsed_put_request_with_status(client: ClientService, params: Optional



async def validated_get_request(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str) -> Response:
async def validated_get_request(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str) -> Response:
"""

High level helper function which
Expand All @@ -431,7 +432,7 @@ async def validated_get_request(client: ClientService, params: Optional[Dict[str

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make GET request to
error_message (str): The error message to embed in other exceptions

Expand Down Expand Up @@ -462,7 +463,7 @@ async def validated_get_request(client: ClientService, params: Optional[Dict[str
f"{error_message} Exception: {e}") from e


async def parsed_post_request_none_return(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str) -> None:
async def parsed_post_request_none_return(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], json_body: Optional[JsonData], url: str, error_message: str) -> None:
"""

High level helper function which
Expand All @@ -476,7 +477,7 @@ async def parsed_post_request_none_return(client: ClientService, params: Optiona

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions
json_body: Optional[JsonData]: JSON data to post if any
Expand Down Expand Up @@ -506,7 +507,7 @@ async def parsed_post_request_none_return(client: ClientService, params: Optiona
f"{error_message} Exception: {e}") from e


async def parsed_delete_request_non_return(client: ClientService, params: Optional[Dict[str, Optional[ParamTypes]]], url: str, error_message: str) -> None:
async def parsed_delete_request_non_return(client: ClientService, params: Optional[Mapping[str, Optional[ParamTypes]]], url: str, error_message: str) -> None:
"""

High level helper function which
Expand All @@ -520,7 +521,7 @@ async def parsed_delete_request_non_return(client: ClientService, params: Option

Args:
client (ClientService): The client being used. Relies on client interface.
params (Optional[Dict[str, Optional[ParamTypes]]]): The params if any
params (Optional[Mapping[str, Optional[ParamTypes]]]): The params if any
url (str): The url to make POST request to
error_message (str): The error message to embed in other exceptions

Expand Down
4 changes: 3 additions & 1 deletion src/provenaclient/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from typing import Optional

import httpx


class BaseException(Exception):
"""A custom exception class that inherits from python's base exception.
Expand Down Expand Up @@ -67,7 +69,7 @@ def __str__(self) -> str:
return base_message


class CustomTimeoutException(BaseException):
class CustomTimeoutException(httpx.TimeoutException):
""" An exception raised when a timeout occurs during an HTTP request.

Parameters
Expand Down
4 changes: 2 additions & 2 deletions src/provenaclient/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'''

from pydantic import BaseModel, ValidationError
from typing import Dict, Any, List, Optional, Tuple, TypeVar, Type, Union, ByteString
from typing import Dict, Any, List, Mapping, Optional, Tuple, TypeVar, Type, Union, ByteString
import json
from httpx import Response
from provenaclient.utils.exceptions import AuthException, HTTPValidationException, ServerException, BadRequestException, ValidationException, NotFoundException
Expand Down Expand Up @@ -166,7 +166,7 @@ def read_file_helper(file_path: str) -> str:
except Exception as e:
raise Exception(f"Error with file. Exception {e}")

def build_params_exclude_none(params: Dict[str, Optional[ParamTypes]]) -> Dict[str, ParamTypes]:
def build_params_exclude_none(params: Mapping[str, Optional[ParamTypes]]) -> Dict[str, ParamTypes]:
"""

Takes a raw params dict with optional args and returns filtered.
Expand Down
Loading
Loading