-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix httpx incorrectly named method on interceptor subclass (#126)
* Use pytest-httpbin to avoid outbound requests in most tests * Enable aiohttp tests in py3.12 * Add standard tests for all engines Reproduce #125 in tests * Fix #125 * Bump to 1.4.3
- Loading branch information
1 parent
e66193b
commit ef5bb1a
Showing
13 changed files
with
195 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
__license__ = "MIT" | ||
|
||
# Current version | ||
__version__ = "1.4.2" | ||
__version__ = "1.4.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import asyncio | ||
from typing import Optional, Tuple | ||
|
||
import pytest | ||
|
||
import pook | ||
|
||
|
||
class StandardTests: | ||
is_async: bool = False | ||
|
||
async def amake_request(self, method: str, url: str) -> Tuple[int, Optional[str]]: | ||
raise NotImplementedError( | ||
"Sub-classes for async transports must implement `amake_request`" | ||
) | ||
|
||
def make_request(self, method: str, url: str) -> Tuple[int, Optional[str]]: | ||
if self.is_async: | ||
return self.loop.run_until_complete(self.amake_request(method, url)) | ||
|
||
raise NotImplementedError("Sub-classes must implement `make_request`") | ||
|
||
@pytest.fixture(autouse=True, scope="class") | ||
def _loop(self, request): | ||
if self.is_async: | ||
request.cls.loop = asyncio.new_event_loop() | ||
yield | ||
request.cls.loop.close() | ||
else: | ||
yield | ||
|
||
@pytest.mark.pook | ||
def test_activate_deactivate(self, httpbin): | ||
url = f"{httpbin.url}/status/404" | ||
pook.get(url).reply(200).body("hello from pook") | ||
|
||
status, body = self.make_request("GET", url) | ||
|
||
assert status == 200 | ||
assert body == "hello from pook" | ||
|
||
pook.disable() | ||
|
||
status, body = self.make_request("GET", url) | ||
|
||
assert status == 404 | ||
|
||
@pytest.mark.pook(allow_pending_mocks=True) | ||
def test_network_mode(self, httpbin): | ||
upstream_url = f"{httpbin.url}/status/500" | ||
mocked_url = f"{httpbin.url}/status/404" | ||
pook.get(mocked_url).reply(200).body("hello from pook") | ||
pook.enable_network() | ||
|
||
# Avoid matching the mocks | ||
status, body = self.make_request("POST", upstream_url) | ||
|
||
assert status == 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.