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
|
Let's first setup some objects that we'll need.
>>> no_priv_browser = setupBrowser(
... auth='Basic no-priv@canonical.com:test')
>>> team_admin_browser = setupBrowser(
... 'Basic jeff.waugh@ubuntulinux.com:jdub')
If you're not logged in and go to the +polls page of the "Ubuntu Team"
you'll see a link to login as a team administrator.
>>> anon_browser.open('http://launchpad.dev/~ubuntu-team')
>>> anon_browser.getLink('Show polls').click()
>>> anon_browser.url
'http://launchpad.dev/~ubuntu-team/+polls'
>>> anon_browser.getLink('Log in as an admin to set up a new poll').url
'http://launchpad.dev/~ubuntu-team/+login'
Try to create a new poll logged in as 'no-priv', which is not a team
administrator. There's no link leading to the +newpoll page, but the user can
easily guess it.
>>> no_priv_browser.open('http://launchpad.dev/~ubuntu-team/+newpoll')
Traceback (most recent call last):
...
Unauthorized:...
Now we're logged in as Jeff Waugh which is a team administrator and thus can
create a new poll.
>>> team_admin_browser.open('http://launchpad.dev/~ubuntu-team')
>>> team_admin_browser.getLink('Show polls').click()
>>> team_admin_browser.getLink('Set up a new poll').click()
>>> team_admin_browser.url
'http://launchpad.dev/~ubuntu-team/+newpoll'
>>> team_admin_browser.title
'New poll : ...'
First we try to create a poll with a invalid name to
test the name field validator.
>>> team_admin_browser.getControl(
... 'The unique name of this poll').value = 'election_2100'
>>> team_admin_browser.getControl(
... 'The title of this poll').value = 'Presidential Election 2100'
>>> proposition = 'Who is going to be the next president?'
>>> team_admin_browser.getControl(
... 'The proposition that is going to be voted').value = proposition
>>> team_admin_browser.getControl(
... 'Users can spoil their votes?').selected = True
>>> team_admin_browser.getControl(
... name='field.dateopens').value = '2100-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl(
... name='field.datecloses').value = '2100-07-04 02:00:00+00:00'
>>> team_admin_browser.getControl('Continue').click()
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
There is 1 error.
Invalid name 'election_2100'. Names must be at least two characters ...
We fix the name, but swap the dates. Again a nice error message.
>>> team_admin_browser.getControl(
... 'The unique name of this poll').value = 'election-2100'
>>> team_admin_browser.getControl(
... name='field.dateopens').value = '2100-07-04 02:00:00+00:00'
>>> team_admin_browser.getControl(
... name='field.datecloses').value = '2100-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl('Continue').click()
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
There is 1 error.
A poll cannot close at the time (or before) it opens.
Now we get it right.
>>> team_admin_browser.getControl(
... name='field.dateopens').value = '2100-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl(
... name='field.datecloses').value = '2100-07-04 02:00:00+00:00'
>>> team_admin_browser.getControl('Continue').click()
We're redirected to the newly created poll page.
>>> team_admin_browser.url
'http://launchpad.dev/~ubuntu-team/+poll/election-2100'
Create a new poll that starts in 2025-06-04 and will last until 2035.
>>> team_admin_browser.open(
... 'http://launchpad.dev/~ubuntu-team/+newpoll')
>>> team_admin_browser.getControl(
... "The unique name of this poll").value = 'dpl-2080'
>>> title_control = team_admin_browser.getControl(
... "The title of this poll")
>>> title_control.value = "Debian Project Leader Election 2080"
>>> proposition = "The next debian project leader"
>>> team_admin_browser.getControl(
... "The proposition that is going to be voted").value = proposition
>>> team_admin_browser.getControl(
... "Users can spoil their votes?").selected = True
>>> team_admin_browser.getControl(
... name='field.dateopens').value = '2025-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl(
... name='field.datecloses').value = '2035-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl('Continue').click()
We're redirected to the newly created poll
>>> team_admin_browser.url
'http://launchpad.dev/~ubuntu-team/+poll/dpl-2080'
>>> team_admin_browser.title
'Debian Project Leader Election 2080 : \xe2\x80\x9cUbuntu Team\xe2\x80\x9d team'
>>> print_location(team_admin_browser.contents)
Hierarchy: ?Ubuntu Team? team > Debian Project Leader Election 2080
Tabs:
* Overview (selected) - http://launchpad.dev/~ubuntu-team
* Code - http://code.launchpad.dev/~ubuntu-team
* Bugs - http://bugs.launchpad.dev/~ubuntu-team
* Blueprints - http://blueprints.launchpad.dev/~ubuntu-team
* Translations - http://translations.launchpad.dev/~ubuntu-team
* Answers - http://answers.launchpad.dev/~ubuntu-team
Main heading: Debian Project Leader Election 2080
>>> team_admin_browser.getLink('add an option').url
'http://launchpad.dev/%7Eubuntu-team/+poll/dpl-2080/+newoption'
Now lets try to insert a poll with the name of a existing one.
# XXX matsubara 2006-07-17 bug=53302:
# There's no link to get back to +polls.
>>> team_admin_browser.open(
... 'http://launchpad.dev/~ubuntu-team/+newpoll')
>>> team_admin_browser.getControl(
... "The unique name of this poll").value = 'dpl-2080'
>>> title_control = team_admin_browser.getControl(
... "The title of this poll")
>>> title_control.value = "Debian Project Leader Election 2080"
>>> proposition = "The next debian project leader"
>>> team_admin_browser.getControl(
... "The proposition that is going to be voted").value = proposition
>>> team_admin_browser.getControl(
... "Users can spoil their votes?").selected = True
>>> team_admin_browser.getControl(
... name='field.dateopens').value = '2025-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl(
... name='field.datecloses').value = '2035-06-04 02:00:00+00:00'
>>> team_admin_browser.getControl('Continue').click()
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
There is 1 error.
dpl-2080 is already in use by another poll in this team.
When creating a new poll, its start date must be at least 12 hours from
now, so that the user creating it has a chance to add some options before
the poll opens -- at that point new options cannot be added.
>>> team_admin_browser.getControl('The unique name').value = 'today'
>>> from datetime import datetime
>>> today = datetime.today().strftime('%Y-%m-%d')
>>> team_admin_browser.getControl(name='field.dateopens').value = today
>>> team_admin_browser.getControl('Continue').click()
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
There is 1 error.
A poll cannot open less than 12 hours after it's created.
|