14
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
from model_mommy import mommy
17
from model_mommy.recipe import Recipe, seq
17
18
from ci_utils.tastypie.test import TastypieTestCase
19
from project.models import SourcePackage
18
20
from ticket.models import (get_enum_title, SubTicketWorkflowStep,
19
21
SubTicketWorkflowStepStatus, TicketWorkflowStep,
20
22
TicketWorkflowStepStatus)
24
sourcepackage_recipe = Recipe(SourcePackage, name=seq('foobar'))
23
27
class TicketReadAPITest(TastypieTestCase):
26
30
super(TicketReadAPITest, self).setUp('/api/v1')
27
31
self.ticket = mommy.make('Ticket')
28
self.sourcepackage = mommy.make('SourcePackage')
32
self.sourcepackage = sourcepackage_recipe.make()
29
33
self.spu = mommy.make('SourcePackageUpload',
30
34
sourcepackage=self.sourcepackage)
31
35
self.subticket = mommy.make('SubTicket', ticket=self.ticket,
32
36
source_package_upload=self.spu)
33
self.artifact = mommy.make('Artifact', subticket=self.subticket)
37
self.artifact_1 = mommy.make('SubTicketArtifact',
38
subticket=self.subticket)
39
self.artifact_2 = mommy.make('TicketArtifact', ticket=self.ticket)
35
def test_get_artifact_api(self):
36
obj = self.getResource('artifact/')
42
def test_get_artifact_api_subticket(self):
43
obj = self.getResource('subticketartifact/')
37
44
self.assertEqual(obj['objects'][0], {
38
u'name': unicode(self.artifact.name),
39
u'reference': unicode(self.artifact.reference),
45
u'name': unicode(self.artifact_1.name),
46
u'reference': unicode(self.artifact_1.reference),
41
48
u'status': unicode(get_enum_title(self.subticket.status,
42
49
SubTicketWorkflowStepStatus)),
77
84
u'id': self.subticket.pk,
78
85
u'resource_uri': u'/api/v1/subticket/{0}/'.format(
79
86
self.subticket.pk)},
80
u'type': unicode(self.artifact.type),
81
u'id': self.artifact.pk,
82
u'resource_uri': u'/api/v1/artifact/{0}/'.format(self.artifact.pk),
87
u'type': unicode(self.artifact_1.type),
88
u'id': self.artifact_1.pk,
89
u'resource_uri': u'/api/v1/subticketartifact/{0}/'.format(
93
def test_get_artifact_api_ticket(self):
94
obj = self.getResource('ticketartifact/')
95
self.assertEqual(obj['objects'][0], {
96
u'name': unicode(self.artifact_2.name),
97
u'reference': unicode(self.artifact_2.reference),
99
u'added_binaries': self.ticket.added_binaries,
100
u'status': unicode(get_enum_title(self.ticket.status,
101
TicketWorkflowStepStatus)),
102
u'created': unicode(self.ticket.created.strftime(
103
"%Y-%m-%dT%H:%M:%S.%f")),
104
u'current_workflow_step': unicode(get_enum_title(
105
self.ticket.current_workflow_step,
106
TicketWorkflowStep)),
107
u'description': unicode(self.ticket.description),
108
u'title': unicode(self.ticket.title),
109
u'bug_id': self.ticket.bug_id,
110
u'owner': unicode(self.ticket.owner),
111
u'removed_binaries': self.ticket.removed_binaries,
112
u'base_image': unicode(self.ticket.base_image),
113
u'id': self.ticket.pk,
114
u'resource_uri': u'/api/v1/ticket/{0}/'.format(
116
u'updated': unicode(self.ticket.updated.strftime(
117
"%Y-%m-%dT%H:%M:%S.%f"))},
118
u'type': unicode(self.artifact_2.type),
119
u'id': self.artifact_2.pk,
120
u'resource_uri': u'/api/v1/ticketartifact/{0}/'.format(
85
124
def test_get_subticket_api(self):
275
314
TicketWorkflowStep.PKG_PUBLISHING))
276
315
self.ticket_7 = mommy.make(
277
316
'Ticket', current_workflow_step=int(TicketWorkflowStep.COMPLETED))
278
self.sourcepackage = mommy.make('SourcePackage')
317
self.sourcepackage = sourcepackage_recipe.make()
279
318
self.spu = mommy.make('SourcePackageUpload',
280
319
sourcepackage=self.sourcepackage)
281
320
self.subticket_1 = mommy.make('SubTicket', ticket=self.ticket_1,
282
321
source_package_upload=self.spu)
283
self.artifact_1 = mommy.make('Artifact', subticket=self.subticket_1)
322
self.artifact_1 = mommy.make('SubTicketArtifact',
323
subticket=self.subticket_1)
284
324
self.subticket_2 = mommy.make('SubTicket', ticket=self.ticket_2,
285
325
source_package_upload=self.spu)
286
self.artifact_2 = mommy.make('Artifact', subticket=self.subticket_2)
326
self.artifact_2 = mommy.make('SubTicketArtifact',
327
subticket=self.subticket_2)
287
328
self.subticket_3 = mommy.make('SubTicket', ticket=self.ticket_3,
288
329
source_package_upload=self.spu)
289
self.artifact_3 = mommy.make('Artifact', subticket=self.subticket_3)
330
self.artifact_3 = mommy.make('SubTicketArtifact',
331
subticket=self.subticket_3)
290
332
self.subticket_4 = mommy.make('SubTicket', ticket=self.ticket_4,
291
333
source_package_upload=self.spu)
292
self.artifact_4 = mommy.make('Artifact', subticket=self.subticket_4)
334
self.artifact_4 = mommy.make('SubTicketArtifact',
335
subticket=self.subticket_4)
293
336
self.subticket_5 = mommy.make('SubTicket', ticket=self.ticket_5,
294
337
source_package_upload=self.spu)
295
self.artifact_5 = mommy.make('Artifact', subticket=self.subticket_5)
338
self.artifact_5 = mommy.make('SubTicketArtifact',
339
subticket=self.subticket_5)
296
340
self.subticket_6 = mommy.make('SubTicket', ticket=self.ticket_6,
297
341
source_package_upload=self.spu)
298
self.artifact_6 = mommy.make('Artifact', subticket=self.subticket_6)
342
self.artifact_6 = mommy.make('SubTicketArtifact',
343
subticket=self.subticket_6)
299
344
self.subticket_7 = mommy.make('SubTicket', ticket=self.ticket_7,
300
345
source_package_upload=self.spu)
301
self.artifact_7 = mommy.make('Artifact', subticket=self.subticket_7)
346
self.artifact_7 = mommy.make('SubTicketArtifact',
347
subticket=self.subticket_7)
303
349
def test_total_open_tickets(self):
304
350
obj = self.getResource('opentickets/')