test: use postgrest.read_stdout in io tests (#3412)
It's easier to maintain this way in case there are new log lines.
This commit is contained in:
+41
-30
@@ -772,16 +772,8 @@ def test_admin_works_with_host_special_values(specialhostvalue, defaultenv):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize("level", ["crit", "error", "warn", "info"])
|
||||||
"level, has_output",
|
def test_log_level(level, defaultenv):
|
||||||
[
|
|
||||||
("info", [True, True, True]),
|
|
||||||
("warn", [False, True, True]),
|
|
||||||
("error", [False, False, True]),
|
|
||||||
("crit", [False, False, False]),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_log_level(level, has_output, defaultenv):
|
|
||||||
"log_level should filter request logging"
|
"log_level should filter request logging"
|
||||||
|
|
||||||
env = {**defaultenv, "PGRST_LOG_LEVEL": level}
|
env = {**defaultenv, "PGRST_LOG_LEVEL": level}
|
||||||
@@ -791,29 +783,49 @@ def test_log_level(level, has_output, defaultenv):
|
|||||||
headers = jwtauthheader(claim, SECRET)
|
headers = jwtauthheader(claim, SECRET)
|
||||||
|
|
||||||
with run(env=env) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
response = postgrest.session.get("/")
|
response = postgrest.session.get("/", headers=headers)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 500
|
||||||
if has_output[0]:
|
|
||||||
assert re.match(
|
|
||||||
r'- - postgrest_test_anonymous \[.+\] "GET / HTTP/1.1" 200 - "" "python-requests/.+"',
|
|
||||||
postgrest.process.stdout.readline().decode(),
|
|
||||||
)
|
|
||||||
|
|
||||||
response = postgrest.session.get("/unknown")
|
response = postgrest.session.get("/unknown")
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
if has_output[1]:
|
|
||||||
assert re.match(
|
|
||||||
r'- - postgrest_test_anonymous \[.+\] "GET /unknown HTTP/1.1" 404 - "" "python-requests/.+"',
|
|
||||||
postgrest.process.stdout.readline().decode(),
|
|
||||||
)
|
|
||||||
|
|
||||||
response = postgrest.session.get("/", headers=headers)
|
response = postgrest.session.get("/")
|
||||||
assert response.status_code == 500
|
assert response.status_code == 200
|
||||||
if has_output[2]:
|
|
||||||
|
output = sorted(postgrest.read_stdout(nlines=3))
|
||||||
|
|
||||||
|
if level == "crit":
|
||||||
|
assert len(output) == 0
|
||||||
|
elif level == "error":
|
||||||
assert re.match(
|
assert re.match(
|
||||||
r'- - - \[.+\] "GET / HTTP/1.1" 500 - "" "python-requests/.+"',
|
r'- - - \[.+\] "GET / HTTP/1.1" 500 - "" "python-requests/.+"',
|
||||||
postgrest.process.stdout.readline().decode(),
|
output[0],
|
||||||
)
|
)
|
||||||
|
assert len(output) == 1
|
||||||
|
elif level == "warn":
|
||||||
|
assert re.match(
|
||||||
|
r'- - - \[.+\] "GET / HTTP/1.1" 500 - "" "python-requests/.+"',
|
||||||
|
output[0],
|
||||||
|
)
|
||||||
|
assert re.match(
|
||||||
|
r'- - postgrest_test_anonymous \[.+\] "GET /unknown HTTP/1.1" 404 - "" "python-requests/.+"',
|
||||||
|
output[1],
|
||||||
|
)
|
||||||
|
assert len(output) == 2
|
||||||
|
else:
|
||||||
|
assert re.match(
|
||||||
|
r'- - - \[.+\] "GET / HTTP/1.1" 500 - "" "python-requests/.+"',
|
||||||
|
output[0],
|
||||||
|
)
|
||||||
|
assert re.match(
|
||||||
|
r'- - postgrest_test_anonymous \[.+\] "GET / HTTP/1.1" 200 - "" "python-requests/.+"',
|
||||||
|
output[1],
|
||||||
|
)
|
||||||
|
assert re.match(
|
||||||
|
r'- - postgrest_test_anonymous \[.+\] "GET /unknown HTTP/1.1" 404 - "" "python-requests/.+"',
|
||||||
|
output[2],
|
||||||
|
)
|
||||||
|
assert len(output) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_no_pool_connection_required_on_bad_http_logic(defaultenv):
|
def test_no_pool_connection_required_on_bad_http_logic(defaultenv):
|
||||||
@@ -1074,10 +1086,9 @@ def test_log_postgrest_version(defaultenv):
|
|||||||
with run(env=defaultenv, no_startup_stdout=False) as postgrest:
|
with run(env=defaultenv, no_startup_stdout=False) as postgrest:
|
||||||
version = postgrest.session.head("/").headers["Server"].split("/")[1]
|
version = postgrest.session.head("/").headers["Server"].split("/")[1]
|
||||||
|
|
||||||
assert (
|
output = sorted(postgrest.read_stdout(nlines=5))
|
||||||
"Starting PostgREST %s..." % version
|
|
||||||
in postgrest.process.stdout.readline().decode()
|
assert "Starting PostgREST %s..." % version in output[3]
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_succeed_w_role_having_superuser_settings(defaultenv):
|
def test_succeed_w_role_having_superuser_settings(defaultenv):
|
||||||
|
|||||||
Reference in New Issue
Block a user