~launchpad-pqm/launchpad/devel

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
IStructuralSubscriptionTarget
-----------------------------

Let's subscribe ubuntu-team.

    >>> from lp.registry.interfaces.person import IPersonSet
    >>> personset = getUtility(IPersonSet)
    >>> ubuntu_team = personset.getByName("ubuntu-team")
    >>> no_priv = personset.getByName("no-priv")
    >>> foobar = personset.getByName("name16")
    >>> from canonical.launchpad.ftests import login
    >>> login("foo.bar@canonical.com")
    >>> target.addBugSubscription(ubuntu_team, foobar)
    <...StructuralSubscription ...>

We can add and remove these subscriptions.

    >>> def print_subscriptions_list(subscriptions):
    ...     for subscription in subscriptions:
    ...         print subscription.subscriber.name

    >>> subscription = target.addBugSubscription(foobar, foobar)
    >>> print_subscriptions_list(target.getSubscriptions())
    name16
    ubuntu-team
    >>> target.removeBugSubscription(foobar, foobar)
    >>> print_subscriptions_list(target.getSubscriptions())
    ubuntu-team

To get a user's subscription to the target, use
IStructuralSubscriptionTarget.getSubscription.

    >>> target.getSubscription(ubuntu_team)
    <...StructuralSubscription ...>
    >>> print target.getSubscription(no_priv)
    None

To search for all subscriptions on a structure we use getSubscriptions.

    >>> print_subscriptions_list(target.bug_subscriptions)
    ubuntu-team
    >>> subscription = target.addSubscription(no_priv, no_priv)
    >>> print_subscriptions_list(target.bug_subscriptions)
    no-priv
    ubuntu-team


Structural subscriptions and indirect bug subscriptions
=======================================================

    >>> bug = filebug(target, 'test bug one')
    >>> indirect_subscribers = set(
    ...     subscriber.name for subscriber in bug.getIndirectSubscribers())
    >>> structural_subscribers = set(
    ...     sub.subscriber.name for sub in target.bug_subscriptions)
    >>> structural_subscribers.difference(indirect_subscribers)
    set([])