Skip to content

Commit

Permalink
Update drivers repr
Browse files Browse the repository at this point in the history
  • Loading branch information
unmade committed Mar 9, 2020
1 parent dd1a5a8 commit a79a151
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
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 a79a151

Please sign in to comment.