3
A poll can have any number of options, but these must be created
4
before the poll has opened.
6
First we create a new poll to use throughout this test.
8
>>> login('jeff.waugh@ubuntulinux.com')
9
>>> from zope.component import getUtility
10
>>> from lp.registry.interfaces.person import IPersonSet
11
>>> factory.makePoll(getUtility(IPersonSet).getByName('ubuntu-team'),
12
... 'dpl-2080', 'dpl-2080', 'dpl-2080')
16
Our poll is not yet open, so new options can be added to it.
18
>>> team_admin_browser = setupBrowser(
19
... auth='Basic jeff.waugh@ubuntulinux.com:jdub')
20
>>> team_admin_browser.open(
21
... 'http://launchpad.dev/~ubuntu-team/+poll/dpl-2080')
22
>>> team_admin_browser.getLink('Add new option').click()
23
>>> team_admin_browser.url
24
'http://launchpad.dev/~ubuntu-team/+poll/dpl-2080/+newoption'
27
... 'bill-amazingly-huge-middle-name-almost-impossible-to-read-graham')
28
>>> team_admin_browser.getControl('Name').value = bill_name
29
>>> team_admin_browser.getControl('Title').value = 'Bill Graham'
30
>>> team_admin_browser.getControl('Create').click()
32
After adding an options we're taken back to the poll's home page.
34
>>> team_admin_browser.url
35
'http://launchpad.dev/~ubuntu-team/+poll/dpl-2080'
37
And here we see the option listed as one of the active options for this
40
>>> print extract_text(
41
... find_tag_by_id(team_admin_browser.contents, 'options'))
43
bill... Bill Graham Yes
45
If we try to add a new option without providing a title, we'll get an error
46
message because the title is required.
48
>>> team_admin_browser.getLink('Add new option').click()
49
>>> team_admin_browser.url
50
'http://launchpad.dev/~ubuntu-team/+poll/dpl-2080/+newoption'
53
... 'will-amazingly-huge-middle-name-almost-impossible-to-read-graham')
54
>>> team_admin_browser.getControl('Name').value = will_name
55
>>> team_admin_browser.getControl('Title').value = ''
56
>>> team_admin_browser.getControl('Create').click()
58
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
60
Required input is missing.
62
If we try to add a new option with the same name of a existing option, we
63
should get a nice error message
65
>>> team_admin_browser.getControl('Name').value = bill_name
66
>>> team_admin_browser.getControl('Title').value = 'Bill Again'
67
>>> team_admin_browser.getControl('Create').click()
69
>>> print "\n".join(get_feedback_messages(team_admin_browser.contents))
71
...is already in use by another option in this poll.
73
It's not possible to add/edit a poll option after a poll is open or closed.
74
That's only possible when the poll is not yet open.
76
>>> team_admin_browser.open(
77
... 'http://launchpad.dev/~ubuntu-team/+poll/director-2004/+newoption')
79
>>> "\n".join(get_feedback_messages(team_admin_browser.contents))
80
u'You can’t add new options because the poll is already closed.'
82
>>> team_admin_browser.open(
83
... 'http://launchpad.dev/~ubuntu-team/+poll/never-closes/+newoption')
84
>>> "\n".join(get_feedback_messages(team_admin_browser.contents))
85
u'You can’t add new options because the poll is already open.'