@@ -772,16 +772,8 @@ def test_admin_works_with_host_special_values(specialhostvalue, defaultenv):
772772 assert response .status_code == 200
773773
774774
775- @pytest .mark .parametrize (
776- "level, has_output" ,
777- [
778- ("info" , [True , True , True ]),
779- ("warn" , [False , True , True ]),
780- ("error" , [False , False , True ]),
781- ("crit" , [False , False , False ]),
782- ],
783- )
784- def test_log_level (level , has_output , defaultenv ):
775+ @pytest .mark .parametrize ("level" , ["crit" , "error" , "warn" , "info" ])
776+ def test_log_level (level , defaultenv ):
785777 "log_level should filter request logging"
786778
787779 env = {** defaultenv , "PGRST_LOG_LEVEL" : level }
@@ -791,29 +783,31 @@ def test_log_level(level, has_output, defaultenv):
791783 headers = jwtauthheader (claim , SECRET )
792784
793785 with run (env = env ) as postgrest :
794- response = postgrest .session .get ("/" )
795- assert response .status_code == 200
796- if has_output [0 ]:
797- assert re .match (
798- r'- - postgrest_test_anonymous \[.+\] "GET / HTTP/1.1" 200 - "" "python-requests/.+"' ,
799- postgrest .process .stdout .readline ().decode (),
800- )
786+ response = postgrest .session .get ("/" , headers = headers )
787+ assert response .status_code == 500
801788
802789 response = postgrest .session .get ("/unknown" )
803790 assert response .status_code == 404
804- if has_output [1 ]:
805- assert re .match (
806- r'- - postgrest_test_anonymous \[.+\] "GET /unknown HTTP/1.1" 404 - "" "python-requests/.+"' ,
807- postgrest .process .stdout .readline ().decode (),
808- )
809791
810- response = postgrest .session .get ("/" , headers = headers )
811- assert response .status_code == 500
812- if has_output [2 ]:
813- assert re .match (
814- r'- - - \[.+\] "GET / HTTP/1.1" 500 - "" "python-requests/.+"' ,
815- postgrest .process .stdout .readline ().decode (),
816- )
792+ response = postgrest .session .get ("/" )
793+ assert response .status_code == 200
794+
795+ output = sorted (postgrest .read_stdout (nlines = 3 ))
796+
797+ if level == "crit" :
798+ assert len (output ) == 0
799+ elif level == "error" :
800+ assert '"GET / HTTP/1.1" 500' in output [0 ]
801+ assert len (output ) == 1
802+ elif level == "warn" :
803+ assert '"GET / HTTP/1.1" 500' in output [0 ]
804+ assert '"GET /unknown HTTP/1.1" 404' in output [1 ]
805+ assert len (output ) == 2
806+ else :
807+ assert '"GET / HTTP/1.1" 500' in output [0 ]
808+ assert '"GET / HTTP/1.1" 200' in output [1 ]
809+ assert '"GET /unknown HTTP/1.1" 404' in output [2 ]
810+ assert len (output ) == 3
817811
818812
819813def test_no_pool_connection_required_on_bad_http_logic (defaultenv ):
@@ -1074,10 +1068,9 @@ def test_log_postgrest_version(defaultenv):
10741068 with run (env = defaultenv , no_startup_stdout = False ) as postgrest :
10751069 version = postgrest .session .head ("/" ).headers ["Server" ].split ("/" )[1 ]
10761070
1077- assert (
1078- "Starting PostgREST %s..." % version
1079- in postgrest .process .stdout .readline ().decode ()
1080- )
1071+ output = sorted (postgrest .read_stdout (nlines = 5 ))
1072+
1073+ assert "Starting PostgREST %s..." % version in output [3 ]
10811074
10821075
10831076def test_succeed_w_role_having_superuser_settings (defaultenv ):
0 commit comments