Skip to content

Commit 81474f1

Browse files
authored
Adding support for httpx (#183)
* Adding support for `httpx`.
1 parent 8b994a8 commit 81474f1

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.3.0
44
hooks:
55
- id: check-yaml
66
args: ['--unsafe']
@@ -12,7 +12,7 @@ repos:
1212
args: ['--autofix']
1313

1414
- repo: [email protected]:humitos/mirrors-autoflake.git
15-
rev: v1.3
15+
rev: v1.1
1616
hooks:
1717
- id: autoflake
1818
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
@@ -23,6 +23,6 @@ repos:
2323
- id: isort
2424

2525
- repo: https://github.com/psf/black
26-
rev: stable
26+
rev: 22.6.0
2727
hooks:
2828
- id: black

Pipfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ http-parser = ">=0.9.0"
1313
pre-commit = "*"
1414
pytest = ">4.6"
1515
pytest-cov = "*"
16+
pytest-asyncio = "*"
1617
requests = "*"
1718
redis = "*"
1819
gevent = "*"
1920
sure = "*"
2021
pook = "*"
21-
flake8 = "*"
22+
flake8 = "<5"
2223
xxhash = "*"
2324
aiohttp = "*"
2425
async-timeout = "*"
26+
httpx = "*"
2527
pipfile = "*"
2628
build = "*"
2729
wheel = "*"
2830
twine = "*"
29-
anaconda-client = {git = "https://github.com/Anaconda-Server/anaconda-client"}
31+
anaconda-client = "*"
3032

3133
[requires]
3234
python_version = "3"

mocket/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
__all__ = ("async_mocketize", "mocketize", "Mocket", "MocketEntry", "Mocketizer")
55

6-
__version__ = "3.10.6"
6+
__version__ = "3.10.7"

mocket/mocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class FakeSSLContext(SuperFakeSSLContext):
7676
"load_default_certs",
7777
"load_verify_locations",
7878
"set_alpn_protocols",
79+
"set_ciphers",
7980
)
8081
sock = None
8182
post_handshake_auth = None
@@ -426,6 +427,8 @@ def register(cls, *entries):
426427

427428
@classmethod
428429
def get_entry(cls, host, port, data):
430+
host = host or Mocket._address[0]
431+
port = port or Mocket._address[1]
429432
entries = cls._entries.get((host, port), [])
430433
for entry in entries:
431434
if entry.can_handle(data):

tests/tests37/test_httpx.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
3+
import httpx
4+
import pytest
5+
6+
from mocket import async_mocketize
7+
from mocket.mockhttp import Entry
8+
9+
10+
@pytest.mark.asyncio
11+
@async_mocketize
12+
async def test_httpx():
13+
url = "https://example.org/"
14+
data = {"message": "Hello"}
15+
16+
Entry.single_register(
17+
Entry.GET,
18+
url,
19+
body=json.dumps(data),
20+
headers={"content-type": "application/json"},
21+
)
22+
23+
async with httpx.AsyncClient() as client:
24+
response = await client.get(url)
25+
26+
assert response.json() == data

0 commit comments

Comments
 (0)