@@ -772,16 +772,8 @@ def test_admin_works_with_host_special_values(specialhostvalue, defaultenv):
772
772
assert response .status_code == 200
773
773
774
774
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 ):
785
777
"log_level should filter request logging"
786
778
787
779
env = {** defaultenv , "PGRST_LOG_LEVEL" : level }
@@ -791,29 +783,31 @@ def test_log_level(level, has_output, defaultenv):
791
783
headers = jwtauthheader (claim , SECRET )
792
784
793
785
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
801
788
802
789
response = postgrest .session .get ("/unknown" )
803
790
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
- )
809
791
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
817
811
818
812
819
813
def test_no_pool_connection_required_on_bad_http_logic (defaultenv ):
@@ -1074,9 +1068,11 @@ def test_log_postgrest_version(defaultenv):
1074
1068
with run (env = defaultenv , no_startup_stdout = False ) as postgrest :
1075
1069
version = postgrest .session .head ("/" ).headers ["Server" ].split ("/" )[1 ]
1076
1070
1071
+ output = sorted (postgrest .read_stdout (nlines = 5 ))
1072
+
1077
1073
assert (
1078
1074
"Starting PostgREST %s..." % version
1079
- in postgrest . process . stdout . readline (). decode ()
1075
+ in output [ 3 ]
1080
1076
)
1081
1077
1082
1078
0 commit comments