143
164
self.assertRaisesWithContent(
144
165
BugTargetNotFound, message,
145
166
AffectsEmailCommand.getBugTarget, 'fnord/pting/snarf/thrup')
168
def test_execute_bug(self):
169
bug = self.factory.makeBug()
170
product = self.factory.makeProduct(name='fnord')
171
login_person(bug.bugtasks[0].target.owner)
172
command = AffectsEmailCommand('affects', ['fnord'])
173
bugtask, bugtask_event, bug_event = command.execute(bug, None)
174
self.assertEqual(bug, bugtask.bug)
175
self.assertEqual(product, bugtask.target)
176
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
177
self.assertEqual(None, bug_event)
179
def test_execute_bug_params_product(self):
180
user = self.factory.makePerson()
182
product = self.factory.makeProduct(name='fnord')
183
message = self.factory.makeMessage(
184
subject='bug title', content='borked\n affects fnord')
185
command = AffectsEmailCommand('affects', ['fnord'])
186
bug_params = CreateBugParams(
187
title='bug title', msg=message, owner=user)
188
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
189
self.assertEqual(product, bugtask.target)
190
self.assertEqual('bug title', bugtask.bug.title)
191
self.assertEqual('borked\n affects fnord', bugtask.bug.description)
192
self.assertEqual(user, bugtask.bug.owner)
193
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
194
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
196
def test_execute_bug_params_productseries(self):
197
product = self.factory.makeProduct(name='fnord')
198
login_person(product.owner)
199
series = self.factory.makeProductSeries(name='pting', product=product)
200
message = self.factory.makeMessage(
201
subject='bug title', content='borked\n affects fnord/pting')
202
command = AffectsEmailCommand('affects', ['fnord/pting'])
203
bug_params = CreateBugParams(
204
title='bug title', msg=message, owner=product.owner)
205
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
206
self.assertEqual(series, bugtask.target)
207
self.assertEqual('bug title', bugtask.bug.title)
208
self.assertEqual(2, len(bugtask.bug.bugtasks))
209
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
210
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
212
def test_execute_bug_params_distribution(self):
213
user = self.factory.makePerson()
215
distribution = self.factory.makeDistribution(name='fnord')
216
message = self.factory.makeMessage(
217
subject='bug title', content='borked\n affects fnord')
218
command = AffectsEmailCommand('affects', ['fnord'])
219
bug_params = CreateBugParams(
220
title='bug title', msg=message, owner=user)
221
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
222
self.assertEqual(distribution, bugtask.target)
223
self.assertEqual('bug title', bugtask.bug.title)
224
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
225
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
227
def test_execute_bug_params_dsp(self):
228
user = self.factory.makePerson()
230
distribution = self.factory.makeDistribution(name='fnord')
231
series = self.factory.makeDistroSeries(
232
name='pting', distribution=distribution)
233
package = self.factory.makeSourcePackage(
234
sourcepackagename='snarf', distroseries=series, publish=True)
235
dsp = distribution.getSourcePackage(package.name)
236
message = self.factory.makeMessage(
237
subject='bug title', content='borked\n affects fnord/snarf')
238
command = AffectsEmailCommand('affects', ['fnord/snarf'])
239
bug_params = CreateBugParams(
240
title='bug title', msg=message, owner=user)
241
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
242
self.assertEqual(dsp, bugtask.target)
243
self.assertEqual('bug title', bugtask.bug.title)
244
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
245
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
247
def test_execute_bug_params_distroseries(self):
248
distribution = self.factory.makeDistribution(name='fnord')
249
login_person(distribution.owner)
250
series = self.factory.makeDistroSeries(
251
name='pting', distribution=distribution)
252
message = self.factory.makeMessage(
253
subject='bug title', content='borked\n affects fnord/pting')
254
command = AffectsEmailCommand('affects', ['fnord/pting'])
255
bug_params = CreateBugParams(
256
title='bug title', msg=message, owner=distribution.owner)
257
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
258
self.assertEqual(series, bugtask.target)
259
self.assertEqual('bug title', bugtask.bug.title)
260
self.assertEqual(2, len(bugtask.bug.bugtasks))
261
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
262
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
264
def test_execute_bug_params_distroseries_sourcepackage(self):
265
distribution = self.factory.makeDistribution(name='fnord')
266
login_person(distribution.owner)
267
series = self.factory.makeDistroSeries(
268
name='pting', distribution=distribution)
269
package = self.factory.makeSourcePackage(
270
sourcepackagename='snarf', distroseries=series, publish=True)
271
message = self.factory.makeMessage(
272
subject='bug title', content='borked\n affects fnord/pting/snarf')
273
command = AffectsEmailCommand('affects', ['fnord/pting/snarf'])
274
bug_params = CreateBugParams(
275
title='bug title', msg=message, owner=distribution.owner)
276
bugtask, bugtask_event, bug_event = command.execute(bug_params, None)
277
self.assertEqual(package, bugtask.target)
278
self.assertEqual('bug title', bugtask.bug.title)
279
self.assertEqual(2, len(bugtask.bug.bugtasks))
280
self.assertTrue(IObjectCreatedEvent.providedBy(bugtask_event))
281
self.assertTrue(IObjectCreatedEvent.providedBy(bug_event))
284
class BugEmailCommandTestCase(TestCaseWithFactory):
286
layer = LaunchpadFunctionalLayer
288
def test_execute_bug_id(self):
289
bug = self.factory.makeBug()
290
command = BugEmailCommand('bug', [str(bug.id)])
291
self.assertEqual((bug, None), command.execute(None, None))
293
def test_execute_bug_id_wrong_type(self):
294
command = BugEmailCommand('bug', ['nickname'])
295
error = self.assertRaises(
296
EmailProcessingError, command.execute, None, None)
297
message = str(error).split('\n')
299
"The 'bug' command expects either 'new' or a bug id.", message[0])
301
def test_execute_bug_id_not_found(self):
302
command = BugEmailCommand('bug', ['9999999'])
303
error = self.assertRaises(
304
EmailProcessingError, command.execute, None, None)
305
message = str(error).split('\n')
307
"There is no such bug in Launchpad: 9999999", message[0])
309
def test_execute_bug_id_new(self):
310
user = self.factory.makePerson()
312
message = self.factory.makeSignedMessage(
313
body='borked\n affects fnord',
314
subject='title borked',
315
to_address='new@bugs.launchpad.dev')
316
filealias = self.factory.makeLibraryFileAlias()
317
command = BugEmailCommand('bug', ['new'])
318
params, event = command.execute(message, filealias)
319
self.assertEqual(None, event)
320
self.assertEqual(user, params.owner)
321
self.assertEqual('title borked', params.title)
322
self.assertEqual(message['Message-Id'], params.msg.rfc822msgid)
325
class PrivateEmailCommandTestCase(TestCaseWithFactory):
327
layer = DatabaseFunctionalLayer
329
def test_execute_bug(self):
330
bug = self.factory.makeBug()
331
login_person(bug.bugtasks[0].target.owner)
332
command = PrivateEmailCommand('private', ['yes'])
333
exec_bug, event = command.execute(bug, None)
334
self.assertEqual(bug, exec_bug)
335
self.assertEqual(True, bug.private)
336
self.assertTrue(IObjectModifiedEvent.providedBy(event))
338
def test_execute_bug_params(self):
339
user = self.factory.makePerson()
341
bug_params = CreateBugParams(title='bug title', owner=user)
342
command = PrivateEmailCommand('private', ['yes'])
343
dummy_event = object()
344
params, event = command.execute(bug_params, dummy_event)
345
self.assertEqual(bug_params, params)
346
self.assertEqual(True, bug_params.private)
347
self.assertEqual(dummy_event, event)
349
def test_execute_bug_params_with_security(self):
350
# BugSet.createBug() requires new security bugs to be private.
351
user = self.factory.makePerson()
353
bug_params = CreateBugParams(
354
title='bug title', owner=user, security_related='yes')
355
command = PrivateEmailCommand('private', ['no'])
356
dummy_event = object()
357
params, event = command.execute(bug_params, dummy_event)
358
self.assertEqual(bug_params, params)
359
self.assertEqual(True, bug_params.private)
360
self.assertEqual(dummy_event, event)
363
class SecurityEmailCommandTestCase(TestCaseWithFactory):
365
layer = DatabaseFunctionalLayer
367
def test_execute_bug(self):
368
bug = self.factory.makeBug()
369
login_person(bug.bugtasks[0].target.owner)
370
command = SecurityEmailCommand('security', ['yes'])
371
exec_bug, event = command.execute(bug, None)
372
self.assertEqual(bug, exec_bug)
373
self.assertEqual(True, bug.security_related)
374
self.assertTrue(IObjectModifiedEvent.providedBy(event))
376
def test_execute_bug_params(self):
377
user = self.factory.makePerson()
379
bug_params = CreateBugParams(title='bug title', owner=user)
380
command = SecurityEmailCommand('security', ['yes'])
381
dummy_event = object()
382
params, event = command.execute(bug_params, dummy_event)
383
self.assertEqual(bug_params, params)
384
self.assertEqual(True, bug_params.security_related)
385
self.assertEqual(True, bug_params.private)
386
self.assertEqual(dummy_event, event)
389
class SubscribeEmailCommandTestCase(TestCaseWithFactory):
391
layer = DatabaseFunctionalLayer
393
def test_execute_bug_with_user_name(self):
394
bug = self.factory.makeBug()
395
login_person(bug.bugtasks[0].target.owner)
396
subscriber = self.factory.makePerson()
397
command = SubscribeEmailCommand('subscribe', [subscriber.name])
398
dummy_event = object()
399
exec_bug, event = command.execute(bug, dummy_event)
400
self.assertEqual(bug, exec_bug)
401
self.assertContentEqual(
402
[bug.owner, subscriber], bug.getDirectSubscribers())
403
self.assertEqual(dummy_event, event)
405
def test_execute_bug_without_user_name(self):
406
bug = self.factory.makeBug()
407
target_owner = bug.bugtasks[0].target.owner
408
login_person(target_owner)
409
command = SubscribeEmailCommand('subscribe', [])
410
dummy_event = object()
411
exec_bug, event = command.execute(bug, dummy_event)
412
self.assertEqual(bug, exec_bug)
413
self.assertContentEqual(
414
[bug.owner, target_owner], bug.getDirectSubscribers())
415
self.assertEqual(dummy_event, event)
417
def test_execute_bug_params_one_subscriber(self):
418
user = self.factory.makePerson()
420
subscriber = self.factory.makePerson()
421
bug_params = CreateBugParams(title='bug title', owner=user)
422
command = SubscribeEmailCommand('subscribe', [subscriber.name])
423
dummy_event = object()
424
params, event = command.execute(bug_params, dummy_event)
425
self.assertEqual(bug_params, params)
426
self.assertContentEqual([subscriber], bug_params.subscribers)
427
self.assertEqual(dummy_event, event)
429
def test_execute_bug_params_many_subscriber(self):
430
user = self.factory.makePerson()
432
subscriber_1 = self.factory.makePerson()
433
subscriber_2 = self.factory.makePerson()
434
bug_params = CreateBugParams(
435
title='bug title', owner=user, subscribers=[subscriber_1])
436
command = SubscribeEmailCommand('subscribe', [subscriber_2.name])
437
dummy_event = object()
438
params, event = command.execute(bug_params, dummy_event)
439
self.assertEqual(bug_params, params)
440
self.assertContentEqual(
441
[subscriber_1, subscriber_2], bug_params.subscribers)
442
self.assertEqual(dummy_event, event)
445
class UnsubscribeEmailCommandTestCase(TestCaseWithFactory):
447
layer = DatabaseFunctionalLayer
449
def test_execute_bug_with_user_name(self):
450
bug = self.factory.makeBug()
451
target_owner = bug.bugtasks[0].target.owner
452
login_person(target_owner)
453
bug.subscribe(target_owner, target_owner)
454
command = UnsubscribeEmailCommand('unsubscribe', [target_owner.name])
455
dummy_event = object()
456
exec_bug, event = command.execute(bug, dummy_event)
457
self.assertEqual(bug, exec_bug)
458
self.assertContentEqual(
459
[bug.owner], bug.getDirectSubscribers())
460
self.assertEqual(dummy_event, event)
462
def test_execute_bug_without_user_name(self):
463
bug = self.factory.makeBug()
464
target_owner = bug.bugtasks[0].target.owner
465
login_person(target_owner)
466
bug.subscribe(target_owner, target_owner)
467
command = UnsubscribeEmailCommand('unsubscribe', [])
468
dummy_event = object()
469
exec_bug, event = command.execute(bug, dummy_event)
470
self.assertEqual(bug, exec_bug)
471
self.assertContentEqual(
472
[bug.owner], bug.getDirectSubscribers())
473
self.assertEqual(dummy_event, event)
475
def test_execute_bug_params(self):
476
# Unsubscribe does nothing because the is not yet a bug.
477
# Any value can be used for the user name.
478
user = self.factory.makePerson()
480
bug_params = CreateBugParams(title='bug title', owner=user)
481
command = UnsubscribeEmailCommand('unsubscribe', ['non-existent'])
482
dummy_event = object()
483
params, event = command.execute(bug_params, dummy_event)
484
self.assertEqual(bug_params, params)
485
self.assertEqual(dummy_event, event)
488
class SummaryEmailCommandTestCase(TestCaseWithFactory):
490
layer = DatabaseFunctionalLayer
492
def test_execute_bug(self):
493
bug = self.factory.makeBug()
494
login_person(bug.bugtasks[0].target.owner)
495
command = SummaryEmailCommand('summary', ['new title'])
496
exec_bug, event = command.execute(bug, None)
497
self.assertEqual(bug, exec_bug)
498
self.assertEqual('new title', bug.title)
499
self.assertTrue(IObjectModifiedEvent.providedBy(event))
501
def test_execute_bug_params(self):
502
user = self.factory.makePerson()
504
bug_params = CreateBugParams(title='bug title', owner=user)
505
command = SummaryEmailCommand('summary', ['new title'])
506
dummy_event = object()
507
params, event = command.execute(bug_params, dummy_event)
508
self.assertEqual(bug_params, params)
509
self.assertEqual('new title', bug_params.title)
510
self.assertEqual(dummy_event, event)
513
class DuplicateEmailCommandTestCase(TestCaseWithFactory):
515
layer = DatabaseFunctionalLayer
517
def test_execute_bug(self):
518
master_bug = self.factory.makeBug()
519
bug = self.factory.makeBug()
520
login_person(bug.bugtasks[0].target.owner)
521
command = DuplicateEmailCommand('duplicate', [str(master_bug.id)])
522
exec_bug, event = command.execute(bug, None)
523
self.assertEqual(master_bug, exec_bug)
524
self.assertEqual(master_bug, bug.duplicateof)
525
self.assertTrue(IObjectModifiedEvent.providedBy(event))
527
def test_execute_bug_params(self):
528
# duplicate does nothing because the is not yet a bug.
529
# Any value can be used for the bug is.
530
user = self.factory.makePerson()
532
bug_params = CreateBugParams(title='bug title', owner=user)
533
command = DuplicateEmailCommand('duplicate', ['non-existent'])
534
dummy_event = object()
535
params, event = command.execute(bug_params, dummy_event)
536
self.assertEqual(bug_params, params)
537
self.assertEqual(dummy_event, event)
540
class CVEEmailCommandTestCase(TestCaseWithFactory):
542
layer = DatabaseFunctionalLayer
544
def test_execute_bug(self):
545
bug = self.factory.makeBug()
546
login_person(bug.bugtasks[0].target.owner)
547
cve = self.factory.makeCVE('1999-1717')
548
command = CVEEmailCommand('cve', ['1999-1717'])
549
dummy_event = object()
550
exec_bug, event = command.execute(bug, dummy_event)
551
self.assertEqual(bug, exec_bug)
552
self.assertEqual([cve], [cve_link.cve for cve_link in bug.cve_links])
553
self.assertEqual(dummy_event, event)
555
def test_execute_bug_params(self):
556
user = self.factory.makePerson()
558
cve = self.factory.makeCVE('1999-1717')
559
bug_params = CreateBugParams(title='bug title', owner=user)
560
command = CVEEmailCommand('cve', ['1999-1717'])
561
dummy_event = object()
562
params, event = command.execute(bug_params, dummy_event)
563
self.assertEqual(bug_params, params)
564
self.assertEqual(cve, params.cve)
565
self.assertEqual(dummy_event, event)
568
class TagEmailCommandTestCase(TestCaseWithFactory):
570
layer = DatabaseFunctionalLayer
572
def test_execute_bug(self):
573
bug = self.factory.makeBug()
574
login_person(bug.bugtasks[0].target.owner)
576
command = TagEmailCommand('tag', ['ui', 'trivial'])
577
dummy_event = object()
578
exec_bug, event = command.execute(bug, dummy_event)
579
self.assertEqual(bug, exec_bug)
580
self.assertContentEqual(['form', 'ui', 'trivial'], bug.tags)
581
self.assertEqual(dummy_event, event)
583
def test_execute_bug_params(self):
584
user = self.factory.makePerson()
586
bug_params = CreateBugParams(title='bug title', owner=user)
587
command = TagEmailCommand('tag', ['ui', 'trivial'])
588
dummy_event = object()
589
params, event = command.execute(bug_params, dummy_event)
590
self.assertEqual(bug_params, params)
591
self.assertContentEqual(['ui', 'trivial'], bug_params.tags)
592
self.assertEqual(dummy_event, event)