Пример #1
0
def fill_user_form(user, version=None):
    monkey_patch_sst()

    keys = user.keys()
    # for 1.8 and possibly lower, country needs to be filled before region_id
    # is a dropdown
    keys.sort()

    for key in keys:
        (vtype, value) = user[key]
        print 'fill', key, vtype, value
        try:
            el = a.get_element(id=key)
        except AssertionError:
            continue

        # before 1.9 region was a text field
        #if version < (1, 9, 0, 0) and key == 'region_id':
        #    el = a.get_element(id='region')
        #    a.write_textfield(el, value)
        if vtype == 'text':
            a.write_textfield(el, value)
        elif vtype == 'password':
            a.write_textfield(el, value, check=False)
        elif vtype == 'option':
            a.wait_for(a.assert_displayed, el)
            a.set_dropdown_value(el, value)
Пример #2
0
def check_2f_for_url(url):
    # are we redirected?
    go_to(url)
    wait_for(assert_title, 'Log in')
    login()
    go_to(url)
    # should be redirected
    assert_url('/two_factor_auth?next=%s' % quote(url))
    logout()
Пример #3
0
 def test_YUI3_unit_tests(self):
     # Load the page and then wait for #suite to contain
     # 'done'.  Read the results in '#test_results'.
     go_to(self.test_url)
     wait_for(assert_text, 'suite', 'done')
     results = json.loads(get_element(id='test_results').text)
     if results['failed'] != 0:
         message = '%d test(s) failed.\n\n%s' % (
             results['failed'], yui3.get_failed_tests_message(results))
         self.fail(message)
Пример #4
0
 def test_YUI3_unit_tests(self):
     # Load the page and then wait for #suite to contain
     # 'done'.  Read the results in '#test_results'.
     go_to(self.test_url)
     wait_for(assert_text, 'suite', 'done')
     results = json.loads(get_element(id='test_results').text)
     if results['failed'] != 0:
         message = '%d test(s) failed.\n\n%s' % (
             results['failed'], yui3.get_failed_tests_message(results))
         self.fail(message)
Пример #5
0
 def wait_for_product_saved(self):
     a.wait_for(a.get_element_by_xpath,
         "//div[@id='messages']//span[%s]"
         "|"
         "//div[@id='messages']//li[%s]" % (
         # 1.5 and higher
         xpath_contains_text('product has been saved'),
         # 1.4
         xpath_contains_text('Product was successfully saved.')),
     )
Пример #6
0
def login_to_test_account():
    from sst import actions

    login(settings.TEST_ACCOUNT_EMAIL, settings.TEST_ACCOUNT_PASSWORD)
    # Wait for the reload
    wait_for(exists_element, id='ubuntu-header')

    if exists_element(tag='span', css_class='error',
                      text="Password didn't match."):
        if is_production():
            actions._raise("This test requires a test account to be present")

        register_account(settings.TEST_ACCOUNT_EMAIL, "Test Account",
                         settings.TEST_ACCOUNT_PASSWORD)
Пример #7
0
def login_to_isdqa_account():
    from sst import actions

    global _LAST_EMAIL, _LAST_PASSWORD

    login(settings.SSO_TEST_ACCOUNT_EMAIL, settings.SSO_TEST_ACCOUNT_PASSWORD)
    # Wait for the reload
    wait_for(exists_element, id='ubuntu-header')

    if exists_element(tag='span', css_class='error',
                      text="Password didn't match."):
        actions._raise("This test requires a test account to be present")

    _LAST_EMAIL = settings.SSO_TEST_ACCOUNT_EMAIL
    _LAST_PASSWORD = settings.SSO_TEST_ACCOUNT_PASSWORD
