示例#1
0
def test_a_users_profile(accounts_base_url, selenium, student):
    """Login as a student user with a username."""
    # GIVEN: a valid student user viewing the Accounts home page
    home = AccountsHome(selenium, accounts_base_url).open()

    # WHEN: they log into Accounts
    profile = home.log_in(*student)

    # THEN: the user's profile is displayed
    # AND:  the admin console links are not displayed
    # AND:  the profile shows the name, username (if assigned), emails and log
    #       in methods
    assert('profile' in profile.location), f'User "{student[0]}" not logged in'
    assert(profile.content.root.is_displayed()), \
        'profile content not displayed'

    assert(not profile.console.is_admin), 'User is an administrator'
    with pytest.raises(AccountsException) as err:
        profile.console.view_popup_console()
    assert('not an administrator' in str(err.value)), \
        'pop up console displayed'

    assert(profile.content.name), "user's name not found"
    assert(profile.content.has_username), 'no username found'
    assert(profile.content.emails.emails), 'no email found'
    assert(profile.content.enabled_providers), 'no log in providers found'
示例#2
0
def test_set_the_user_name(accounts_base_url, selenium, student):
    """Test the user's name field."""
    # SETUP:
    new_name = Utility.random_name()

    # GIVEN: a logged in student user viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*student)
    name = profile.content.name.get_name_parts()

    # WHEN: they changes their name
    profile.content.name.change_name()
    profile.content.name.title = new_name[Accounts.TITLE]
    profile.content.name.first_name = new_name[Accounts.FIRST]
    profile.content.name.last_name = new_name[Accounts.LAST]
    profile.content.name.suffix = new_name[Accounts.SUFFIX]
    profile.content.name.accept()

    # THEN: their name is changed
    assert(profile.content.name.full_name == ' '.join(new_name).strip()), \
        'the new name does not match'

    # WHEN: they resets the changes
    profile.content.name.change_name()
    profile.content.name.title = name[Accounts.TITLE]
    profile.content.name.first_name = name[Accounts.FIRST]
    profile.content.name.last_name = name[Accounts.LAST]
    profile.content.name.suffix = name[Accounts.SUFFIX]
    profile.content.name.accept()

    # THEN: their name is reset
    assert(profile.content.name.full_name == ' '.join(name).strip()), \
        'the name did not reset'
示例#3
0
def test_get_current_emails_and_status(accounts_base_url, selenium, student):
    """Test the email fields."""
    # GIVEN: a student viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*student)

    # WHEN: they add a new email to the account
    name = profile.content.name.get_name_parts()
    fake_email = Utility.fake_email(name[Accounts.FIRST], name[Accounts.LAST])
    profile.content.emails.add_email_address()
    profile.content.emails.new_email.email = fake_email
    profile.content.emails.new_email.accept()

    # THEN: The new email is attached to the account
    status = False
    for entry in profile.content.emails.emails:
        status = status or (entry.email == fake_email)
    assert(status), f'"{fake_email}" not added'

    # WHEN: The new email is deleted
    for entry in profile.content.emails.emails:
        if entry.email == fake_email:
            popup = entry.delete()
            popup.ok()
            break

    # THEN: The email is removed from the account
    for entry in profile.content.emails.emails:
        assert(entry.email != fake_email), f'"{fake_email}" not removed'
示例#4
0
def test_get_and_set_a_username(accounts_base_url, selenium, student):
    """Test the username field."""
    # SETUP:
    new_username = Utility.random_hex(18, True)

    # GIVEN: a user with a username viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*student)
    old_username = profile.content.username.username

    # WHEN: they click their username
    # AND:  enter a new username in the input field
    # AND:  click the checkmark button
    profile.content.username.change_username()
    profile.content.username.username = new_username
    profile.content.username.accept()

    # THEN: the username field shows the change
    assert (profile.content.username.username != old_username), \
        'username change failed'

    # WHEN: they click their username
    # AND:  enter the original username in the input field
    # AND:  click the checkmark button
    profile.content.username.change_username()
    profile.content.username.username = old_username
    profile.content.username.accept()

    # THEN: the original username is shown
    assert (profile.content.username.username == old_username), \
        'username reset failed'
