Skip to content

Commit

Permalink
Merge pull request #45 from unmade/update-driver-repr
Browse files Browse the repository at this point in the history
Update drivers repr
  • Loading branch information
unmade authored Mar 9, 2020
2 parents dd1a5a8 + 7e821f0 commit 40412b8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "apiwrappers"
version = "0.1.0"
version = "0.1.1"
description = "apiwrappers is a library for building API clients that work both with regular and async code"
keywords = ["api", "wrapper", "http", "client"]
readme = "README.rst"
Expand All @@ -11,7 +11,7 @@ packages = [
{ include = "apiwrappers", from = "src" },
]
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand Down
3 changes: 2 additions & 1 deletion src/apiwrappers/drivers/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __repr__(self) -> str:
f"{self.__class__.__name__}("
f"{', '.join(middleware)}"
f"timeout={self.timeout}, "
f"verify={self.verify}"
f"verify={repr(self.verify)}, "
f"cert={repr(self.cert)}"
")"
)

Expand Down
5 changes: 3 additions & 2 deletions src/apiwrappers/drivers/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def __repr__(self) -> str:
return (
f"{self.__class__.__name__}("
f"{', '.join(middleware)}"
f"timeout={self.timeout}, "
f"verify={self.verify}"
f"timeout={repr(self.timeout)}, "
f"verify={repr(self.verify)}, "
f"cert={repr(self.cert)}"
")"
)

Expand Down
14 changes: 12 additions & 2 deletions tests/test_drivers/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,25 @@ async def echo(request: Request):
async def test_representation() -> None:
driver = aiohttp_driver()
setattr(driver, "_middleware", [])
assert repr(driver) == "AioHttpDriver(timeout=300, verify=True)"
assert repr(driver) == "AioHttpDriver(timeout=300, verify=True, cert=None)"


async def test_representation_with_middleware() -> None:
driver = aiohttp_driver(RequestMiddleware, ResponseMiddleware)
assert repr(driver) == (
"AioHttpDriver("
"Authentication, RequestMiddleware, ResponseMiddleware, "
"timeout=300, verify=True"
"timeout=300, verify=True, cert=None"
")"
)


async def test_representation_with_verify_and_cert() -> None:
driver = aiohttp_driver(verify=CA_BUNDLE, cert=CLIENT_CERT_PAIR)
assert repr(driver) == (
"AioHttpDriver("
"Authentication, "
f"timeout=300, verify='{CA_BUNDLE}', cert={CLIENT_CERT_PAIR}"
")"
)

Expand Down
14 changes: 12 additions & 2 deletions tests/test_drivers/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,25 @@ def echo(request: PreparedRequest):
def test_representation() -> None:
driver = requests_driver()
setattr(driver, "_middleware", [])
assert repr(driver) == "RequestsDriver(timeout=300, verify=True)"
assert repr(driver) == "RequestsDriver(timeout=300, verify=True, cert=None)"


def test_representation_with_middleware() -> None:
driver = requests_driver(RequestMiddleware, ResponseMiddleware)
assert repr(driver) == (
"RequestsDriver("
"Authentication, RequestMiddleware, ResponseMiddleware, "
"timeout=300, verify=True"
"timeout=300, verify=True, cert=None"
")"
)


def test_representation_with_verify_and_cert() -> None:
driver = requests_driver(verify=CA_BUNDLE, cert=CLIENT_CERT_PAIR)
assert repr(driver) == (
"RequestsDriver("
"Authentication, "
f"timeout=300, verify='{CA_BUNDLE}', cert={CLIENT_CERT_PAIR}"
")"
)

Expand Down

0 comments on commit 40412b8

Please sign in to comment.