Пример #8
0
def wait_click_url(ps=None, flash='#', attempts=10, index=0, element=None,
                   css_select=None, *args, **kwargs):
    """
    clicks url AND waits for url to change

    ps: logging message of your choosing
    type ps: string
    flash: accentuates your print statement in the console
    type flash: string
    index: will return the elment you specify by index
    type index: int
    attempts: number of tries, seperated by a 1 second sleep to get the elements
    type attempts: int
    xpath: an xpath like you would pass into get_element_by_xpath()
    type xpath: string
    css_select: a css selector like you would pass into get_element_by_css()
    type css_select: string
     *args, **kwargs: any element pair you would pass into get_element()
         e.g tag='some_tag_type', css_class='some_class_name'

    """
    chk_url = get_current_url()
    counter = 1
    while chk_url == get_current_url():
        if element:
            wait_for(click_element, element)
        elif css_select:
            try:
                wait_for(click_element, get_elements_by_css(css_select)[index])
            except Exception as e:
                if counter > 2:
                    test_print('ERROR: "{0}". Attempt {1} of {2}'.format(e, counter, attempts))
        else:
            try:
                wait_for(click_element, get_elements(*args, **kwargs)[index])
            except Exception as e:
                if counter > 2:
                    test_print('ERROR: "{0}". Attempt {1} of {2}'.format(e, counter, attempts))
        if counter == attempts:
            raise Exception('Error: The url did not change after {0} attempts'.format(attempts))
            break
        else:
            sleep(1)
        counter += 1
    if ps:
        test_print(ps, flash)
Пример #9
0
 def test_wait_for_returns_result_of_wrapped_call(self):
     actions.set_wait_timeout(0.3)
     self.assertEquals(actions.wait_for(lambda: 2), 2)
     self.assertEquals(actions.wait_for(lambda: True), True)
     self.assertRaises(AssertionError, actions.wait_for, lambda: None)
     self.assertRaises(AssertionError, actions.wait_for, lambda: False)
Пример #10
0
    skip_production,
)


config.set_base_url_from_env()
skip_production()

# XXX: skip if staging until the test can be made to reliably pass
if is_staging():
    skip()


resulting_teams = ast.literal_eval(resulting_teams)

go_to(urls.CONSUMER)
wait_for(assert_title, 'Django OpenID Example Consumer')

toggle_checkbox('id_teams')
write_textfield('id_request_teams', team_names)
click_button(get_element(value='Begin'))

login_from_redirect()

wait_for(assert_title, 'Django OpenID Example Consumer')
assert_text_contains(get_element(tag='div', css_class='message success'),
                     'OpenID authentication succeeded')

# Check the results of the team requests from the list in the .csv
for i, team in enumerate(resulting_teams):
    assert_text(get_elements_by_xpath("//li")[i], team)
Пример #11
0
    add_device,
    enter_otp,
)


config.set_base_url_from_env()

# Create a new account
# (We're going to lockout this account so always create a new one)
helpers.register_account()

# Add an authentication device
add_device('add_two_devices')

# Change the preference to always require 2 factor authentication and save
helpers.set_twofactor_to_always_required()

# Logout and attempt to log back in
helpers.logout_and_in()

# Enter an incorrect otp 18 times to trigger account suspension
for _ in range(18):
    # Check we are on the 2-factor login page
    wait_for(assert_displayed, 'id_oath_token')

    # Enter an incorrect password and submit
    enter_otp('12345678')

# The account is now suspended
assert_element(tag='h1', text='Account suspended')
Пример #12
0
email_address = helpers.register_account(displayname="Fred Jones", verify=True)
helpers.logout()

# Request the password reset.
go_to(urls.HOME)
assert_title('Log in')
click_link('forgotpw-link')
write_textfield('id_email', email_address)
# Even though the recaptcha field is ignored for our tests, we do
# want to verify that it is on the page.
write_textfield('recaptcha_response_field', 'ignored')
click_button(get_element(name='continue'))

assert_element(**{'data-qa-id': 'forgot_password_step_2'})

# Fetch and verify the confirmation link.
link = mail.get_verification_link_for_address(email_address)
go_to(link)

# Reset the password and verify that we're logged in.
assert_title('Reset password')
write_textfield('id_password', "Other008")
write_textfield('id_passwordconfirm', "Other008")
click_button(get_element(name='continue'))
assert_element(**edit_account_anchor)

# Now confirm that we can log in with the new password.
helpers.logout()
helpers.login(email_address, 'Other008')
wait_for(assert_element, **edit_account_anchor)
Пример #13
0
# confirm device renamed
assert_device('rename_device_new')
assert_no_device(name)

