Skip to content

Commit 96083ac

Browse files
Use a locally hosted httpbin for tests
1 parent da5f360 commit 96083ac

File tree

6 files changed

+43
-28
lines changed

6 files changed

+43
-28
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ jobs:
5656
runs-on: ${{ matrix.os }}
5757
name: test-${{ matrix.python-version }} ${{ matrix.nox-session }}
5858
continue-on-error: ${{ matrix.experimental }}
59+
services:
60+
httpbin:
61+
image: kennethreitz/httpbin
62+
ports:
63+
- 8080:80
5964
steps:
6065
- name: Checkout repository
6166
uses: actions/checkout@v2

tests/async_/test_async_transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ async def test_async_transport_httpbin(httpbin_node_config):
5252

5353
assert resp.status == 200
5454
assert data["method"] == "GET"
55-
assert data["url"] == "https://httpbin.org/anything?key=value"
55+
assert data["url"] == "http://localhost:8080/anything?key=value"
5656
assert data["args"] == {"key": "value"}
5757

5858
data["headers"].pop("X-Amzn-Trace-Id", None)
59-
assert data["headers"] == {"User-Agent": DEFAULT_USER_AGENT, "Host": "httpbin.org"}
59+
assert data["headers"] == {"User-Agent": DEFAULT_USER_AGENT, "Connection": "keep-alive", "Host": "localhost:8080"}
6060

6161

6262
@pytest.mark.skipif(

tests/async_/test_httpbin.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def test_simple_request(httpbin_node_config):
3838
)
3939
assert resp.status == 200
4040
assert data["method"] == "GET"
41-
assert data["url"] == "https://httpbin.org/anything?key[]=1&key[]=2&q1&q2="
41+
assert data["url"] == "http://localhost:8080/anything?key[]=1&key[]=2&q1&q2="
4242

4343
# httpbin makes no-value query params into ''
4444
assert data["args"] == {
@@ -53,7 +53,8 @@ async def test_simple_request(httpbin_node_config):
5353
"Content-Type": "application/json",
5454
"Content-Length": "15",
5555
"Custom": "headeR",
56-
"Host": "httpbin.org",
56+
"Connection": "keep-alive",
57+
"Host": "localhost:8080",
5758
}
5859
assert all(v == data["headers"][k] for k, v in request_headers.items())
5960

@@ -69,11 +70,12 @@ def new_node(**kwargs):
6970
parsed = parse_httpbin(data)
7071
assert parsed == {
7172
"headers": {
72-
"Host": "httpbin.org",
73+
"Connection": "keep-alive",
74+
"Host": "localhost:8080",
7375
"User-Agent": DEFAULT_USER_AGENT,
7476
},
7577
"method": "GET",
76-
"url": "https://httpbin.org/anything",
78+
"url": "http://localhost:8080/anything",
7779
}
7880

7981
node = new_node(http_compress=True)
@@ -83,11 +85,12 @@ def new_node(**kwargs):
8385
assert parsed == {
8486
"headers": {
8587
"Accept-Encoding": "gzip",
86-
"Host": "httpbin.org",
88+
"Connection": "keep-alive",
89+
"Host": "localhost:8080",
8790
"User-Agent": DEFAULT_USER_AGENT,
8891
},
8992
"method": "GET",
90-
"url": "https://httpbin.org/anything",
93+
"url": "http://localhost:8080/anything",
9194
}
9295

9396
resp, data = await node.perform_request("GET", "/anything", body=b"hello, world!")
@@ -99,11 +102,12 @@ def new_node(**kwargs):
99102
"Content-Encoding": "gzip",
100103
"Content-Type": "application/octet-stream",
101104
"Content-Length": "33",
102-
"Host": "httpbin.org",
105+
"Connection": "keep-alive",
106+
"Host": "localhost:8080",
103107
"User-Agent": DEFAULT_USER_AGENT,
104108
},
105109
"method": "GET",
106-
"url": "https://httpbin.org/anything",
110+
"url": "http://localhost:8080/anything",
107111
}
108112

109113
resp, data = await node.perform_request(
@@ -120,9 +124,10 @@ def new_node(**kwargs):
120124
"Content-Encoding": "gzip",
121125
"Content-Length": "36",
122126
"Content-Type": "application/json",
123-
"Host": "httpbin.org",
127+
"Connection": "keep-alive",
128+
"Host": "localhost:8080",
124129
"User-Agent": DEFAULT_USER_AGENT,
125130
},
126131
"method": "POST",
127-
"url": "https://httpbin.org/anything",
132+
"url": "http://localhost:8080/anything",
128133
}

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def httpbin_cert_fingerprint(request) -> str:
8686
@pytest.fixture(scope="session")
8787
def httpbin_node_config() -> NodeConfig:
8888
try:
89-
sock = socket.create_connection(("httpbin.org", 443))
89+
sock = socket.create_connection(("localhost", 8080))
9090
except Exception as e:
91-
pytest.skip(f"Couldn't connect to httpbin.org, internet not connected? {e}")
91+
pytest.skip(f"Couldn't connect to localhost:8080, not running httpbin image? {e}")
9292
sock.close()
9393
return NodeConfig(
94-
"https", "httpbin.org", 443, verify_certs=False, ssl_show_warn=False
94+
"http", "localhost", 8080, verify_certs=False, ssl_show_warn=False
9595
)
9696