示例#5
0
def test_attempt_to_log_in_with_a_blank_user(accounts_base_url, selenium):
    """Blank username error message test."""
    # SETUP:
    user = ''
    password = ''

    # GIVEN: a user viewing the Accounts Home page
    home = Home(selenium, accounts_base_url).open()

    # WHEN: they click the "Continue" button
    with pytest.raises(AccountsException) as err:
        home.log_in(user, password)

    # THEN: an error message "Email can't be blank" is displayed
    assert("Email can't be blank" in str(err.value)), \
        'Incorrect error message'
示例#6
0
def test_attempt_to_log_in_with_an_invalid_password(
        accounts_base_url, selenium, student):
    """Invalid password error message test."""
    # SETUP:
    user = student[0]
    password = ''

    # GIVEN: a user viewing the Accounts Home page
    home = Home(selenium, accounts_base_url).open()

    # WHEN: they enter the username or e-mail
    # AND:  enters an invalid password
    # AND:  clicks the "Continue" button
    with pytest.raises(AccountsException) as err:
        home.log_in(user, password)

    # THEN: an error message "Password can't be blank" is displayed
    assert("Password can't be blank" in str(err.value)), \
        'Incorrect error message'
示例#7
0
def test_open_the_admin_pop_up_console(accounts_base_url, admin, selenium):
    """Open the pop up console modal."""
    # GIVEN: an admin viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*admin)

    # WHEN: they click the "Popup Console" link
    popup = profile.console.view_popup_console()

    # THEN: the pop up console is displayed
    assert(popup.root.is_displayed()), 'failed to open the popup console.'
示例#8
0
def test_go_to_the_admins_full_console(accounts_base_url, admin, selenium):
    """Open the full administrator console."""
    # GIVEN: an admin viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*admin)

    # WHEN: they click the "Full Console" link
    console = profile.console.view_full_console()

    # THEN: the admin control console is loaded
    assert('/admin/console' in selenium.current_url), \
        'not at the console page'
    assert(console.is_displayed()), 'full console not displayed'
示例#9
0
def test_reset_a_users_password(accounts_base_url, selenium):
    """Reset a user's password."""
    # SETUP:
    name = Utility.random_name()
    email = RestMail(f'{name[1]}.{name[2]}.{Utility.random_hex(6)}'.lower())
    email.empty()
    address = email.address
    password = Utility.random_hex(length=14, lower=True)
    reset_password = Utility.random_hex(length=12, lower=True)

    # GIVEN: a registered user viewing the Accounts Home page
    home = Home(selenium, accounts_base_url).open()
    profile = home.student_signup(first_name=name[1], last_name=name[2],
                                  password=password, email=email)
    home = profile.content.log_out()
    email.empty()

    # WHEN: they click the "Forgot your password?" link
    # AND:  enter their email address
    # AND:  click the "Reset my password" button
    reset = home.content.forgot_your_password().content
    reset.email = address
    link_sent = reset.reset_my_password()

    # THEN: a "Password reset email sent" message is displayed
    assert('Password reset email sent' in link_sent.page_source), \
        f'Password reset message not seen ({link_sent.location})'

    # WHEN: open the "Reset your OpenStax password" e-mail
    # AND: click the "Click here to reset your OpenStax password." link
    # AND: a new password is entered in both input boxes
    # AND: click the "RESET PASSWORD" button
    # AND: click the "CONTINUE" button
    email.wait_for_mail()
    print(email.inbox[0].html)
    url = email.inbox[0].reset_link
    selenium.get(url)
    reset_form = ChangePassword(selenium, accounts_base_url).content
    reset_form.password = reset_password
    profile = reset_form.log_in()

    # THEN: the user's profile is displayed
    assert('profile' in profile.location), 'User is not logged in'

    # WHEN: the user logs out
    # AND: logs in using the new password
    home = profile.content.log_out()
    profile = home.log_in(address, reset_password)

    # THEN: the user's profile is displayed
    assert('profile' in profile.location), 'User is not logged in'
