Skip to content

Commit

Permalink
test: httpbin.org -> localhost:8080
Browse files Browse the repository at this point in the history
Move all the tests from httpbin.org to local openresty server
  • Loading branch information
steve-chavez committed Aug 17, 2023
1 parent 02b9941 commit 18a3c82
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
26 changes: 26 additions & 0 deletions nix/nginx/conf/custom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ location /really-slow-reply {
location /echo-method {
echo $request_method;
}

location /anything {
echo $is_args$query_string;
}

location /headers {
echo_duplicate 1 $echo_client_request_headers;
}

location /post {
if ($request_method != 'POST'){
return 405;
}
if ($http_accept != "application/json") {
return 406;
}
echo_read_request_body;
echo $request_body;
}

location /delete {
if ($request_method != 'DELETE'){
return 405;
}
echo_duplicate 1 $echo_client_request_headers$is_args$query_string;
}
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mkShell {
format.do format.doCheck
nginxScript
pathodScript
oldOpenresty
];
shellHook = ''
export NIX_PATH="nixpkgs=${nixpkgs}:."
Expand Down
6 changes: 2 additions & 4 deletions test/test_http_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_http_delete_returns_id(sess):
(request_id,) = sess.execute(
"""
select net.http_get(
url:='https://httpbin.org/delete'
url:='http://localhost:8080/delete'
);
"""
).fetchone()
Expand All @@ -21,7 +21,7 @@ def test_http_delete_collect_sync_success(sess):
(request_id,) = sess.execute(
"""
select net.http_delete(
url:='https://httpbin.org/delete'
url:='http://localhost:8080/delete'
, params:= '{"param-foo": "bar"}'
, headers:= '{"X-Baz": "foo"}'
);
Expand All @@ -45,7 +45,5 @@ def test_http_delete_collect_sync_success(sess):
assert response[0] == "SUCCESS"
assert response[1] == "ok"
assert response[2] is not None
# psycopg2 does not deserialize nested composites
assert response[2].startswith("(200")
assert "X-Baz" in response[2]
assert "param-foo" in response[2]
2 changes: 1 addition & 1 deletion test/test_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_http_headers_set(sess):
(request_id,) = sess.execute(
"""
select net.http_get(
url:='https://httpbin.org/headers',
url:='http://localhost:8080/headers',
headers:='{"pytest-header": "pytest-header", "accept": "application/json"}'
);
"""
Expand Down
14 changes: 4 additions & 10 deletions test/test_http_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@


def test_http_get_url_params_set(sess):
"""Check that headers are being set
Test url is (use browser):
https://httpbin.org/anything?hello=world
"""Check that params are being set on GET
"""
# Create a request
(request_id,) = sess.execute(
"""
select net.http_get(
url:='https://httpbin.org/anything',
url:='http://localhost:8080/anything',
params:='{"hello": "world"}'::jsonb
);
"""
Expand All @@ -36,16 +33,13 @@ def test_http_get_url_params_set(sess):


def test_http_post_url_params_set(sess):
"""Check that headers are being set
Test url is (use browser):
https://httpbin.org/anything?hello=world
"""Check that params are being set on POST
"""
# Create a request
(request_id,) = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/anything',
url:='http://localhost:8080/anything',
params:='{"hello": "world"}'::jsonb
);
"""
Expand Down
21 changes: 8 additions & 13 deletions test/test_http_post_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_http_post_returns_id(sess):
(request_id,) = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post',
url:='http://localhost:8080/post',
body:='{}'::jsonb
);
"""
Expand All @@ -22,7 +22,7 @@ def test_http_post_special_chars_body(sess):
(request_id,) = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post',
url:='http://localhost:8080/post',
body:=json_build_object('foo', 'ba"r')::jsonb
);
"""
Expand All @@ -38,7 +38,7 @@ def test_http_post_collect_sync_success(sess):
(request_id,) = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post'
url:='http://localhost:8080/post'
);
"""
).fetchone()
Expand All @@ -60,8 +60,6 @@ def test_http_post_collect_sync_success(sess):
assert response[0] == "SUCCESS"
assert response[1] == "ok"
assert response[2] is not None
# psycopg2 does not deserialize nested composites
assert response[2].startswith("(200")


# def test_http_post_collect_async_pending(sess):
Expand All @@ -71,7 +69,7 @@ def test_http_post_collect_sync_success(sess):
# (request_id,) = sess.execute(
# """
# select net.http_post(
# url:='https://httpbin.org/post',
# url:='http://localhost:8080/post',
# body:='{}'::jsonb
# );
# """
Expand All @@ -98,14 +96,12 @@ def test_http_post_collect_sync_success(sess):

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

# Create a request
(request_id,) = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post',
url:='http://localhost:8080/post',
body:='{"hello": "world"}'::jsonb,
headers:='{"Content-Type": "application/json", "accept": "application/json"}'::jsonb
);
Expand All @@ -127,7 +123,6 @@ def test_http_post_collect_non_empty_body(sess):
assert response is not None
assert response[0] == "SUCCESS"
assert "ok" in response[1]
assert "json" in response[2]
assert "hello" in response[2]
assert "world" in response[2]

Expand All @@ -144,7 +139,7 @@ def test_http_post_collect_non_empty_body(sess):
{"request_id": request_id},
).fetchone()

assert response_json["json"]["hello"] == "world"
assert response_json["hello"] == "world"


def test_http_post_wrong_header_exception(sess):
Expand All @@ -156,7 +151,7 @@ def test_http_post_wrong_header_exception(sess):
sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post',
url:='http://localhost:8080/post',
headers:='{"Content-Type": "application/text"}'::jsonb
);
"""
Expand All @@ -175,7 +170,7 @@ def test_http_post_no_content_type_coerce(sess):
request_id, = sess.execute(
"""
select net.http_post(
url:='https://httpbin.org/post',
url:='http://localhost:8080/post',
headers:='{"other": "val"}'::jsonb
);
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_http_requests_deleted_after_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_http_requests_deleted_after_ttl(sess):
(request_id,) = sess.execute(
"""
select net.http_get(
'https://httpbin.org/anything'
'http://localhost:8080/anything'
);
"""
).fetchone()
Expand Down

0 comments on commit 18a3c82

Please sign in to comment.