~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/structural-subscription-target.txt

[r=deryck][ui=none][bug=556489] If a distribution has a bug
        supervisor set,
        only allow the bug supervisor or members of that team to subscribe to
        all of the distribution's bug reports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
= IStructuralSubscriptionTarget =
2
2
 
3
 
Structural subscriptions allow users to subscribe to notifications about
4
 
new items and changes to existing items for a Launchpad structure such as
5
 
Product, ProjectGroup, Distribution, Milestone and series.
6
 
 
7
 
    >>> from canonical.launchpad.interfaces import (
8
 
    ...     IStructuralSubscriptionTarget)
9
 
    >>> from canonical.launchpad.webapp.testing import verifyObject
10
 
    >>> verifyObject(IStructuralSubscriptionTarget, target)
11
 
    True
12
 
 
13
 
== Bug Subscriptions ==
14
 
 
15
 
Bug subscriptions are structural subscriptions to notifications about
16
 
bug activity.
17
 
 
18
 
    >>> target.bug_subscriptions
19
 
    []
20
 
 
21
 
First, we try to create a new subscription.
 
3
 
 
4
Let's subscribe ubuntu-team.
22
5
 
23
6
    >>> from canonical.launchpad.interfaces import IPersonSet
24
7
    >>> personset = getUtility(IPersonSet)
 
8
    >>> ubuntu_team = personset.getByName("ubuntu-team")
25
9
    >>> no_priv = personset.getByName("no-priv")
26
 
 
27
 
Only authenticated users can create subscriptions.
28
 
 
29
 
    >>> target.addBugSubscription(no_priv, no_priv)
30
 
    Traceback (most recent call last):
31
 
      ...
32
 
    Unauthorized: ...
33
 
 
34
 
Let's login then to add a subscription:
35
 
 
 
10
    >>> foobar = personset.getByName("name16")
36
11
    >>> from canonical.launchpad.ftests import login
37
12
    >>> login("foo.bar@canonical.com")
38
 
 
39
 
    >>> target.addBugSubscription(no_priv, no_priv)
40
 
    <StructuralSubscription ...>
41
 
    >>> [sub.subscriber.name for sub in target.bug_subscriptions]
42
 
    [u'no-priv']
43
 
 
44
 
Trying to add a subscription to a target when that person
45
 
or team is already subscribed to that target will return
46
 
the existing subscription.
47
 
 
48
 
    >>> target.addBugSubscription(no_priv, no_priv)
49
 
    <StructuralSubscription ...>
50
 
 
51
 
People can only be subscribed by themselves, and only the team admins may
52
 
subscribe a team.
53
 
 
54
 
no-priv, who has no relationship to ubuntu-team, cannot subscribe it.
55
 
 
56
 
    >>> ubuntu_team = personset.getByName("ubuntu-team")
57
 
    >>> target.addBugSubscription(ubuntu_team, no_priv)
58
 
    Traceback (most recent call last):
59
 
      ...
60
 
    UserCannotSubscribePerson: no-priv does not have permission to subscribe ubuntu-team.
61
 
 
62
 
But kamion, an admin of the team, can.
63
 
 
64
 
    >>> kamion = personset.getByName("kamion")
65
 
    >>> target.addBugSubscription(ubuntu_team, kamion)
66
 
    <StructuralSubscription ...>
67
 
 
68
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
69
 
    [u'no-priv', u'ubuntu-team']
70
 
 
71
 
foobar, a Launchpad administrator, can as well.
72
 
 
73
 
    >>> foobar = personset.getByName("name16")
74
 
    >>> target.addBugSubscription(ubuntu_team, foobar)
75
 
    <StructuralSubscription ...>
76
 
 
77
 
A non-admin cannot subscribe a person other than themselves.
78
 
 
79
 
    >>> target.addBugSubscription(kamion, no_priv)
80
 
    Traceback (most recent call last):
81
 
      ...
82
 
    UserCannotSubscribePerson: no-priv does not have permission to subscribe kamion.
83
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
84
 
    [u'no-priv', u'ubuntu-team']
85
 
 
86
 
But again, an admin can.
87
 
 
88
 
    >>> target.addBugSubscription(kamion, foobar)
89
 
    <StructuralSubscription ...>
90
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
91
 
    [u'kamion', u'no-priv', u'ubuntu-team']
92
 
 
93
 
To remove a bug subscription, use
94
 
IStructuralSubscriptionTarget.removeBugSubscription:
95
 
 
96
 
    >>> target.removeBugSubscription(no_priv, no_priv)
97
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
98
 
    [u'kamion', u'ubuntu-team']
99
 
 
100
 
The subscription rules apply to unsubscription as well.
101
 
 
102
 
An unprivileged user cannot unsubscribe a team.
103
 
 
104
 
    >>> target.removeBugSubscription(ubuntu_team, no_priv)
105
 
    Traceback (most recent call last):
106
 
      ...
107
 
    UserCannotSubscribePerson: no-priv does not have permission to unsubscribe ubuntu-team.
108
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
109
 
    [u'kamion', u'ubuntu-team']
110
 
 
111
 
But a team admin can.
112
 
 
113
 
    >>> target.removeBugSubscription(ubuntu_team, kamion)
114
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
115
 
    [u'kamion']
116
 
 
117
 
An unprivileged user also cannot unsubscribe another user.
118
 
 
119
 
    >>> target.removeBugSubscription(kamion, no_priv)
120
 
    Traceback (most recent call last):
121
 
      ...
122
 
    UserCannotSubscribePerson: no-priv does not have permission to unsubscribe kamion.
123
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
124
 
    [u'kamion']
125
 
 
126
 
But the user themselves can.
127
 
 
128
 
    >>> target.removeBugSubscription(kamion, kamion)
129
 
    >>> sorted([sub.subscriber.name for sub in target.bug_subscriptions])
130
 
    []
131
 
 
132
 
Trying to remove a subscription that doesn't exist on a target raises a
133
 
DeleteSubscriptionError.
134
 
 
135
 
    >>> target.removeBugSubscription(foobar, foobar)
136
 
    Traceback (most recent call last):
137
 
      ...
138
 
    DeleteSubscriptionError: ...
139
 
 
140
 
Let's subscribe ubuntu-team again.
141
 
 
142
13
    >>> target.addBugSubscription(ubuntu_team, foobar)
143
14
    <StructuralSubscription ...>
144
15
 
191
62
 
192
63
 
193
64
=== Structural subscriptions and indirect bug subscriptions ===
194
 
 
 
65
 
195
66
    >>> bug = filebug(target, 'test bug one')
196
67
    >>> indirect_subscribers = set(
197
68
    ...     subscriber.name for subscriber in bug.getIndirectSubscribers())