示例#10
0
def test_log_in_as_a_student(accounts_base_url, selenium, student):
    """Student log in test."""
    # GIVEN: a user viewing the Accounts Home page
    # AND:   valid credentials for a student user
    home = Home(selenium, accounts_base_url).open()

    # WHEN: the student user logs in
    profile = home.log_in(*student)

    # THEN: the student is logged in
    # AND: the student's profile is displayed
    assert('profile' in profile.location), f'User "{student[0]}" not logged in'

    assert(profile.content.title == "My Account"), 'Not viewing a profile'
示例#11
0
def test_verify_an_email(accounts_base_url, selenium, student):
    """Test the email verification process."""
    # SETUP:
    name = Utility.random_hex(19, True)
    email = RestMail(name)
    email.empty()
    address = email.address

    # GIVEN: a student viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*student)

    # WHEN: they add an email without verifying it
    # AND:  click the email address
    # AND:  click the "Resend confirmation email" link
    # AND:  open the second verification email
    # AND:  click the confirmation link
    # AND:  close the new tab showing "Thank you for confirming your email
    #       address."
    # AND:  reload the profile page
    profile.content.emails.add_email_address()
    profile.content.emails.new_email.email = address
    profile.content.emails.new_email.accept()
    email.wait_for_mail()
    email.empty()
    for entry in profile.content.emails.emails:
        if entry.email == address:
            entry.toggle()
            entry.resend_confirmation_email()
    email.wait_for_mail()[-1].confirm_email()
    profile.reload()

    # THEN: the new email does not have "unconfirmed" to the right of it
    for entry in profile.content.emails.emails:
        if entry.email == address:
            assert(entry.is_confirmed), 'email is not confirmed'
            break

    # WHEN: they delete the new email
    for entry in profile.content.emails.emails:
        if entry.email == address:
            popup = entry.delete()
            profile = popup.ok()
            break

    # THEN: the email list is restored
    for entry in profile.content.emails.emails:
        assert(entry.email != address), 'email was not been removed'
示例#12
0
def test_get_the_user_name(accounts_base_url, selenium, student):
    """Test the name fields."""
    # GIVEN: a logged in student user viewing their profile
    home = AccountsHome(selenium, accounts_base_url).open()
    profile = home.log_in(*student)
    name = profile.content.name.full_name

    # WHEN: they open the name properties
    profile.content.name.change_name()
    getters = [
        profile.content.name.title,
        profile.content.name.first_name,
        profile.content.name.last_name,
        profile.content.name.suffix]

    # THEN: the user's full name matches the various name parts
    assert(name == ' '.join(getters).strip()), \
        'name does not match'
示例#13
0
def test_an_administrators_profile(accounts_base_url, admin, selenium):
    """Login as an administrative user with a username."""
    # GIVEN: a valid administrative user viewing the Accounts home page
    home = AccountsHome(selenium, accounts_base_url).open()

    # WHEN: they log into Accounts
    profile = home.log_in(*admin)

    # THEN: the user's profile is displayed
    # AND:  the admin console links are displayed
    # AND:  the profile shows the name, username (if assigned), e-mails and log
    #       in methods
    assert('profile' in profile.location), f'User "{admin[0]}" not logged in'
    assert(profile.content.root.is_displayed()), \
        'profile content not displayed'

    assert(profile.console.is_admin), 'User is not an administrator'

    assert(profile.content.name), "user's name not found"
    assert(profile.content.has_username), 'no username found'
    assert(profile.content.emails.emails), 'no email found'
    assert(profile.content.enabled_providers), 'no log in providers found'