1
- import pytest
2
1
from unittest .mock import Mock
3
- from urllib .request import Request
4
2
5
3
import httpx
4
+ import pytest
6
5
7
6
from ai21 .errors import ServiceUnavailable , Unauthorized
7
+ from ai21 .http_client .async_http_client import AsyncAI21HTTPClient
8
8
from ai21 .http_client .base_http_client import RETRY_ERROR_CODES
9
9
from ai21 .http_client .http_client import AI21HTTPClient
10
- from ai21 .http_client .async_http_client import AsyncAI21HTTPClient
11
10
12
11
_METHOD = "GET"
13
12
_URL = "http://test_url"
14
13
_API_KEY = "fake-key"
15
14
16
15
17
16
def test__execute_http_request__when_retry_error_code_once__should_retry_and_succeed (mock_httpx_client : Mock ) -> None :
18
- request = Request (method = _METHOD , url = _URL )
17
+ request = httpx . Request (method = _METHOD , url = _URL )
19
18
retries = 3
20
19
mock_httpx_client .send .side_effect = [
21
20
httpx .Response (status_code = 429 , request = request ),
@@ -28,7 +27,7 @@ def test__execute_http_request__when_retry_error_code_once__should_retry_and_suc
28
27
29
28
30
29
def test__execute_http_request__when_retry_error__should_retry_and_stop (mock_httpx_client : Mock ) -> None :
31
- request = Request (method = _METHOD , url = _URL )
30
+ request = httpx . Request (method = _METHOD , url = _URL )
32
31
retries = len (RETRY_ERROR_CODES )
33
32
34
33
mock_httpx_client .send .side_effect = [
@@ -44,7 +43,7 @@ def test__execute_http_request__when_retry_error__should_retry_and_stop(mock_htt
44
43
45
44
def test__execute_http_request__when_streaming__should_handle_non_200_response_code (mock_httpx_client : Mock ) -> None :
46
45
error_details = "test_error"
47
- request = Request (method = _METHOD , url = _URL )
46
+ request = httpx . Request (method = _METHOD , url = _URL )
48
47
response = httpx .Response (status_code = 401 , request = request , text = error_details )
49
48
mock_httpx_client .send .return_value = response
50
49
@@ -57,7 +56,7 @@ def test__execute_http_request__when_streaming__should_handle_non_200_response_c
57
56
async def test__execute_async_http_request__when_retry_error_code_once__should_retry_and_succeed (
58
57
mock_httpx_async_client : Mock ,
59
58
) -> None :
60
- request = Request (method = _METHOD , url = _URL )
59
+ request = httpx . Request (method = _METHOD , url = _URL )
61
60
retries = 3
62
61
mock_httpx_async_client .send .side_effect = [
63
62
httpx .Response (status_code = 429 , request = request ),
@@ -73,7 +72,7 @@ async def test__execute_async_http_request__when_retry_error_code_once__should_r
73
72
async def test__execute_async_http_request__when_retry_error__should_retry_and_stop (
74
73
mock_httpx_async_client : Mock ,
75
74
) -> None :
76
- request = Request (method = _METHOD , url = _URL )
75
+ request = httpx . Request (method = _METHOD , url = _URL )
77
76
retries = len (RETRY_ERROR_CODES )
78
77
79
78
mock_httpx_async_client .send .side_effect = [
@@ -92,7 +91,7 @@ async def test__execute_async_http_request__when_streaming__should_handle_non_20
92
91
mock_httpx_async_client : Mock ,
93
92
) -> None :
94
93
error_details = "test_error"
95
- request = Request (method = _METHOD , url = _URL )
94
+ request = httpx . Request (method = _METHOD , url = _URL )
96
95
response = httpx .Response (status_code = 401 , request = request , text = error_details )
97
96
mock_httpx_async_client .send .return_value = response
98
97
0 commit comments