Skip to content
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: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.8'
python-version: '3.12'

- name: Install build dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog


## [1.3.0] - 2024-02-05

### Changed
- Dropped support for Python 3.8 and 3.9
- Added support for Python 3.12

### Fixed
- Fixed issue where `partial_json` modifications were mutating the class-level `default_json` attribute in `MockAPIResponse`, causing unexpected behavior in tests.

## [1.2.1] - 2024-05-22

### Changed
Expand Down
2 changes: 1 addition & 1 deletion multi_api_mocker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Dacian Popute"""
__email__ = "dacian@ottu.com"
__version__ = "1.2.2"
__version__ = "1.3.0"
24 changes: 12 additions & 12 deletions multi_api_mocker/definitions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
import re
from typing import Union, Optional, Type, Any
from typing import Any


class MockAPIResponse:
Expand Down Expand Up @@ -41,13 +41,13 @@ class MockAPIResponse:
customizations.
"""

url: Union[str, re.Pattern] = None
url: str | re.Pattern = None
method: str = None
endpoint_name: str = None
default_status_code: Optional[int] = None
default_json: Optional[Any] = None
default_text: Optional[str] = None
default_exc: Optional[Union[Exception, Type[Exception], None]] = None
default_status_code: int | None = None
default_json: Any | None = None
default_text: str | None = None
default_exc: Exception | type[Exception] | None = None

def __init__(
self,
Expand Down Expand Up @@ -130,9 +130,9 @@ def validate_class_attributes(cls):

type_name = type(value).__name__
message = (
f"The `{attr}` attribute in subclass `{cls.__name__}` "
f"must be of type `{', '.join(expected_type_names)}`, "
f"got `{type_name}`: `{value}`."
f"The {attr!r} attribute in subclass {cls.__name__!r} "
f"must be of type {', '.join(expected_type_names)!r}, "
f"got {type_name!r}: {value!r}."
)
raise TypeError(message)

Expand All @@ -144,9 +144,9 @@ def validate_class_attributes(cls):
or isinstance(value, Exception)
):
raise TypeError(
f"The `default_exc` attribute in subclass `{cls.__name__}` "
f"The 'default_exc' attribute in subclass {cls.__name__!r} "
f"must be a subclass or instance of Exception or None, "
f"got `{type(value).__name__}`: `{value}`."
f"got {type(value).__name__!r}: {value!r}."
)

@property
Expand Down Expand Up @@ -174,7 +174,7 @@ def exc(self):
return self._exc or self.__class__.default_exc

def _default_json(self, status_code):
return self.default_json
return self.default_json.copy() if self.default_json else None

def _default_text(self, status_code):
return self.default_text
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.2
current_version = 1.3.0
commit = False
tag = True
tag_name = v{new_version}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/ottuco/multi_api_mocker",
version="1.2.2",
version="1.3.0",
zip_safe=False,
)
26 changes: 13 additions & 13 deletions tests/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def test_subclassing_with_invalid_url(self):

assert (
str(exc_info.value)
== "The `url` attribute in subclass `MockAPIResponseSubclass` "
"must be of type `str, Pattern`, got `int`: `1`."
== "The 'url' attribute in subclass 'MockAPIResponseSubclass' "
"must be of type 'str, Pattern', got 'int': 1."
)

@pytest.mark.parametrize(
Expand All @@ -129,37 +129,37 @@ def test_subclassing_with_invalid_url(self):
(
"method",
200,
"The `method` attribute in subclass `MockAPIResponseSubclass` "
"must be of type `str`, got `int`: `200`.",
"The 'method' attribute in subclass 'MockAPIResponseSubclass' "
"must be of type 'str', got 'int': 200.",
),
(
"endpoint_name",
False,
(
"The `endpoint_name` attribute in subclass "
"`MockAPIResponseSubclass` must be of type `str`, got `bool`: `False`." # noqa: E501
"The 'endpoint_name' attribute in subclass "
"'MockAPIResponseSubclass' must be of type 'str', got 'bool': False." # noqa: E501
),
),
(
"default_status_code",
"NotAnInt",
(
"The `default_status_code` attribute in subclass `MockAPIResponseSubclass` " # noqa: E501
"must be of type `int, None`, got `str`: `NotAnInt`."
"The 'default_status_code' attribute in subclass 'MockAPIResponseSubclass' " # noqa: E501
"must be of type 'int, None', got 'str': 'NotAnInt'."
),
),
(
"default_text",
123,
"The `default_text` attribute in subclass `MockAPIResponseSubclass` "
"must be of type `str, None`, got `int`: `123`.",
"The 'default_text' attribute in subclass 'MockAPIResponseSubclass' "
"must be of type 'str, None', got 'int': 123.",
),
(
"default_exc",
"NotATypeOrNone",
"The `default_exc` attribute in subclass `MockAPIResponseSubclass` "
"must be a subclass or instance of Exception or None, got `str`: "
"`NotATypeOrNone`.",
"The 'default_exc' attribute in subclass 'MockAPIResponseSubclass' "
"must be a subclass or instance of Exception or None, got 'str': "
"'NotATypeOrNone'.",
),
],
ids=[
Expand Down