9797

tests/test_httpbin.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_simple_request(node_class, httpbin_node_config):
3737
)
3838
assert resp.status == 200
3939
assert data["method"] == "GET"
40-
assert data["url"] == "https://httpbin.org/anything?key[]=1&key[]=2&q1&q2="
40+
assert data["url"] == "http://localhost:8080/anything?key[]=1&key[]=2&q1&q2="
4141

4242
# httpbin makes no-value query params into ''
4343
assert data["args"] == {
@@ -52,7 +52,8 @@ def test_simple_request(node_class, httpbin_node_config):
5252
"Content-Type": "application/json",
5353
"Content-Length": "15",
5454
"Custom": "headeR",
55-
"Host": "httpbin.org",
55+
"Connection": "keep-alive",
56+
"Host": "localhost:8080",
5657
}
5758
assert all(v == data["headers"][k] for k, v in request_headers.items())
5859

@@ -71,11 +72,12 @@ def new_node(**kwargs):
7172
assert parsed == {
7273
"headers": {
7374
"Accept-Encoding": "identity",
74-
"Host": "httpbin.org",
75+
"Connection": "keep-alive",
76+
"Host": "localhost:8080",
7577
"User-Agent": DEFAULT_USER_AGENT,
7678
},
7779
"method": "GET",
78-
"url": "https://httpbin.org/anything",
80+
"url": "http://localhost:8080/anything",
7981
}
8082

8183
node = new_node(http_compress=True)
@@ -85,11 +87,12 @@ def new_node(**kwargs):
8587
assert parsed == {
8688
"headers": {
8789
"Accept-Encoding": "gzip",
88-
"Host": "httpbin.org",
90+
"Connection": "keep-alive",
91+
"Host": "localhost:8080",
8992
"User-Agent": DEFAULT_USER_AGENT,
9093
},
9194
"method": "GET",
92-
"url": "https://httpbin.org/anything",
95+
"url": "http://localhost:8080/anything",
9396
}
9497

9598
resp, data = node.perform_request("GET", "/anything", body=b"hello, world!")
@@ -100,11 +103,12 @@ def new_node(**kwargs):
100103
"Accept-Encoding": "gzip",
101104
"Content-Encoding": "gzip",
102105
"Content-Length": "33",
103-
"Host": "httpbin.org",
106+
"Connection": "keep-alive",
107+
"Host": "localhost:8080",
104108
"User-Agent": DEFAULT_USER_AGENT,
105109
},
106110
"method": "GET",
107-
"url": "https://httpbin.org/anything",
111+
"url": "http://localhost:8080/anything",
108112
}
109113

110114
resp, data = node.perform_request(
@@ -121,16 +125,17 @@ def new_node(**kwargs):
121125
"Content-Encoding": "gzip",
122126
"Content-Length": "36",
123127
"Content-Type": "application/json",
124-
"Host": "httpbin.org",
128+
"Connection": "keep-alive",
129+
"Host": "localhost:8080",
125130
"User-Agent": DEFAULT_USER_AGENT,
126131
},
127132
"method": "POST",
128-
"url": "https://httpbin.org/anything",
133+
"url": "http://localhost:8080/anything",
129134
}
130135

131136

132137
def parse_httpbin(value):
133-
"""Parses a response from httpbin.org/anything by stripping all the variable things"""
138+
"""Parses a response from httpbin's /anything by stripping all the variable things"""
134139
if isinstance(value, bytes):
135140
value = json.loads(value)
136141
else:

tests/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ async def test_debug_logging(node_class, httpbin_node_config):
7979
' "form": {}, ',
8080
' "headers": {',
8181
' "Content-Type": "application/json", ',
82-
' "Host": "httpbin.org", ',
82+
' "Host": "localhost:8080", ',
8383
f' "User-Agent": "{DEFAULT_USER_AGENT}", ',
8484
" }, ",
8585
' "json": {',
8686
' "key": "value"',
8787
" }, ",
8888
' "method": "GET", ',
89-
' "url": "https://httpbin.org/anything"',
89+
' "url": "http://localhost:8080/anything"',
9090
"}",
9191
]:
9292
assert line in lines

0 commit comments

Comments
 (0)