# sad paths

# rename escapes content
name = '<script>alert("rename_device");</script>'
rename_device('rename_device_new', name)
assert_device(name)
assert_no_device('rename_device_new')

# try to rename to empty string
rename_device(name, '')
# rename should have failed
assert_url_contains('/device-rename/\d+', regex=True)
# check error message
assert_text('name-error', 'This field is required.')
# cancel and go back
click_link(get_element(tag='a', text_regex='[cC]ancel'))

# spaces get trimmed
rename_device(name, ' ')
# rename should have failed
assert_url_contains('/device-rename/\d+', regex=True)
# check error message
wait_for(assert_text, 'name-error',
         'The name must contain at least one non-whitespace character.')
# cancel and go back
click_link(get_element(tag='a', text_regex='[cC]ancel'))
Пример #14
0
    write_textfield,
    wait_for,
)
from sst import config as sst_config
from u1testutils import mail
from u1testutils.sst import config

from acceptance import helpers

if 'allow_unverified' in sst_config.flags:
    skip("allow_unverified means this test is irrelevant")

config.set_base_url_from_env()

email_address_for_token = mail.make_unique_test_email_address()
token = helpers.register_account(email_address_for_token)

# Now we create a second account and try to use the original
# verification code/token.
another_email = mail.make_unique_test_email_address()
helpers.logout()
helpers.register_account(another_email, verify=False)
write_textfield(get_element(name='confirmation_code'), token)
sleep(1)  # we have no idea why this is needed but bad things happen if omitted
click_button(get_element(css_class='btn'))

# We are still on the 'Enter confirmation code' page, and have been told
# that the confirmation code we used is unknown.
wait_for(assert_title_contains, 'Enter confirmation code')
exists_element(id='confirmation_code_error')

# Interacting with external sites can take a long time
set_wait_timeout(20)

config.set_base_url_from_env()
helpers.skip_unless_staging_or_production()
helpers.login_to_test_account()

go_to("https://bitbucket.org/account/signin/")
click_link(get_element(text="OpenID log in"))


def openid_link_is_visible():
    return get_element(href="#openid", title="OpenID").is_displayed()
wait_for(openid_link_is_visible)

click_link(get_element(href="#openid", title="OpenID"))
wait_for(lambda: get_element(tag='input', id='openid-url').is_displayed())

input = get_element(tag='input', id='openid-url')
input.clear()
input.send_keys(get_base_url())
submit_button = get_element_by_css(
    'div.buttons.selected button[type=submit]')
click_button(submit_button)

wait_for(get_element, type='submit', name='yes', css_class='btn')
click_button(get_element(type='submit', name='yes', css_class='btn'))

wait_for(assert_url_contains, 'bitbucket.org')
Пример #16
0
    assert_title,
    assert_element,
    go_to,
    wait_for,
)
from u1testutils.sst import config

from acceptance import urls

from identityprovider.utils import get_current_brand


config.set_base_url_from_env()

go_to(urls.HOME)
wait_for(assert_title, 'Log in')

if get_current_brand() == 'ubuntuone':
    links = (
        ('Terms of use', 'https://one.ubuntu.com/terms/'),
        ('Privacy', 'https://one.ubuntu.com/privacy/'),
        ('Login support', 'https://forms.canonical.com/sso-support/'),
        ('Choose your language', urls.get_base_url() + '/set_language'),
    )
