3
3
4
4
import time_machine
5
5
from django .test import SimpleTestCase , TestCase
6
+ from django .urls import reverse
6
7
7
8
from .models import (
8
9
Attachment ,
@@ -29,7 +30,7 @@ def test_router(self):
29
30
30
31
31
32
class TicketTestCase (TracDBCreateDatabaseMixin , TestCase ):
32
- databases = {"trac" }
33
+ databases = {"default" , " trac" }
33
34
34
35
def _create_ticket (self , custom = None , ** kwargs ):
35
36
"""
@@ -224,6 +225,59 @@ def test_from_querystring_invalid_time(self):
224
225
with self .assertRaises (ValueError ):
225
226
Ticket .objects .from_querystring ("time=2024-10-24.." )
226
227
228
+ def test_api_ticket_404 (self ):
229
+ no_ticket_url = reverse ("api_ticket" , args = [30000 ])
230
+ response = self .client .get (no_ticket_url )
231
+ self .assertEqual (response .status_code , 404 )
232
+
233
+ def test_api_ticket_405 (self ):
234
+ ticket = self ._create_ticket (summary = "test" )
235
+ ticket_url = reverse ("api_ticket" , args = [ticket .id ])
236
+ post_response = self .client .post (ticket_url , {})
237
+ delete_response = self .client .delete (ticket_url )
238
+ self .assertEqual (post_response .status_code , 405 )
239
+ self .assertEqual (delete_response .status_code , 405 )
240
+
241
+ def test_api_ticket_200 (self ):
242
+ ticket = self ._create_ticket (
243
+
244
+ type = "Bug" ,
245
+ summary = "test summary" ,
246
+ description = "test description" ,
247
+ severity = "Normal" ,
248
+ resolution = "fixed" ,
249
+ status = "assigned" ,
250
+ custom = {
251
+ "stage" : "Accepted" ,
252
+ "has_patch" : "1" ,
253
+ "needs_better_patch" : "0" ,
254
+ "needs_tests" : "0" ,
255
+ },
256
+ )
257
+
258
+ with self .assertNumQueries (1 , using = "trac" ):
259
+ response = self .client .get (reverse ("api_ticket" , args = [ticket .id ]))
260
+
261
+ self .assertEqual (response .status_code , 200 )
262
+ self .assertJSONEqual (
263
+ response .content ,
264
+ {
265
+ "id" : ticket .id ,
266
+ "type" : "Bug" ,
267
+ "summary" : "test summary" ,
268
+ "description" : "test description" ,
269
+ "severity" : "Normal" ,
270
+ "status" : "assigned" ,
271
+ "resolution" : "fixed" ,
272
+ "custom" : {
273
+ "stage" : "Accepted" ,
274
+ "has_patch" : "1" ,
275
+ "needs_better_patch" : "0" ,
276
+ "needs_tests" : "0" ,
277
+ },
278
+ },
279
+ )
280
+
227
281
228
282
class TracTimeTestCase (SimpleTestCase ):
229
283
def test_datetime_to_timestamp (self ):
0 commit comments