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.