@@ -63,32 +63,40 @@ def test_accept_header(self) -> None:
6363
6464
6565class TestGetHost :
66- def test_get_host_success (self , client ):
67- for f in HOSTS_SUCCESS_RESULTS_DIR .iterdir ():
68- with open (f ) as ff :
69- res_json = json .load (ff )
70- ipv4 = f .name [:- 5 ] # remove .json
71- with requests_mock .Mocker () as m :
72- url = f"{ client .base_url } /host/{ ipv4 } "
73- m .get (url , json = res_json , status_code = 200 )
74- response = client .get_host (ipv4 )
75- assert response .is_success ()
76- assert len (response .json ()["services" ]) == 3
77- assert response .json ()["leaks" ] is None
78-
79- def test_get_host_404 (self , client ):
80- for f in HOSTS_404_RESULTS_DIR .iterdir ():
81- with open (f ) as ff :
82- res_json = json .load (ff )
83- ipv4 = f .name [:- 5 ] # remove .json
84- with requests_mock .Mocker () as m :
85- url = f"{ client .base_url } /host/{ ipv4 } "
86- m .get (url , json = res_json , status_code = 404 )
87- response = client .get_host (ipv4 )
88- assert response .is_error ()
89- assert response .status_code () == 404
90- assert response .json ()["title" ] == "Not Found"
91- assert response .json ()["description" ] == "Host not found"
66+ @pytest .mark .parametrize (
67+ "fixture_file" ,
68+ list (HOSTS_SUCCESS_RESULTS_DIR .iterdir ()),
69+ ids = lambda f : f .stem ,
70+ )
71+ def test_get_host_success (self , client , fixture_file ):
72+ with open (fixture_file ) as ff :
73+ res_json = json .load (ff )
74+ ipv4 = fixture_file .stem
75+ with requests_mock .Mocker () as m :
76+ url = f"{ client .base_url } /host/{ ipv4 } "
77+ m .get (url , json = res_json , status_code = 200 )
78+ response = client .get_host (ipv4 )
79+ assert response .is_success ()
80+ assert len (response .json ()["services" ]) == 3
81+ assert response .json ()["leaks" ] is None
82+
83+ @pytest .mark .parametrize (
84+ "fixture_file" ,
85+ list (HOSTS_404_RESULTS_DIR .iterdir ()),
86+ ids = lambda f : f .stem ,
87+ )
88+ def test_get_host_404 (self , client , fixture_file ):
89+ with open (fixture_file ) as ff :
90+ res_json = json .load (ff )
91+ ipv4 = fixture_file .stem
92+ with requests_mock .Mocker () as m :
93+ url = f"{ client .base_url } /host/{ ipv4 } "
94+ m .get (url , json = res_json , status_code = 404 )
95+ response = client .get_host (ipv4 )
96+ assert response .is_error ()
97+ assert response .status_code () == 404
98+ assert response .json ()["title" ] == "Not Found"
99+ assert response .json ()["description" ] == "Host not found"
92100
93101 def test_get_host_429 (self , client , fake_ipv4 ):
94102 res_json = {"reason" : "rate-limit" , "status" : "error" }
0 commit comments