1
1
import json
2
2
from datetime import datetime
3
3
4
- import httpx
5
4
import pytest
6
5
import respx
7
6
22
21
],
23
22
)
24
23
def test_query_tickets (kwargs : dict , expected : str , api_client : ApiClient , respx_mock : respx .mock ):
25
- respx_mock .post ().mock (
26
- return_value = httpx .Response (
27
- status_code = httpx .codes .OK ,
28
- text = """{"error": null, "result": [3, 2, 1], "id": null}""" ,
29
- )
30
- )
24
+ respx_mock .post ().respond (text = """{"error": null, "result": [3, 2, 1], "id": null}""" )
31
25
32
26
def get_last_request_params () -> str :
33
27
(param ,) = json .loads (respx_mock .calls .last .request .content )["params" ]
@@ -38,12 +32,7 @@ def get_last_request_params() -> str:
38
32
39
33
40
34
def test_get_ticket_attachments (api_client : ApiClient , respx_mock : respx .mock ):
41
- respx_mock .post ().mock (
42
- return_value = httpx .Response (
43
- status_code = httpx .codes .OK ,
44
- text = get_fixture ("trac-get-ticket-attachments-response.json" ),
45
- )
46
- )
35
+ respx_mock .post ().respond (text = get_fixture ("trac-get-ticket-attachments-response.json" ))
47
36
48
37
(attachment ,) = api_client .get_ticket_attachments (1 )
49
38
assert respx_mock .calls .last .request .content == b'{"id":null,"method":"ticket.listAttachments","params":[1]}'
@@ -58,12 +47,7 @@ def test_get_ticket_attachments(api_client: ApiClient, respx_mock: respx.mock):
58
47
59
48
60
49
def test_get_ticket_changelog (api_client : ApiClient , respx_mock : respx .mock ):
61
- respx_mock .post ().mock (
62
- return_value = httpx .Response (
63
- status_code = httpx .codes .OK ,
64
- text = get_fixture ("trac-get-ticket-changelog-response.json" ),
65
- )
66
- )
50
+ respx_mock .post ().respond (text = get_fixture ("trac-get-ticket-changelog-response.json" ))
67
51
68
52
changelog = api_client .get_ticket_changelog (1 )
69
53
assert respx_mock .calls .last .request .content == b'{"id":null,"method":"ticket.changeLog","params":[1]}'
@@ -113,12 +97,7 @@ def test_get_ticket_changelog(api_client: ApiClient, respx_mock: respx.mock):
113
97
114
98
115
99
def test_get_ticket (api_client : ApiClient , respx_mock : respx .mock ):
116
- respx_mock .post ().mock (
117
- return_value = httpx .Response (
118
- status_code = httpx .codes .OK ,
119
- text = get_fixture ("trac-get-ticket-response.json" ),
120
- )
121
- )
100
+ respx_mock .post ().respond (text = get_fixture ("trac-get-ticket-response.json" ))
122
101
123
102
assert api_client .get_ticket (1 ) == TracTicketProperties (
124
103
id = 1 ,
@@ -145,12 +124,7 @@ def test_get_ticket(api_client: ApiClient, respx_mock: respx.mock):
145
124
146
125
147
126
def test_get_ticket_last_field_change (api_client : ApiClient , respx_mock : respx .mock ):
148
- respx_mock .post ().mock (
149
- return_value = httpx .Response (
150
- status_code = httpx .codes .OK ,
151
- text = get_fixture ("trac-get-ticket-changelog-response.json" ),
152
- )
153
- )
127
+ respx_mock .post ().respond (text = get_fixture ("trac-get-ticket-changelog-response.json" ))
154
128
155
129
last_comment = api_client .get_ticket_last_field_change (1 , "comment" )
156
130
assert last_comment == TracTicketChangelogEntry (
0 commit comments