else:
    links = (
        ('Login support', 'https://forms.canonical.com/sso-support/'),
        ('Find out more', urls.get_base_url() + '/+description'),
        ('Source code for this service',
         'https://launchpad.net/canonical-identity-provider'),
        ('AGPL', 'http://www.gnu.org/licenses/agpl-3.0.html'),
from u1testutils import mail
from u1testutils.sso import mail as sso_mail
from u1testutils.sst import config

from acceptance import helpers


check_flags('allow_unverified')

config.set_base_url_from_env()

edit_account_anchor = {'data-qa-id': 'edit_account'}
email_address = mail.make_unique_test_email_address()
password = "******"
helpers.register_account(email_address, password=password)

wait_for(assert_element, **edit_account_anchor)

helpers.logout()

link = sso_mail.get_verification_link_for_address(email_address)
go_to(link)
wait_for(assert_title, "Log in")

helpers.login(email_address, password)

go_to(link)
click_button(get_element(name='continue'))

wait_for(assert_element, **edit_account_anchor)
Пример #18
0
from acceptance import helpers, urls


config.set_base_url_from_env()

# Some external sites have extraordinary wait times
set_wait_timeout(20)

email_address = mail.make_unique_test_email_address()
account_password = '******'

go_to(urls.NEW_ACCOUNT)
assert_title('Create account')
helpers.register_account(email_address, password=account_password)

wait_for(assert_element, **{'data-qa-id': 'edit_account'})

# Depending whether we're on Production or Staging different tests
if get_base_url() == 'https://login.ubuntu.com':   # Production
    # shop
    go_to('http://shop.canonical.com')
    wait_for(assert_title, 'Canonical Store')
    click_link(get_element(href="https://shop.canonical.com/login.php"))
    wait_for(get_element, id='id_email')
    write_textfield('id_email', email_address)
    write_textfield('id_password', account_password)
    click_button(get_element(name='continue'))
    click_button(get_element(name='yes'))
    wait_for(get_element, name='email_address')
    assert_element(value=email_address)
Пример #19
0
helpers.logout()

helpers.register_account(email_b_id, password=PASSWORD)
vcode_y = helpers.add_email(email_c_id)


# try x from a, should fail
helpers.logout()
helpers.login(email_a_id, PASSWORD)
# Trying and failing to use token X completely invalidates token X, even for
# account B (which now owns the token) later in this test.
# helpers.try_to_validate_email(email_c_id, vcode_x)
# fails(assert_title, 'Complete email address validation')

# try y from a, should fail
helpers.try_to_validate_email(email_c_id, vcode_y, finish_validation=False)
fails(assert_title, 'Complete email address validation')

# both x & y should work for b, but using one should kill the other.
# try x from b, should work
helpers.logout()
helpers.login(email_b_id, PASSWORD)
helpers.try_to_validate_email(email_c_id, vcode_x, finish_validation=False)
wait_for(assert_title, 'Complete email address validation')

# now, y from b should fail, because address C was already verified (but would
# normally work)
helpers.try_to_validate_email(email_c_id, vcode_y, finish_validation=False)
fails(assert_title, 'Complete email address validation')
Пример #20
0
    wait_for,
    write_textfield,
)
from u1testutils import mail
from u1testutils.sso import mail as sso_mail
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()
NAME = 'Some Name'

# Register the primary account.
primary_email = helpers.register_account(displayname=NAME)

# Register a secondary email, and grab the link from the email sent to
# the secondary address.
secondary_email = mail.make_unique_test_email_address()
go_to(urls.EMAILS)
wait_for(assert_title_contains, "'s email addresses")
write_textfield('id_newemail', secondary_email)
click_button(get_element(name='continue'))
link = sso_mail.get_verification_link_for_address(secondary_email)

# Follow the link from the email to ensure it verifies the secondary
# address.
go_to(link)
click_button(get_element(name='continue'))
wait_for(assert_element, **{'data-qa-id': 'edit_account'})
Пример #21
0
# 2) Check you cannot login with the wrong password, then click the 'Forgot
# Password' and ensure it is prepopulated

from sst.actions import (
    assert_text_contains,
    assert_title,
    click_link,
    get_element,
    wait_for,
)
from u1testutils import mail
from u1testutils.sst import config

from acceptance import helpers


config.set_base_url_from_env()

primary_email_id = mail.make_unique_test_email_address()
secondary_email_id = mail.make_unique_test_email_address()
helpers.register_account(primary_email_id)

helpers.logout()
helpers.login(primary_email_id, 'BOGUS')
assert_text_contains('content', "Password didn't match")
click_link('forgotpw-link')
wait_for(assert_title, 'Reset password')
assert get_element(id='id_email').get_attribute('value') == primary_email_id
    write_textfield,
    wait_for,
)
from u1testutils.sso import mail
from u1testutils.sst import config

