1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
import transaction
from datetime import datetime
from lazr.lifecycle.event import ObjectModifiedEvent
from lazr.lifecycle.snapshot import Snapshot
from pytz import UTC
from storm.store import Store
from testtools.matchers import LessThan
from zope.component import (
getMultiAdapter,
getUtility,
)
from zope.event import notify
from zope.interface import providedBy
from zope.security.proxy import removeSecurityProxy
from canonical.launchpad.ftests import (
ANONYMOUS,
login,
login_person,
)
from canonical.launchpad.testing.pages import find_tag_by_id
from canonical.launchpad.webapp import canonical_url
from canonical.launchpad.webapp.servers import LaunchpadTestRequest
from canonical.testing.layers import (
DatabaseFunctionalLayer,
LaunchpadFunctionalLayer,
)
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
from lp.bugs.browser.bugtask import (
BugActivityItem,
BugTaskEditView,
BugTasksAndNominationsView,
)
from lp.bugs.interfaces.bugactivity import IBugActivitySet
from lp.bugs.interfaces.bugnomination import IBugNomination
from lp.bugs.interfaces.bugtask import (
BugTaskStatus,
IBugTask,
IBugTaskSet,
)
from lp.services.propertycache import get_property_cache
from lp.soyuz.interfaces.component import IComponentSet
from lp.testing import (
celebrity_logged_in,
person_logged_in,
TestCaseWithFactory,
)
from lp.testing._webservice import QueryCollector
from lp.testing.matchers import (
BrowsesWithQueryLimit,
HasQueryCount,
)
from lp.testing.sampledata import (
ADMIN_EMAIL,
NO_PRIVILEGE_EMAIL,
USER_EMAIL,
)
from lp.testing.views import create_initialized_view
class TestBugTaskView(TestCaseWithFactory):
layer = LaunchpadFunctionalLayer
def invalidate_caches(self, obj):
store = Store.of(obj)
# Make sure everything is in the database.
store.flush()
# And invalidate the cache (not a reset, because that stops us using
# the domain objects)
store.invalidate()
def test_rendered_query_counts_constant_with_team_memberships(self):
login(ADMIN_EMAIL)
task = self.factory.makeBugTask()
person_no_teams = self.factory.makePerson(password='test')
person_with_teams = self.factory.makePerson(password='test')
for _ in range(10):
self.factory.makeTeam(members=[person_with_teams])
# count with no teams
url = canonical_url(task)
recorder = QueryCollector()
recorder.register()
self.addCleanup(recorder.unregister)
self.invalidate_caches(task)
self.getUserBrowser(url, person_no_teams)
# This may seem large: it is; there is easily another 30% fat in
# there.
self.assertThat(recorder, HasQueryCount(LessThan(74)))
count_with_no_teams = recorder.count
# count with many teams
self.invalidate_caches(task)
self.getUserBrowser(url, person_with_teams)
# Allow an increase of one because storm bug 619017 causes additional
# queries, revalidating things unnecessarily. An increase which is
# less than the number of new teams shows it is definitely not
# growing per-team.
self.assertThat(recorder, HasQueryCount(
LessThan(count_with_no_teams + 3),
))
def test_rendered_query_counts_constant_with_attachments(self):
with celebrity_logged_in('admin'):
browses_under_limit = BrowsesWithQueryLimit(
78, self.factory.makePerson())
# First test with a single attachment.
task = self.factory.makeBugTask()
self.factory.makeBugAttachment(bug=task.bug)
self.assertThat(task, browses_under_limit)
with celebrity_logged_in('admin'):
# And now with 10.
task = self.factory.makeBugTask()
self.factory.makeBugTask(bug=task.bug)
for i in range(10):
self.factory.makeBugAttachment(bug=task.bug)
self.assertThat(task, browses_under_limit)
def test_interesting_activity(self):
# The interesting_activity property returns a tuple of interesting
# `BugActivityItem`s.
bug = self.factory.makeBug()
view = create_initialized_view(
bug.default_bugtask, name=u'+index', rootsite='bugs')
def add_activity(what, old=None, new=None, message=None):
getUtility(IBugActivitySet).new(
bug, datetime.now(UTC), bug.owner, whatchanged=what,
oldvalue=old, newvalue=new, message=message)
del get_property_cache(view).interesting_activity
# A fresh bug has no interesting activity.
self.assertEqual((), view.interesting_activity)
# Some activity is not considered interesting.
add_activity("boring")
self.assertEqual((), view.interesting_activity)
# A description change is interesting.
add_activity("description")
self.assertEqual(1, len(view.interesting_activity))
[activity] = view.interesting_activity
self.assertEqual("description", activity.whatchanged)
def test_error_for_changing_target_with_invalid_status(self):
# If a user moves a bug task with a restricted status (say,
# Triaged) to a target where they do not have permission to set
# that status, they will be unable to complete the retargeting
# and will instead receive an error in the UI.
person = self.factory.makePerson()
product = self.factory.makeProduct(
name='product1', owner=person, official_malone=True)
with person_logged_in(person):
product.setBugSupervisor(person, person)
product_2 = self.factory.makeProduct(
name='product2', official_malone=True)
with person_logged_in(product_2.owner):
product_2.setBugSupervisor(product_2.owner, product_2.owner)
bug = self.factory.makeBug(
product=product, owner=person)
# We need to commit here, otherwise all the sample data we
# created gets destroyed when the transaction is rolled back.
transaction.commit()
with person_logged_in(person):
form_data = {
'%s.product' % product.name: product_2.name,
'%s.status' % product.name: BugTaskStatus.TRIAGED.title,
'%s.actions.save' % product.name: 'Save Changes',
}
view = create_initialized_view(
bug.default_bugtask, name=u'+editstatus',
form=form_data)
# The bugtask's target won't have changed, since an error
# happend. The error will be listed in the view.
self.assertEqual(1, len(view.errors))
self.assertEqual(product, bug.default_bugtask.target)
class TestBugTasksAndNominationsView(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestBugTasksAndNominationsView, self).setUp()
login(ADMIN_EMAIL)
self.bug = self.factory.makeBug()
self.view = BugTasksAndNominationsView(
self.bug, LaunchpadTestRequest())
def refresh(self):
# The view caches, to see different scenarios, a refresh is needed.
self.view = BugTasksAndNominationsView(
self.bug, LaunchpadTestRequest())
def test_current_user_affected_status(self):
self.failUnlessEqual(
None, self.view.current_user_affected_status)
self.bug.markUserAffected(self.view.user, True)
self.refresh()
self.failUnlessEqual(
True, self.view.current_user_affected_status)
self.bug.markUserAffected(self.view.user, False)
self.refresh()
self.failUnlessEqual(
False, self.view.current_user_affected_status)
def test_current_user_affected_js_status(self):
self.failUnlessEqual(
'null', self.view.current_user_affected_js_status)
self.bug.markUserAffected(self.view.user, True)
self.refresh()
self.failUnlessEqual(
'true', self.view.current_user_affected_js_status)
self.bug.markUserAffected(self.view.user, False)
self.refresh()
self.failUnlessEqual(
'false', self.view.current_user_affected_js_status)
def test_not_many_bugtasks(self):
for count in range(10 - len(self.bug.bugtasks) - 1):
self.factory.makeBugTask(bug=self.bug)
self.view.initialize()
self.failIf(self.view.many_bugtasks)
row_view = self.view._getTableRowView(
self.bug.default_bugtask, False, False)
self.failIf(row_view.many_bugtasks)
def test_many_bugtasks(self):
for count in range(10 - len(self.bug.bugtasks)):
self.factory.makeBugTask(bug=self.bug)
self.view.initialize()
self.failUnless(self.view.many_bugtasks)
row_view = self.view._getTableRowView(
self.bug.default_bugtask, False, False)
self.failUnless(row_view.many_bugtasks)
def test_other_users_affected_count(self):
# The number of other users affected does not change when the
# logged-in user marked him or herself as affected or not.
self.failUnlessEqual(
1, self.view.other_users_affected_count)
self.bug.markUserAffected(self.view.user, True)
self.refresh()
self.failUnlessEqual(
1, self.view.other_users_affected_count)
self.bug.markUserAffected(self.view.user, False)
self.refresh()
self.failUnlessEqual(
1, self.view.other_users_affected_count)
def test_other_users_affected_count_other_users(self):
# The number of other users affected only changes when other
# users mark themselves as affected.
self.failUnlessEqual(
1, self.view.other_users_affected_count)
other_user_1 = self.factory.makePerson()
self.bug.markUserAffected(other_user_1, True)
self.failUnlessEqual(
2, self.view.other_users_affected_count)
other_user_2 = self.factory.makePerson()
self.bug.markUserAffected(other_user_2, True)
self.failUnlessEqual(
3, self.view.other_users_affected_count)
self.bug.markUserAffected(other_user_1, False)
self.failUnlessEqual(
2, self.view.other_users_affected_count)
self.bug.markUserAffected(self.view.user, True)
self.refresh()
self.failUnlessEqual(
2, self.view.other_users_affected_count)
def test_affected_statement_no_one_affected(self):
self.bug.markUserAffected(self.bug.owner, False)
self.failUnlessEqual(
0, self.view.other_users_affected_count)
self.failUnlessEqual(
"Does this bug affect you?",
self.view.affected_statement)
def test_affected_statement_only_you(self):
self.view.context.markUserAffected(self.view.user, True)
self.failUnless(self.bug.isUserAffected(self.view.user))
self.view.context.markUserAffected(self.bug.owner, False)
self.failUnlessEqual(
0, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects you",
self.view.affected_statement)
def test_affected_statement_only_not_you(self):
self.view.context.markUserAffected(self.view.user, False)
self.failIf(self.bug.isUserAffected(self.view.user))
self.view.context.markUserAffected(self.bug.owner, False)
self.failUnlessEqual(
0, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug doesn't affect you",
self.view.affected_statement)
def test_affected_statement_1_person_not_you(self):
self.assertIs(None, self.bug.isUserAffected(self.view.user))
self.failUnlessEqual(
1, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects 1 person. Does this bug affect you?",
self.view.affected_statement)
def test_affected_statement_1_person_and_you(self):
self.view.context.markUserAffected(self.view.user, True)
self.failUnless(self.bug.isUserAffected(self.view.user))
self.failUnlessEqual(
1, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects you and 1 other person",
self.view.affected_statement)
def test_affected_statement_1_person_and_not_you(self):
self.view.context.markUserAffected(self.view.user, False)
self.failIf(self.bug.isUserAffected(self.view.user))
self.failUnlessEqual(
1, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects 1 person, but not you",
self.view.affected_statement)
def test_affected_statement_more_than_1_person_not_you(self):
self.assertIs(None, self.bug.isUserAffected(self.view.user))
other_user = self.factory.makePerson()
self.view.context.markUserAffected(other_user, True)
self.failUnlessEqual(
2, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects 2 people. Does this bug affect you?",
self.view.affected_statement)
def test_affected_statement_more_than_1_person_and_you(self):
self.view.context.markUserAffected(self.view.user, True)
self.failUnless(self.bug.isUserAffected(self.view.user))
other_user = self.factory.makePerson()
self.view.context.markUserAffected(other_user, True)
self.failUnlessEqual(
2, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects you and 2 other people",
self.view.affected_statement)
def test_affected_statement_more_than_1_person_and_not_you(self):
self.view.context.markUserAffected(self.view.user, False)
self.failIf(self.bug.isUserAffected(self.view.user))
other_user = self.factory.makePerson()
self.view.context.markUserAffected(other_user, True)
self.failUnlessEqual(
2, self.view.other_users_affected_count)
self.failUnlessEqual(
"This bug affects 2 people, but not you",
self.view.affected_statement)
def test_anon_affected_statement_no_one_affected(self):
self.bug.markUserAffected(self.bug.owner, False)
self.failUnlessEqual(0, self.bug.users_affected_count)
self.assertIs(None, self.view.anon_affected_statement)
def test_anon_affected_statement_1_user_affected(self):
self.failUnlessEqual(1, self.bug.users_affected_count)
self.failUnlessEqual(
"This bug affects 1 person",
self.view.anon_affected_statement)
def test_anon_affected_statement_2_users_affected(self):
self.view.context.markUserAffected(self.view.user, True)
self.failUnlessEqual(2, self.bug.users_affected_count)
self.failUnlessEqual(
"This bug affects 2 people",
self.view.anon_affected_statement)
def test_getTargetLinkTitle_product(self):
# The target link title is always none for products.
target = self.factory.makeProduct()
bug_task = self.factory.makeBugTask(bug=self.bug, target=target)
self.view.initialize()
self.assertEqual(None, self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_productseries(self):
# The target link title is always none for productseries.
target = self.factory.makeProductSeries()
bug_task = self.factory.makeBugTask(bug=self.bug, target=target)
self.view.initialize()
self.assertEqual(None, self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_distribution(self):
# The target link title is always none for distributions.
target = self.factory.makeDistribution()
bug_task = self.factory.makeBugTask(bug=self.bug, target=target)
self.view.initialize()
self.assertEqual(None, self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_distroseries(self):
# The target link title is always none for distroseries.
target = self.factory.makeDistroSeries()
bug_task = self.factory.makeBugTask(bug=self.bug, target=target)
self.view.initialize()
self.assertEqual(None, self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_unpublished_distributionsourcepackage(self):
# The target link title states that the package is not published
# in the current release.
distribution = self.factory.makeDistribution(name='boy')
spn = self.factory.makeSourcePackageName('badger')
component = getUtility(IComponentSet)['universe']
maintainer = self.factory.makePerson(name="jim")
creator = self.factory.makePerson(name="tim")
self.factory.makeSourcePackagePublishingHistory(
distroseries=distribution.currentseries, version='2.0',
component=component, sourcepackagename=spn,
date_uploaded=datetime(2008, 7, 18, 10, 20, 30, tzinfo=UTC),
maintainer=maintainer, creator=creator)
target = distribution.getSourcePackage('badger')
bug_task = self.factory.makeBugTask(
bug=self.bug, target=target, publish=False)
self.view.initialize()
self.assertEqual({}, self.view.target_releases)
self.assertEqual(
'No current release for this source package in Boy',
self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_published_distributionsourcepackage(self):
# The target link title states the information about the current
# package in the distro.
distribution = self.factory.makeDistribution(name='koi')
distroseries = self.factory.makeDistroSeries(
distribution=distribution)
spn = self.factory.makeSourcePackageName('finch')
component = getUtility(IComponentSet)['universe']
maintainer = self.factory.makePerson(name="jim")
creator = self.factory.makePerson(name="tim")
self.factory.makeSourcePackagePublishingHistory(
distroseries=distroseries, version='2.0',
component=component, sourcepackagename=spn,
date_uploaded=datetime(2008, 7, 18, 10, 20, 30, tzinfo=UTC),
maintainer=maintainer, creator=creator)
target = distribution.getSourcePackage('finch')
bug_task = self.factory.makeBugTask(
bug=self.bug, target=target, publish=False)
self.view.initialize()
self.assertTrue(
target in self.view.target_releases.keys())
self.assertEqual(
'Latest release: 2.0, uploaded to universe on '
'2008-07-18 10:20:30+00:00 by Tim (tim), maintained by Jim (jim)',
self.view.getTargetLinkTitle(bug_task.target))
def test_getTargetLinkTitle_published_sourcepackage(self):
# The target link title states the information about the current
# package in the distro.
distroseries = self.factory.makeDistroSeries()
spn = self.factory.makeSourcePackageName('bunny')
component = getUtility(IComponentSet)['universe']
maintainer = self.factory.makePerson(name="jim")
creator = self.factory.makePerson(name="tim")
self.factory.makeSourcePackagePublishingHistory(
distroseries=distroseries, version='2.0',
component=component, sourcepackagename=spn,
date_uploaded=datetime(2008, 7, 18, 10, 20, 30, tzinfo=UTC),
maintainer=maintainer, creator=creator)
target = distroseries.getSourcePackage('bunny')
bug_task = self.factory.makeBugTask(
bug=self.bug, target=target, publish=False)
self.view.initialize()
self.assertTrue(
target in self.view.target_releases.keys())
self.assertEqual(
'Latest release: 2.0, uploaded to universe on '
'2008-07-18 10:20:30+00:00 by Tim (tim), maintained by Jim (jim)',
self.view.getTargetLinkTitle(bug_task.target))
def _get_object_type(self, task_or_nomination):
if IBugTask.providedBy(task_or_nomination):
return "bugtask"
elif IBugNomination.providedBy(task_or_nomination):
return "nomination"
else:
return "unknown"
def test_bugtask_listing_for_inactive_projects(self):
# Bugtasks should only be listed for active projects.
product_foo = self.factory.makeProduct(name="foo")
product_bar = self.factory.makeProduct(name="bar")
foo_bug = self.factory.makeBug(product=product_foo)
bugtask_set = getUtility(IBugTaskSet)
bugtask_set.createTask(foo_bug, foo_bug.owner, product_bar)
removeSecurityProxy(product_bar).active = False
request = LaunchpadTestRequest()
foo_bugtasks_and_nominations_view = getMultiAdapter(
(foo_bug, request), name="+bugtasks-and-nominations-table")
foo_bugtasks_and_nominations_view.initialize()
task_and_nomination_views = (
foo_bugtasks_and_nominations_view.getBugTaskAndNominationViews())
actual_results = []
for task_or_nomination_view in task_and_nomination_views:
task_or_nomination = task_or_nomination_view.context
actual_results.append((
self._get_object_type(task_or_nomination),
task_or_nomination.status.title,
task_or_nomination.target.bugtargetdisplayname))
# Only the one active project's task should be listed.
self.assertEqual([("bugtask", "New", "Foo")], actual_results)
def test_listing_with_no_bugtasks(self):
# Test the situation when there are no bugtasks to show.
product_foo = self.factory.makeProduct(name="foo")
foo_bug = self.factory.makeBug(product=product_foo)
removeSecurityProxy(product_foo).active = False
request = LaunchpadTestRequest()
foo_bugtasks_and_nominations_view = getMultiAdapter(
(foo_bug, request), name="+bugtasks-and-nominations-table")
foo_bugtasks_and_nominations_view.initialize()
task_and_nomination_views = (
foo_bugtasks_and_nominations_view.getBugTaskAndNominationViews())
self.assertEqual([], task_and_nomination_views)
def test_bugtarget_parent_shown_for_orphaned_series_tasks(self):
# Test that a row is shown for the parent of a series task, even
# if the parent doesn't actually have a task.
series = self.factory.makeProductSeries()
bug = self.factory.makeBug(series=series)
self.assertEqual(2, len(bug.bugtasks))
new_prod = self.factory.makeProduct()
bug.getBugTask(series.product).transitionToTarget(new_prod)
view = create_initialized_view(bug, "+bugtasks-and-nominations-table")
subviews = view.getBugTaskAndNominationViews()
self.assertEqual([
(series.product, '+bugtasks-and-nominations-table-row'),
(bug.getBugTask(series), '+bugtasks-and-nominations-table-row'),
(bug.getBugTask(new_prod), '+bugtasks-and-nominations-table-row'),
], [(v.context, v.__name__) for v in subviews])
content = subviews[0]()
self.assertIn(
'href="%s"' % canonical_url(
series.product, path_only_if_possible=True),
content)
self.assertIn(series.product.displayname, content)
class TestBugTaskEditViewStatusField(TestCaseWithFactory):
"""We show only those options as possible value in the status
field that the user can select.
"""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestBugTaskEditViewStatusField, self).setUp()
product_owner = self.factory.makePerson(name='product-owner')
bug_supervisor = self.factory.makePerson(name='bug-supervisor')
product = self.factory.makeProduct(
owner=product_owner, bug_supervisor=bug_supervisor)
self.bug = self.factory.makeBug(product=product)
def getWidgetOptionTitles(self, widget):
"""Return the titles of options of the given choice widget."""
return [
item.value.title for item in widget.field.vocabulary]
def test_status_field_items_for_anonymous(self):
# Anonymous users see only the current value.
login(ANONYMOUS)
view = BugTaskEditView(
self.bug.default_bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
['New'], self.getWidgetOptionTitles(view.form_fields['status']))
def test_status_field_items_for_ordinary_users(self):
# Ordinary users can set the status to all values except Won't fix,
# Expired, Triaged, Unknown.
login(NO_PRIVILEGE_EMAIL)
view = BugTaskEditView(
self.bug.default_bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
['New', 'Incomplete', 'Opinion', 'Invalid', 'Confirmed',
'In Progress', 'Fix Committed', 'Fix Released'],
self.getWidgetOptionTitles(view.form_fields['status']))
def test_status_field_privileged_persons(self):
# The bug target owner and the bug target supervisor can set
# the status to any value except Unknown and Expired.
for user in (
self.bug.default_bugtask.pillar.owner,
self.bug.default_bugtask.pillar.bug_supervisor):
login_person(user)
view = BugTaskEditView(
self.bug.default_bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
['New', 'Incomplete', 'Opinion', 'Invalid', "Won't Fix",
'Confirmed', 'Triaged', 'In Progress', 'Fix Committed',
'Fix Released'],
self.getWidgetOptionTitles(view.form_fields['status']),
'Unexpected set of settable status options for %s'
% user.name)
def test_status_field_bug_task_in_status_unknown(self):
# If a bugtask has the status Unknown, this status is included
# in the options.
owner = self.bug.default_bugtask.pillar.owner
login_person(owner)
self.bug.default_bugtask.transitionToStatus(
BugTaskStatus.UNKNOWN, owner)
login(NO_PRIVILEGE_EMAIL)
view = BugTaskEditView(
self.bug.default_bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
['New', 'Incomplete', 'Opinion', 'Invalid', 'Confirmed',
'In Progress', 'Fix Committed', 'Fix Released', 'Unknown'],
self.getWidgetOptionTitles(view.form_fields['status']))
def test_status_field_bug_task_in_status_expired(self):
# If a bugtask has the status Expired, this status is included
# in the options.
removeSecurityProxy(self.bug.default_bugtask).status = (
BugTaskStatus.EXPIRED)
login(NO_PRIVILEGE_EMAIL)
view = BugTaskEditView(
self.bug.default_bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
['New', 'Incomplete', 'Opinion', 'Invalid', 'Expired',
'Confirmed', 'In Progress', 'Fix Committed', 'Fix Released'],
self.getWidgetOptionTitles(view.form_fields['status']))
class TestBugTaskEditViewAssigneeField(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestBugTaskEditViewAssigneeField, self).setUp()
self.owner = self.factory.makePerson()
self.product = self.factory.makeProduct(owner=self.owner)
self.bugtask = self.factory.makeBug(
product=self.product).default_bugtask
def test_assignee_vocabulary_regular_user_with_bug_supervisor(self):
# For regular users, the assignee vocabulary is
# AllUserTeamsParticipation if there is a bug supervisor defined.
login_person(self.owner)
self.product.setBugSupervisor(self.owner, self.owner)
login(USER_EMAIL)
view = BugTaskEditView(self.bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
'AllUserTeamsParticipation',
view.form_fields['assignee'].field.vocabularyName)
def test_assignee_vocabulary_regular_user_without_bug_supervisor(self):
# For regular users, the assignee vocabulary is
# ValidAssignee is there is not a bug supervisor defined.
login_person(self.owner)
self.product.setBugSupervisor(None, self.owner)
login(USER_EMAIL)
view = BugTaskEditView(self.bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
'ValidAssignee',
view.form_fields['assignee'].field.vocabularyName)
def test_assignee_field_vocabulary_privileged_user(self):
# Privileged users, like the bug task target owner, can
# assign anybody.
login_person(self.bugtask.target.owner)
view = BugTaskEditView(self.bugtask, LaunchpadTestRequest())
view.initialize()
self.assertEqual(
'ValidAssignee',
view.form_fields['assignee'].field.vocabularyName)
class TestBugTaskEditView(TestCaseWithFactory):
"""Test the bug task edit form."""
layer = DatabaseFunctionalLayer
def test_retarget_already_exists_error(self):
user = self.factory.makePerson()
login_person(user)
ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
dsp_1 = self.factory.makeDistributionSourcePackage(
distribution=ubuntu, sourcepackagename='mouse')
self.factory.makeSourcePackagePublishingHistory(
distroseries=ubuntu.currentseries,
sourcepackagename=dsp_1.sourcepackagename)
bug_task_1 = self.factory.makeBugTask(target=dsp_1)
dsp_2 = self.factory.makeDistributionSourcePackage(
distribution=ubuntu, sourcepackagename='rabbit')
self.factory.makeSourcePackagePublishingHistory(
distroseries=ubuntu.currentseries,
sourcepackagename=dsp_2.sourcepackagename)
bug_task_2 = self.factory.makeBugTask(
bug=bug_task_1.bug, target=dsp_2)
form = {
'ubuntu_rabbit.actions.save': 'Save Changes',
'ubuntu_rabbit.status': 'In Progress',
'ubuntu_rabbit.importance': 'High',
'ubuntu_rabbit.assignee.option':
'ubuntu_rabbit.assignee.assign_to_nobody',
'ubuntu_rabbit.sourcepackagename': 'mouse',
}
view = create_initialized_view(
bug_task_2, name='+editstatus', form=form, principal=user)
self.assertEqual(1, len(view.errors))
self.assertEqual(
'A fix for this bug has already been requested for mouse in '
'Ubuntu',
view.errors[0])
def setUpRetargetMilestone(self):
"""Setup a bugtask with a milestone and a product to retarget to."""
first_product = self.factory.makeProduct(name='bunny')
with person_logged_in(first_product.owner):
first_product.official_malone = True
bug = self.factory.makeBug(product=first_product)
bug_task = bug.bugtasks[0]
milestone = self.factory.makeMilestone(
productseries=first_product.development_focus, name='1.0')
bug_task.transitionToMilestone(milestone, first_product.owner)
second_product = self.factory.makeProduct(name='duck')
with person_logged_in(second_product.owner):
second_product.official_malone = True
return bug_task, second_product
def test_retarget_product_with_milestone(self):
# Milestones are always cleared when retargeting a product bug task.
bug_task, second_product = self.setUpRetargetMilestone()
user = self.factory.makePerson()
login_person(user)
form = {
'bunny.status': 'In Progress',
'bunny.assignee.option': 'bunny.assignee.assign_to_nobody',
'bunny.product': 'duck',
'bunny.actions.save': 'Save Changes',
}
view = create_initialized_view(
bug_task, name='+editstatus', form=form)
self.assertEqual([], view.errors)
self.assertEqual(second_product, bug_task.target)
self.assertEqual(None, bug_task.milestone)
notifications = view.request.response.notifications
self.assertEqual(1, len(notifications))
expected = ('The Bunny 1.0 milestone setting has been removed')
self.assertTrue(notifications.pop().message.startswith(expected))
def test_retarget_product_and_assign_milestone(self):
# Milestones are always cleared when retargeting a product bug task.
bug_task, second_product = self.setUpRetargetMilestone()
login_person(bug_task.target.owner)
milestone_id = bug_task.milestone.id
bug_task.transitionToMilestone(None, bug_task.target.owner)
form = {
'bunny.status': 'In Progress',
'bunny.assignee.option': 'bunny.assignee.assign_to_nobody',
'bunny.product': 'duck',
'bunny.milestone': milestone_id,
'bunny.actions.save': 'Save Changes',
}
view = create_initialized_view(
bug_task, name='+editstatus', form=form)
self.assertEqual([], view.errors)
self.assertEqual(second_product, bug_task.target)
self.assertEqual(None, bug_task.milestone)
notifications = view.request.response.notifications
self.assertEqual(1, len(notifications))
expected = ('The milestone setting was ignored')
self.assertTrue(notifications.pop().message.startswith(expected))
class TestProjectGroupBugs(TestCaseWithFactory):
"""Test the bugs overview page for Project Groups."""
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestProjectGroupBugs, self).setUp()
self.owner = self.factory.makePerson(name='bob')
self.projectgroup = self.factory.makeProject(name='container',
owner=self.owner)
def makeSubordinateProduct(self, tracks_bugs_in_lp):
"""Create a new product and add it to the project group."""
product = self.factory.makeProduct(official_malone=tracks_bugs_in_lp)
with person_logged_in(product.owner):
product.project = self.projectgroup
def test_empty_project_group(self):
# An empty project group does not use Launchpad for bugs.
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs')
self.assertFalse(self.projectgroup.hasProducts())
self.assertFalse(view.should_show_bug_information)
def test_project_group_with_subordinate_not_using_launchpad(self):
# A project group with all subordinates not using Launchpad
# will itself be marked as not using Launchpad for bugs.
self.makeSubordinateProduct(False)
self.assertTrue(self.projectgroup.hasProducts())
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs')
self.assertFalse(view.should_show_bug_information)
def test_project_group_with_subordinate_using_launchpad(self):
# A project group with one subordinate using Launchpad
# will itself be marked as using Launchpad for bugs.
self.makeSubordinateProduct(True)
self.assertTrue(self.projectgroup.hasProducts())
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs')
self.assertTrue(view.should_show_bug_information)
def test_project_group_with_mixed_subordinates(self):
# A project group with one or more subordinates using Launchpad
# will itself be marked as using Launchpad for bugs.
self.makeSubordinateProduct(False)
self.makeSubordinateProduct(True)
self.assertTrue(self.projectgroup.hasProducts())
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs')
self.assertTrue(view.should_show_bug_information)
def test_project_group_has_no_portlets_if_not_using_LP(self):
# A project group that has no projects using Launchpad will not have
# bug portlets.
self.makeSubordinateProduct(False)
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs',
current_request=True)
self.assertFalse(view.should_show_bug_information)
contents = view.render()
report_a_bug = find_tag_by_id(contents, 'bug-portlets')
self.assertIs(None, report_a_bug)
def test_project_group_has_portlets_link_if_using_LP(self):
# A project group that has projects using Launchpad will have a
# portlets.
self.makeSubordinateProduct(True)
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs',
current_request=True)
self.assertTrue(view.should_show_bug_information)
contents = view.render()
report_a_bug = find_tag_by_id(contents, 'bug-portlets')
self.assertIsNot(None, report_a_bug)
def test_project_group_has_help_link_if_not_using_LP(self):
# A project group that has no projects using Launchpad will have
# a 'Getting started' help link.
self.makeSubordinateProduct(False)
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs',
current_request=True)
contents = view.render()
help_link = find_tag_by_id(contents, 'getting-started-help')
self.assertIsNot(None, help_link)
def test_project_group_has_no_help_link_if_using_LP(self):
# A project group that has no projects using Launchpad will not have
# a 'Getting started' help link.
self.makeSubordinateProduct(True)
view = create_initialized_view(
self.projectgroup, name=u'+bugs', rootsite='bugs',
current_request=True)
contents = view.render()
help_link = find_tag_by_id(contents, 'getting-started-help')
self.assertIs(None, help_link)
class TestBugActivityItem(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setAttribute(self, obj, attribute, value):
obj_before_modification = Snapshot(obj, providing=providedBy(obj))
setattr(removeSecurityProxy(obj), attribute, value)
notify(ObjectModifiedEvent(
obj, obj_before_modification, [attribute],
self.factory.makePerson()))
def test_escapes_assignee(self):
with celebrity_logged_in('admin'):
task = self.factory.makeBugTask()
self.setAttribute(
task, 'assignee',
self.factory.makePerson(displayname="Foo &<>", name='foo'))
self.assertEquals(
"nobody → Foo &<> (foo)",
BugActivityItem(task.bug.activity[-1]).change_details)
def test_escapes_title(self):
with celebrity_logged_in('admin'):
bug = self.factory.makeBug(title="foo")
self.setAttribute(bug, 'title', "bar &<>")
self.assertEquals(
"- foo<br />+ bar &<>",
BugActivityItem(bug.activity[-1]).change_details)
|