Skip to content

Commit 18a3c82

Browse files
committed
test: httpbin.org -> localhost:8080
Move all the tests from httpbin.org to local openresty server
1 parent 02b9941 commit 18a3c82

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

nix/nginx/conf/custom.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,29 @@ location /really-slow-reply {
1111
location /echo-method {
1212
echo $request_method;
1313
}
14+
15+
location /anything {
16+
echo $is_args$query_string;
17+
}
18+
19+
location /headers {
20+
echo_duplicate 1 $echo_client_request_headers;
21+
}
22+
23+
location /post {
24+
if ($request_method != 'POST'){
25+
return 405;
26+
}
27+
if ($http_accept != "application/json") {
28+
return 406;
29+
}
30+
echo_read_request_body;
31+
echo $request_body;
32+
}
33+
34+
location /delete {
35+
if ($request_method != 'DELETE'){
36+
return 405;
37+
}
38+
echo_duplicate 1 $echo_client_request_headers$is_args$query_string;
39+
}

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mkShell {
4141
format.do format.doCheck
4242
nginxScript
4343
pathodScript
44+
oldOpenresty
4445
];
4546
shellHook = ''
4647
export NIX_PATH="nixpkgs=${nixpkgs}:."

test/test_http_delete.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_http_delete_returns_id(sess):
66
(request_id,) = sess.execute(
77
"""
88
select net.http_get(
9-
url:='https://httpbin.org/delete'
9+
url:='http://localhost:8080/delete'
1010
);
1111
"""
1212
).fetchone()
@@ -21,7 +21,7 @@ def test_http_delete_collect_sync_success(sess):
2121
(request_id,) = sess.execute(
2222
"""
2323
select net.http_delete(
24-
url:='https://httpbin.org/delete'
24+
url:='http://localhost:8080/delete'
2525
, params:= '{"param-foo": "bar"}'
2626
, headers:= '{"X-Baz": "foo"}'
2727
);
@@ -45,7 +45,5 @@ def test_http_delete_collect_sync_success(sess):
4545
assert response[0] == "SUCCESS"
4646
assert response[1] == "ok"
4747
assert response[2] is not None
48-
# psycopg2 does not deserialize nested composites
49-
assert response[2].startswith("(200")
5048
assert "X-Baz" in response[2]
5149
assert "param-foo" in response[2]

test/test_http_headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_http_headers_set(sess):
77
(request_id,) = sess.execute(
88
"""
99
select net.http_get(
10-
url:='https://httpbin.org/headers',
10+
url:='http://localhost:8080/headers',
1111
headers:='{"pytest-header": "pytest-header", "accept": "application/json"}'
1212
);
1313
"""

test/test_http_params.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33

44
def test_http_get_url_params_set(sess):
5-
"""Check that headers are being set
6-
7-
Test url is (use browser):
8-
https://httpbin.org/anything?hello=world
5+
"""Check that params are being set on GET
96
"""
107
# Create a request
118
(request_id,) = sess.execute(
129
"""
1310
select net.http_get(
14-
url:='https://httpbin.org/anything',
11+
url:='http://localhost:8080/anything',
1512
params:='{"hello": "world"}'::jsonb
1613
);
1714
"""
@@ -36,16 +33,13 @@ def test_http_get_url_params_set(sess):
3633

3734

3835
def test_http_post_url_params_set(sess):
39-
"""Check that headers are being set
40-
41-
Test url is (use browser):
42-
https://httpbin.org/anything?hello=world
36+
"""Check that params are being set on POST
4337
"""
4438
# Create a request
4539
(request_id,) = sess.execute(
4640
"""
4741
select net.http_post(
48-
url:='https://httpbin.org/anything',
42+
url:='http://localhost:8080/anything',
4943
params:='{"hello": "world"}'::jsonb
5044
);
5145
"""

test/test_http_post_collect.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_http_post_returns_id(sess):
77
(request_id,) = sess.execute(
88
"""
99
select net.http_post(
10-
url:='https://httpbin.org/post',
10+
url:='http://localhost:8080/post',
1111
body:='{}'::jsonb
1212
);
1313
"""
@@ -22,7 +22,7 @@ def test_http_post_special_chars_body(sess):
2222
(request_id,) = sess.execute(
2323
"""
2424
select net.http_post(
25-
url:='https://httpbin.org/post',
25+
url:='http://localhost:8080/post',
2626
body:=json_build_object('foo', 'ba"r')::jsonb
2727
);
2828
"""
@@ -38,7 +38,7 @@ def test_http_post_collect_sync_success(sess):
3838
(request_id,) = sess.execute(
3939
"""
4040
select net.http_post(
41-
url:='https://httpbin.org/post'
41+
url:='http://localhost:8080/post'
4242
);
4343
"""
4444
).fetchone()
@@ -60,8 +60,6 @@ def test_http_post_collect_sync_success(sess):
6060
assert response[0] == "SUCCESS"
6161
assert response[1] == "ok"
6262
assert response[2] is not None
63-
# psycopg2 does not deserialize nested composites
64-
assert response[2].startswith("(200")
6563

6664

6765
# def test_http_post_collect_async_pending(sess):
@@ -71,7 +69,7 @@ def test_http_post_collect_sync_success(sess):
7169
# (request_id,) = sess.execute(
7270
# """
7371
# select net.http_post(
74-
# url:='https://httpbin.org/post',
72+
# url:='http://localhost:8080/post',
7573
# body:='{}'::jsonb
7674
# );
7775
# """
@@ -98,14 +96,12 @@ def test_http_post_collect_sync_success(sess):
9896

9997
def test_http_post_collect_non_empty_body(sess):
10098
"""Collect a response async before completed"""
101-
# Equivalent to
102-
# curl -X POST "https://httpbin.org/post" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hello\":\"world\"}"
10399

104100
# Create a request
105101
(request_id,) = sess.execute(
106102
"""
107103
select net.http_post(
108-
url:='https://httpbin.org/post',
104+
url:='http://localhost:8080/post',
109105
body:='{"hello": "world"}'::jsonb,
110106
headers:='{"Content-Type": "application/json", "accept": "application/json"}'::jsonb
111107
);
@@ -127,7 +123,6 @@ def test_http_post_collect_non_empty_body(sess):
127123
assert response is not None
128124
assert response[0] == "SUCCESS"
129125
assert "ok" in response[1]
130-
assert "json" in response[2]
131126
assert "hello" in response[2]
132127
assert "world" in response[2]
133128

@@ -144,7 +139,7 @@ def test_http_post_collect_non_empty_body(sess):
144139
{"request_id": request_id},
145140
).fetchone()
146141

147-
assert response_json["json"]["hello"] == "world"
142+
assert response_json["hello"] == "world"
148143

149144

150145
def test_http_post_wrong_header_exception(sess):
@@ -156,7 +151,7 @@ def test_http_post_wrong_header_exception(sess):
156151
sess.execute(
157152
"""
158153
select net.http_post(
159-
url:='https://httpbin.org/post',
154+
url:='http://localhost:8080/post',
160155
headers:='{"Content-Type": "application/text"}'::jsonb
161156
);
162157
"""
@@ -175,7 +170,7 @@ def test_http_post_no_content_type_coerce(sess):
175170
request_id, = sess.execute(
176171
"""
177172
select net.http_post(
178-
url:='https://httpbin.org/post',
173+
url:='http://localhost:8080/post',
179174
headers:='{"other": "val"}'::jsonb
180175
);
181176
"""

test/test_http_requests_deleted_after_ttl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_http_requests_deleted_after_ttl(sess):
99
(request_id,) = sess.execute(
1010
"""
1111
select net.http_get(
12-
'https://httpbin.org/anything'
12+
'http://localhost:8080/anything'
1313
);
1414
"""
1515
).fetchone()

0 commit comments

Comments
 (0)