from acceptance import helpers


config.set_base_url_from_env()

# Register a new account and request a password reset.
email_address = helpers.register_account(displayname="Fred Jones", verify=True)
helpers.request_password_reset(email_address)

# Fetch and verify the confirmation code.
link = mail.get_verification_link_for_address(email_address)
go_to(link)

# Reset the password and verify that we're logged in.
assert_title('Reset password')
write_textfield('id_password', "Admin007")
write_textfield('id_passwordconfirm', "Admin007")
click_button(get_element(name='continue'))
assert_element(**{'data-qa-id': 'edit_account'})

# Now try to use the link a second time.
helpers.logout()
go_to(link)
wait_for(assert_title, "Unauthorized confirmation code")
# Interacting with external sites can take a long time
set_wait_timeout(20)

config.set_base_url_from_env()
helpers.skip_unless_staging_or_production()
helpers.login_to_test_account()

go_to("http://askubuntu.com/users/authenticate/")
if exists_element(id='more-options-link'):
    get_element(id='more-options-link').click()

    def openid_input_is_displayed():
        return get_element(id='openid_identifier').is_displayed()

    wait_for(openid_input_is_displayed)

write_textfield('openid_identifier', get_base_url())
click_button('submit-button')

wait_for(get_element, type='submit', name='yes', css_class='btn')
click_button(get_element(type='submit', name='yes', css_class='btn'))

wait_for(assert_url_contains, 'askubuntu.com')
if exists_element(type="submit", value="Confirm and Create New Account"):
    click_button(get_element(type="submit",
                             value="Confirm and Create New Account"))
    wait_for(assert_title, "Ask Ubuntu - Stack Exchange")

go_to(urls.HOME)
link = get_elements_by_css('#visited-sites tbody td a')[0]
Пример #24
0
from u1testutils.sst import config

from acceptance import helpers, urls

from identityprovider.utils import get_current_brand


if get_current_brand() == 'ubuntuone':
    skip(
        'The ubuntuone brand does client side validation'
    )

config.set_base_url_from_env()

# Create and verify account A
helpers.register_account()

# Add and verify 2nd email
go_to(urls.EMAILS)
wait_for(assert_title_contains, "'s email addresses")
write_textfield('id_newemail', address)
click_button(get_element(name='continue'))

# Check the outcome
if valid:
    wait_for(assert_title, 'Validate your email address')
    mail.delete_msgs_sent_to(address)
else:
    wait_for(assert_title, 'Add an email')
    assert_text_contains(get_element(name='newemailform'), 'Invalid email.')
Пример #25
0
    assert_text_contains,
    assert_title,
    fails,
    go_to,
    wait_for,
)
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

# No account required, so jump straight to the form.
go_to(urls.ENTER_TOKEN)
wait_for(assert_title, 'Enter confirmation code')

helpers.try_to_validate_email(address, code, finish_validation=False)
wait_for(assert_title, 'Enter confirmation code')

error1_msg = 'This field is required.'
error2_msg = 'Required field.'

if error1:
    assert_text_contains('content', error1_msg)
else:
    fails(assert_text_contains, 'content', error1_msg)

if error2:
    assert_text_contains('content', error2_msg)
else:
Пример #26
0
    skip_production,
)


config.set_base_url_from_env()
skip_production()
# XXX: skip if staging until the test can be made to reliably pass
if is_staging():
    skip()

toggled_elements = ast.literal_eval(toggled_elements)
disabled_elements = ast.literal_eval(disabled_elements)
returned_sreg = ast.literal_eval(returned_sreg)

go_to(urls.CONSUMER)
wait_for(assert_title, 'Django OpenID Example Consumer')
toggle_checkbox('id_sreg')
set_radio_value(radio_nickname)
set_radio_value(radio_fullname)
set_radio_value(radio_email)
set_radio_value(radio_language)
click_button(get_element(value='Begin'))

wait_for(assert_title, 'Log in')
write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL)
write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD)
click_button(get_element_by_css('*[data-qa-id="ubuntu_login_button"]'))

