14
14
15
15
from .utils import get_fixture
16
16
17
- RESPONSE_STATUS_MULTIPLE_ISSUES = httpx .Response (
18
- httpx .codes .OK ,
19
- text = get_fixture ("response-multiple-check-status-of-multiple-issues.json" ),
20
- )
21
-
22
17
GITHUB_TOKEN = "ghp_abc123"
23
18
19
+ RESPONSE_STATUS_MULTIPLE_ISSUES = get_fixture ("response-multiple-check-status-of-multiple-issues.json" )
20
+
24
21
25
22
@pytest .fixture
26
23
def api_client ():
@@ -32,14 +29,14 @@ def test_simple_client_init(api_client: ApiClient):
32
29
33
30
34
31
def test_base_url_override (respx_mock : respx .mock ):
35
- respx_mock .get (url = "https://test/repos/foo/bar/import/issues" ).mock ( return_value = RESPONSE_STATUS_MULTIPLE_ISSUES )
32
+ respx_mock .get (url = "https://test/repos/foo/bar/import/issues" ).respond ( text = RESPONSE_STATUS_MULTIPLE_ISSUES )
36
33
37
34
api_client = ApiClient (http_client = HttpClient (token = GITHUB_TOKEN , base_url = "https://test" ))
38
35
api_client .get_status_multiple ("foo" , "bar" , datetime .now (tz = UTC ))
39
36
40
37
41
38
def test_headers_override (respx_mock : respx .mock ):
42
- respx_mock .get (headers = {"Foo" : "Bar" }).mock ( return_value = RESPONSE_STATUS_MULTIPLE_ISSUES )
39
+ respx_mock .get (headers = {"Foo" : "Bar" }).respond ( text = RESPONSE_STATUS_MULTIPLE_ISSUES )
43
40
44
41
api_client = ApiClient (http_client = HttpClient (token = GITHUB_TOKEN , headers = {"Foo" : "Bar" }))
45
42
api_client .get_status_multiple ("foo" , "bar" , datetime .now (tz = UTC ))
@@ -48,7 +45,7 @@ def test_headers_override(respx_mock: respx.mock):
48
45
49
46
50
47
def test_event_hooks_override (monkeypatch : MonkeyPatch , respx_mock : respx .mock ):
51
- respx_mock .get ().mock ( return_value = RESPONSE_STATUS_MULTIPLE_ISSUES )
48
+ respx_mock .get ().respond ( text = RESPONSE_STATUS_MULTIPLE_ISSUES )
52
49
53
50
mock_log_request , mock_log_response = MagicMock (), MagicMock ()
54
51
monkeypatch .setattr (HttpClient , "log_github_api_request" , mock_log_request )
@@ -62,9 +59,7 @@ def test_event_hooks_override(monkeypatch: MonkeyPatch, respx_mock: respx.mock):
62
59
63
60
64
61
def test_event_hooks_default (monkeypatch : MonkeyPatch , respx_mock : respx .mock ):
65
- respx_mock .post ("https://api.github.com/repos/foo/bar/import/issues" ).mock (
66
- return_value = httpx .Response (httpx .codes .BAD_GATEWAY )
67
- )
62
+ respx_mock .post ("https://api.github.com/repos/foo/bar/import/issues" ) % httpx .codes .BAD_GATEWAY
68
63
69
64
mock_log_request , mock_log_response = MagicMock (), MagicMock ()
70
65
monkeypatch .setattr (HttpClient , "log_github_api_request" , mock_log_request )
@@ -92,7 +87,7 @@ def test_import_issue(api_client: ApiClient, respx_mock: respx.mock):
92
87
method = HTTPMethod .POST ,
93
88
url = "https://api.github.com/repos/owner/repository/import/issues" ,
94
89
headers = {"Authorization" : f"Token { GITHUB_TOKEN } " } | HttpClient .HEADERS ,
95
- ).mock ( return_value = httpx .Response ( httpx . codes .ACCEPTED , text = import_response ) )
90
+ ).respond ( status_code = httpx .codes .ACCEPTED , text = import_response )
96
91
97
92
response = api_client .import_issue (
98
93
"owner" ,
@@ -107,24 +102,21 @@ def test_import_issue(api_client: ApiClient, respx_mock: respx.mock):
107
102
def test_get_import_status (api_client : ApiClient , respx_mock : respx .mock ):
108
103
import_status_response = get_fixture ("response-single-check-status-of-issue-import.json" )
109
104
110
- respx_mock .get ("https://api.github.com/repos/jonmagic/foo/import/issues/3" ).mock (
111
- return_value = httpx .Response (httpx .codes .OK , text = import_status_response )
112
- )
105
+ respx_mock .get ("https://api.github.com/repos/jonmagic/foo/import/issues/3" ).respond (text = import_status_response )
113
106
114
107
response = api_client .get_status (HttpUrl ("https://api.github.com/repos/jonmagic/foo/import/issues/3" ))
115
108
assert response == IssueImportStatusResponse .model_validate_json (import_status_response )
116
109
117
110
118
111
def test_get_import_status_multiple (api_client : ApiClient , respx_mock : respx .mock ):
119
- multiple_status_response = get_fixture ("response-multiple-check-status-of-multiple-issues.json" )
120
112
since = datetime .now (tz = UTC )
121
113
122
114
respx_mock .get (
123
115
httpx .URL (
124
116
"https://api.github.com/repos/foo/bar/import/issues" ,
125
117
params = {"since" : since .isoformat ()},
126
118
)
127
- ).mock ( return_value = RESPONSE_STATUS_MULTIPLE_ISSUES )
119
+ ).respond ( text = RESPONSE_STATUS_MULTIPLE_ISSUES )
128
120
129
121
response = api_client .get_status_multiple ("foo" , "bar" , since )
130
- assert response == [IssueImportStatusResponse .model_validate (json .loads (multiple_status_response )[0 ])]
122
+ assert response == [IssueImportStatusResponse .model_validate (json .loads (RESPONSE_STATUS_MULTIPLE_ISSUES )[0 ])]
0 commit comments