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
|
= Joining a Team =
Tests for the team '+join' page's raw view objects.
== Joining and Subscribing to the List ==
>>> from lp.registry.interfaces.person import IPersonSet
>>> personset = getUtility(IPersonSet)
# Set up a harness to make form submission testing easier.
>>> from zope.component import getMultiAdapter
>>> from lp.services.webapp.servers import LaunchpadTestRequest
>>> def join_team(team):
... form = {'field.actions.join': '1', 'field.mailinglist_subscribe': u'on'}
... request = LaunchpadTestRequest(method='POST', form=form)
... view = getMultiAdapter((team, request), name='+join')
... view.initialize()
... for notification in request.notifications:
... print notification.message
# Define a helper for creating teams with a specific subscription
# policy.
>>> from lp.registry.tests.mailinglists_helper import (
... new_list_for_team)
>>> from lp.registry.interfaces.person import TeamSubscriptionPolicy
>>> def make_team(teamname, subscription_policy):
... creator = personset.getByName('no-priv')
... team = personset.newTeam(creator, teamname, teamname,
... subscriptionpolicy=subscription_policy)
... return team
>>> from lp.registry.interfaces.mailinglist import IMailingListSet
>>> subscribers = getUtility(IMailingListSet)
Attempting to post a mailing list subscription request to a team that has no list
is thwarted by the view because it strips the checkbox from the form.
Therefore no error message is seen.
>>> sample_person = personset.getByName('name12')
>>> login_person(sample_person)
>>> no_list_team = make_team(
... 'open-team-no-list', TeamSubscriptionPolicy.OPEN)
>>> join_team(no_list_team)
You have successfully joined open-team-no-list.
Someone subscribing to a moderated team's list will be shown an
informative message regarding the delayed subscription.
>>> moderated_team = make_team(
... 'moderated-team-with-list',
... TeamSubscriptionPolicy.MODERATED)
>>> moderated_list = new_list_for_team(moderated_team)
>>> join_team(moderated_team)
Your request to join moderated-team-with-list is awaiting approval.
Your mailing list subscription is awaiting approval.
>>> sorted(email.email for email in
... moderated_list.getSubscribedAddresses())
[]
# The subscription object is in the database, waiting for the
# team membership approval.
>>> moderated_list.getSubscription(sample_person)
<MailingListSubscription ...>
Users joining an open team will be immediately subscribed to the
team's list.
>>> open_team = make_team(
... 'open-team-with-list', TeamSubscriptionPolicy.OPEN)
>>> open_list = new_list_for_team(open_team)
>>> join_team(open_team)
You have successfully joined open-team-with-list.
You have been subscribed to this team’s mailing list.
>>> sorted(email.email for email in
... open_list.getSubscribedAddresses())
[u'test@canonical.com']
|