wait_for(assert_title_contains, 'Authenticate to')
# Check the elements specified in the .csv list
if toggled_elements is not None:
Пример #27
0
from sst.actions import (
    assert_text_contains,
    assert_title,
    assert_title_contains,
    click_button,
    get_element,
    go_to,
    wait_for,
    write_textfield,
)
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

# Create and verify account A
helpers.register_account()

# Add and verify 2nd email
go_to(urls.EMAILS)
wait_for(assert_title_contains, "'s email addresses")
write_textfield('id_newemail', '')
click_button(get_element(name='continue'))

# Check for error message
wait_for(assert_title, 'Add an email')
assert_text_contains(get_element(name='newemailform'), 'Required field.')
Пример #28
0
from u1testutils.sst import config

from acceptance import helpers, urls


config.set_base_url_from_env()

go_to(urls.NEW_ACCOUNT)
assert_title('Create account')

email_address = mail.make_unique_test_email_address()
helpers.fill_registration_form(email_address)

click_button(get_element(name='continue'))

if 'allow_unverified' not in sst_config.flags:
    assert_title_contains('Account creation mail sent')
    assert_text_contains(
        get_element(id='content'),
        r'just emailed .* \(from .*\) to confirm your address\.',
        regex=True)

    vcode = sso_mail.get_verification_code_for_address(email_address)

    write_textfield(get_element(name='confirmation_code'), vcode)
    click_button(get_element(css_class='btn'))

# We know that the confirmation code worked if we are now looking at the
# logged-in details page for the user.
wait_for(assert_element, **{'data-qa-id': 'edit_account'})
Пример #29
0
                     r'just emailed .* \(from .*\) to confirm your address\.',
                     regex=True)

vcode = sso_mail.get_verification_code_for_address(email_address)


# regression check for #920105
# check we cannot submit an empty code
click_button(get_element(css_class='btn'))
# we should not have moved pages
assert_title_contains('Account creation mail sent')

# fill in an invalid code
write_textfield(get_element(name='confirmation_code'), 'XXXXXX')
click_button(get_element(css_class='btn'))

# we should now be at a different page, as the form reuses the enter_token view
# to handle submission

wait_for(assert_title, "Enter confirmation code")

# regression check for #920105
# check the email is filled in
assert_text(get_element(name='email'), email_address)

write_textfield(get_element(name='confirmation_code'), vcode)
click_button(get_element(css_class='btn'))

# Check we still can actually confirm the account
wait_for(assert_element, **{'data-qa-id': 'edit_account'})
Пример #30
0
a.assert_title_contains('Home page')

user = common.User(data.user)

user.login()

# search for tv
a.write_textfield('search', 'tv')
common.click_button_by_title('Search')

# click it
common.click_button_by_title('Add to Cart', multiple=True)

common.click_button_by_title('Proceed to Checkout', multiple=True)

a.wait_for(a.assert_displayed, 'checkout-step-billing')

a.click_button(a.get_element_by_xpath(
    "//div[@id='checkout-step-billing']"
    "//button[@title='Continue']"))

# in 1.4 it doesn't automatically proceed to shipping method
# because Use Billing Address is not active
if common.get_version() < (1, 5, 0, 0):
    check = a.get_element_by_xpath("//input[@id='shipping:same_as_billing']")
    a.wait_for(a.assert_displayed, check)
    check.click()
    # we need the right continue button, so roll by hand
    button = a.get_element_by_xpath(
        "//form[@id='co-shipping-form']//button[@title='Continue']")
    button.click()
Пример #31
0
# 3) Check the following links on the login page to ensure they are all
# working:
# Login support, Find out more, Source code for this service, AGPL, Terms of
# Service, Privacy Policy, ubuntu logo {ubuntu.com}

# This tests only the Ubuntu logo.

from sst.actions import (
    assert_title,
    get_element,
    go_to,
    wait_for,
)
from u1testutils.sst import config

from acceptance import urls

config.set_base_url_from_env()

go_to(urls.HOME)
wait_for(assert_title, 'Log in')
el = get_element(id='footer-logo')
link = el.find_element_by_tag_name('a')

link.click()
wait_for(assert_title, "The world's most popular free OS | Ubuntu")