55from urllib3 .util .retry import Retry
66from config import settings
77
8+
89class HttpClient :
910 """Cliente HTTP focado em testes: timeout, retry e rate-limit simples."""
11+
1012 def __init__ (self , base_url : str , connect_timeout : float , read_timeout : float , retry_total : int , rate_sleep : float ):
1113 self .base_url = base_url .rstrip ("/" )
1214 self .session = requests .Session ()
@@ -17,7 +19,8 @@ def __init__(self, base_url: str, connect_timeout: float, read_timeout: float, r
1719 allowed_methods = ["GET" ],
1820 respect_retry_after_header = True ,
1921 )
20- adapter = HTTPAdapter (max_retries = retry , pool_connections = 10 , pool_maxsize = 10 )
22+ adapter = HTTPAdapter (
23+ max_retries = retry , pool_connections = 10 , pool_maxsize = 10 )
2124 self .session .mount ("https://" , adapter )
2225 self .session .mount ("http://" , adapter )
2326 self .session .headers .update ({"Accept" : "application/json" })
@@ -33,10 +36,12 @@ def get(self, path_or_url: str, **kwargs) -> requests.Response:
3336 time .sleep (self .rate_sleep ) # rate-limit simples
3437 return self .session .get (url , timeout = self .timeout , ** kwargs )
3538
39+
3640@pytest .fixture (scope = "session" )
3741def base_url () -> str :
3842 return settings .BASE_URL
3943
44+
4045@pytest .fixture (scope = "session" )
4146def http () -> HttpClient :
4247 return HttpClient (
@@ -45,4 +50,5 @@ def http() -> HttpClient:
4550 read_timeout = settings .READ_TIMEOUT ,
4651 retry_total = settings .RETRY_TOTAL ,
4752 rate_sleep = settings .RATE_LIMIT_SLEEP ,
48- )
53+ )
54+
0 commit comments