6
from django.conf import settings
7
from canonical.isd.tests.sst import mail
8
from sst.actions import *
11
def register_account(email_address, displayname="My Name",
12
password="Admin007", fetch_email=True, verify=True):
13
"""Register an account and verify the token by default."""
15
go_to('/+new_account')
16
wait_for(assert_title, 'Create account')
17
write_textfield('id_displayname', displayname)
18
write_textfield('id_email', email_address)
19
write_textfield('id_password', password)
20
write_textfield('id_passwordconfirm', password)
21
# Even though the recaptcha field is ignored for our tests, we do
22
# want to verify that it is on the page.
23
write_textfield('recaptcha_response_field', 'ignored')
24
click_button(get_element(name='continue'))
25
wait_for(assert_url, '/+email-sent')
27
vcode = get_verification_code_for_address(email_address)
29
write_textfield(get_element(name='confirmation_code'), vcode)
30
click_button(get_element(css_class='btn'))
34
def add_email(address, verify=False):
36
wait_for(assert_title_contains, "'s email addresses")
37
write_textfield('id_newemail', address)
38
click_button(get_element(name='continue'))
39
code = get_verification_code_for_address(address)
41
go_to('/+enter_token')
42
wait_for(write_textfield, 'id_confirmation_code', code)
43
write_textfield('id_email', address)
44
click_button(get_element(name='continue'))
45
assert_title('Complete email address validation')
46
click_button(get_element(name='continue'))
52
remove_link = get_element(tag='a', text='Remove')
53
click_link(remove_link)
54
confirm_button = get_element(tag='button', text='Yes, remove')
55
click_button(confirm_button)
58
def try_to_validate_email(address, code):
59
go_to('/+enter_token')
60
wait_for(write_textfield, 'id_confirmation_code', code)
61
write_textfield('id_email', address)
62
click_button(get_element(name='continue'))
65
def login(email, password):
67
write_textfield('id_email', email)
68
write_textfield('id_password', password)
69
click_button(get_element(name='continue'))
73
go_to('%s/+logout' % get_base_url())
76
def _get_verification_data_for_address(email_address):
77
"""A private helper for public helpers below.
79
Note: We have two different public helpers here for verification
80
code and link so that functional tests don't need to deal with
82
vcode, ignored = get_verification_for_address(email_address).
84
email_msg = mail.get_latest_email_sent_to(email_address)
87
# The body is encoded as quoted-printable. This affects any line longer
88
# than a certain length. Decode now to not have to worry about it in
90
body = quopri.decodestring(email_msg.get_payload())
92
'Here is your confirmation code:(.*)(Enter|If you made)',
95
vcode = match.group(1).strip()
98
"No verification code found in email.")
100
'confirm your (?:account|email address|reset):(.*)If',
103
link = match.group(1).strip()
105
raise AssertionError(
106
"No verification link found in email.")
110
def get_verification_code_for_address(email_address):
111
print("Retrieving verification code for %s." % email_address)
112
vcode, link = _get_verification_data_for_address(email_address)
113
print("Verification code retrieved: %s." % vcode)
117
def get_verification_link_for_address(email_address):
118
print("Retrieving verification link for %s." % email_address)
119
vcode, link = _get_verification_data_for_address(email_address)
120
print("Verification link retrieved: %s." % link)
124
def request_password_reset(email_address):
126
go_to('/+forgot_password')
127
write_textfield('id_email', email_address)
128
# Even though the recaptcha field is ignored for our tests, we do
129
# want to verify that it is on the page.
130
write_textfield('recaptcha_response_field', 'ignored')
131
click_button(get_element(name='continue'))
134
def login_to_test_account():
135
from sst import actions
137
login(settings.TEST_ACCOUNT_EMAIL, settings.TEST_ACCOUNT_PASSWORD)
138
# Wait for the reload
139
wait_for(exists_element, id='ubuntu-header')
141
if exists_element(tag='span', css_class='error', text="Password didn't match."):
142
if get_base_url() == 'https://login.ubuntu.com/':
143
actions._raise("This test requires a test account to be present")
145
register_account(settings.TEST_ACCOUNT_EMAIL, "Test Account",
146
settings.TEST_ACCOUNT_PASSWORD)
149
def login_from_redirect(email=settings.QA_ACCOUNT_EMAIL,
150
password=settings.QA_ACCOUNT_PASSWORD):
151
wait_for(assert_title, 'Log in')
152
write_textfield('id_email', email)
153
write_textfield('id_password', password)
154
click_button(get_element(name='continue'))
155
wait_for(assert_title_contains, 'Authenticate to')
156
click_button(get_element(name='yes'))