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
|
Poll views
----------
The polls portlet shows the state of current polls, and links to past
polls.
>>> from canonical.launchpad.testing.pages import extract_text
>>> from datetime import timedelta
>>> user = factory.makePerson()
>>> team = factory.makeTeam(name='team')
>>> owner = team.teamowner
>>> def create_team_view(team, name=None, principal=None):
... # XRDS inheritance requires a lot of setup.
... path_info = '/~%s' % team.name
... server_url = 'http://launchpad.dev'
... view = create_view(
... team, name=name, principal=principal,
... server_url=server_url, path_info=path_info)
... view.initialize()
... return view
The portlet does not render any markup when there are no polls...
>>> login_person(user)
>>> view = create_team_view(team, name='+portlet-polls', principal=user)
>>> view.has_current_polls
False
>>> view.should_show_polls_portlet
False
>>> print extract_text(view.render())
<BLANKLINE>
Unless the user is a team owner.
>>> login_person(owner)
>>> view = create_team_view(team, name='+portlet-polls', principal=owner)
>>> view.has_current_polls
False
>>> view.should_show_polls_portlet
True
>>> print extract_text(view.render())
Polls
No current polls.
Show polls
Create a poll
The portlet shows a link to polls to all users when there is a poll, but it
has not opened.
>>> from lp.registry.interfaces.poll import IPollSubset, PollSecrecy
>>> from lp.services.utils import utc_now
>>> open_date = utc_now() + timedelta(hours=6)
>>> close_date = open_date + timedelta(weeks=1)
>>> poll_subset = IPollSubset(team)
>>> poll = poll_subset.new(
... 'name', 'title', 'proposition', open_date, close_date,
... PollSecrecy.OPEN, False)
>>> login_person(user)
>>> view = create_team_view(team, name='+portlet-polls', principal=user)
>>> view.has_current_polls
True
>>> view.should_show_polls_portlet
True
>>> print extract_text(view.render())
Polls
Show polls
The portlet shows more details to the poll owner.
>>> login_person(owner)
>>> view = create_team_view(team, name='+portlet-polls', principal=owner)
>>> view.has_current_polls
True
>>> view.should_show_polls_portlet
True
>>> print extract_text(view.render())
Polls
title - opens in 5 hours
Show polls
Create a poll
Current polls are listed in the portlet, the only difference between a user
and an owner is the owner has a link to create more polls.
>>> poll.dateopens = open_date - timedelta(weeks=2)
>>> login_person(user)
>>> view = create_team_view(team, name='+portlet-polls', principal=user)
>>> print extract_text(view.render())
Polls
title - closes on ...
You have 7 days left to vote in this poll.
Show polls
>>> login_person(owner)
>>> view = create_team_view(team, name='+portlet-polls', principal=owner)
>>> print extract_text(view.render())
Polls
title - closes on ...
You have 7 days left to vote in this poll.
Show polls
Create a poll
When all the polls are closed, the portlet states the case and has a link to
see the polls.
>>> poll.datecloses = close_date - timedelta(weeks=2)
>>> login_person(user)
>>> view = create_team_view(team, name='+portlet-polls', principal=user)
>>> print extract_text(view.render())
Polls
No current polls.
Show polls
>>> login_person(owner)
>>> view = create_team_view(team, name='+portlet-polls', principal=owner)
>>> print extract_text(view.render())
Polls
No current polls.
Show polls
Create a poll
|