Пример #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_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'
Пример #3
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'
Пример #4
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'
Пример #5
0
 def login_with_osa(self, username, password):
     """Login with an os account."""
     self.find_element(*self._os_btn_locator).click()
     sleep(1.0)
     accounts = AccountsHome(self.driver)
     accounts.service_log_in(username, password)
     sleep(1.0)
     return PaymentsHome(self.driver)
Пример #6
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.'
Пример #7
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'
Пример #8
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'
Пример #9
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'
Пример #10
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'
Пример #11
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'
Пример #12
0
 def log_in(self,
            user=None,
            password=None,
            destination=None,
            url=None,
            do_not_log_in=False):
     """Log a user into the website."""
     Utility.click_option(self.driver, element=self.login)
     sleep(0.25)
     from pages.accounts.home import AccountsHome
     if do_not_log_in:
         return go_to_(AccountsHome(self.driver, url))
     if destination:
         home = go_to_(AccountsHome(self.driver))
         return go_to_(home.log_in(user, password, destination, url))
     from pages.web.home import WebHome
     return go_to_(WebHome(self.driver, url))
Пример #13
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'
Пример #14
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'
Пример #15
0
        def go_to_log_in(self):
            """Click the 'LOG IN' button.

            :return: the Accounts log in page
            :rtype: :py:class:`~pages.accounts.home.AccountsHome`

            """
            self.find_element(*self._log_in_locator).click()
            from pages.accounts.home import AccountsHome
            return go_to_(AccountsHome(self.driver))
Пример #16
0
        def log_out(self) -> Page:
            """Click the 'Log out' link.

            :return: the Accounts sign in page
            :rtype: :py:class:`~pages.accounts.home.AccountsHome`

            """
            link = self.find_element(*self._log_out_link_locator)
            Utility.click_option(self.driver, element=link)
            from pages.accounts.home import AccountsHome
            return go_to_(
                AccountsHome(self.driver, base_url=self.page.base_url))
Пример #17
0
 def go_to_openstax_tutor(self, base_url=None):
     """Click the 'Go to OpenStax Tutor' button."""
     Utility.switch_to(self.driver, self._tutor_dashboard_locator)
     if self.page.is_safari:
         sleep(2.0)
     self.wait.until(lambda _: 'accounts' in self.driver.current_url or
                     'tutor' in self.driver.current_url)
     if 'accounts' in self.driver.current_url:
         from pages.accounts.home import AccountsHome
         return go_to_(AccountsHome(self.driver, base_url=base_url))
     from pages.tutor.dashboard import Dashboard
     return go_to_(Dashboard(self.driver, base_url=base_url))
Пример #18
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'
Пример #19
0
def test_unverified_users_sent_to_faculty_verification_for_locked_resources(
        accounts_base_url, web_base_url, selenium, admin):
    """Test non-verified users must fill out faculty verification form."""
    # SETUP:
    name = Utility.random_name()
    email = RestMail('{first}.{last}.{tag}'.format(
        first=name[1], last=name[2], tag=Utility.random_hex(4)).lower())
    email.empty()
    address = email.address
    password = Utility.random_hex(20)

    # GIVEN: a user viewing the instructor resources on a book details page
    # AND:  have a non-verified, non-pending account
    # AND:  are logged into the site
    accounts = AccountsHome(selenium, accounts_base_url).open()
    profile = (
        accounts.content
        .view_sign_up().content
        .sign_up_as_an_educator()
        .account_sign_up(
            email=address, password=password, _type=Accounts.INSTRUCTOR,
            provider=Accounts.RESTMAIL, name=name, school='Automation',
            news=False, phone=Utility.random_phone(),
            webpage=web_base_url, subjects=subject_list(2),
            students=10, use=Accounts.RECOMMENDED))
    profile.log_out()
    profile = accounts.log_in(*admin)
    search = Search(selenium, accounts_base_url).open()
    user = search.find(terms={'email': address}).users[0]
    details = user.edit()
    details.faculty_status = Accounts.REJECTED
    details.save()
    details.close_tab()
    profile = Profile(selenium, accounts_base_url).open()
    profile.log_out()
    accounts.log_in(address, password)
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    book = subjects.select_random_book(_from=Library.HAS_I_LOCK)
    book.select_tab(Web.INSTRUCTOR_RESOURCES)
    locked_resources = book.instructor.resources_by_option(Web.LOCKED)
    random_resource = Utility.random(0, len(locked_resources) - 1)
    resource = locked_resources[random_resource]

    # WHEN: they click on "Click here to unlock" link
    verification = resource.select()

    # THEN: the Accounts faculty verification form is loaded in a new tab
    assert(verification.is_displayed()), 'Verification form not displayed'
    assert('Apply for instructor access' in selenium.page_source), \
        'Instructor access text not found in the page source'
Пример #20
0
def test_students_sign_up_to_access_locked_student_content(
        accounts_base_url, web_base_url, selenium):
    """Users are directed to sign up to access locked student content."""
    # SETUP:
    name = Utility.random_name()
    email = RestMail(f'{name[1]}.{name[2]}.{Utility.random_hex(4)}'.lower())
    email.empty()
    password = Utility.random_hex(20)

    # GIVEN: a user viewing the student resources on a book details page
    # AND:  is not logged into the site
    # AND:  there is a locked student resource
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    book = subjects.select_random_book(_from=Library.HAS_S_LOCK)
    book.select_tab(Web.STUDENT_RESOURCES)

    # WHEN: they click on "Click here to unlock" link
    options = book.student.resources_by_option(Web.LOCKED)
    assert(options), f'No locked student resources found for {book.title}'
    option = options[Utility.random(0, len(options) - 1)]
    option_title = option.title
    option.select()
    accounts = AccountsHome(selenium, accounts_base_url)

    # THEN: the Accounts sign up page is displayed
    assert(accounts.is_displayed()), 'Accounts login page not displayed'
    assert('accounts' in accounts.location), \
        f'Not on an Accounts instance ({accounts.location})'

    # WHEN: they sign up
    book = accounts.student_signup(name[1], name[2], password, email,
                                   Book, web_base_url)

    # THEN: the student resources on the book details page is displayed
    # AND:  the resource is available for download
    assert(book.student.is_displayed()), \
        f'Student resources not displayed ({book.location})'
    option = book.student.resource_by_name(option_title)
    assert(not option.is_locked), f'{option.title} is still locked'
Пример #21
0
def test_pending_instructors_see_access_pending_for_locked_resources(
        accounts_base_url, web_base_url, selenium):
    """Test pending instructors see 'Access pending' for locked resources."""
    # GIVEN: a user viewing the book details page
    # AND:  have an unverified instructor account
    # AND:  the book has locked instructor resources
    name = Utility.random_name()
    email = RestMail(
        '{first}.{last}.{tag}'
        .format(first=name[1], last=name[2], tag=Utility.random_hex(3))
        .lower()
    )
    email.empty()
    address = email.address
    password = Utility.random_hex(17)
    subjects = subject_list(2)
    accounts = AccountsHome(selenium, accounts_base_url).open()
    (accounts.content
        .view_sign_up().content
        .sign_up_as_an_educator()
        .account_sign_up(
            email=address, password=password, _type=Accounts.INSTRUCTOR,
            provider=Accounts.RESTMAIL, name=name, school='Automation',
            news=False, phone=Utility.random_phone(),
            webpage='https://openstax.org/', subjects=subjects,
            students=10, use=Accounts.ADOPTED))
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    book = subjects.select_random_book(_from=Library.HAS_I_LOCK)

    # WHEN: they click on the "Instructor resources" tab
    book.select_tab(Web.INSTRUCTOR_RESOURCES)

    # THEN: locked resources show "Access pending"
    for option in book.instructor.resources:
        assert(option.status_message in Web.ACCESS_OK), (
            '{resource} ("{status}") not pending authorization or available'
            .format(resource=option.title, status=option.status_message))
Пример #22
0
def test_verified_instructors_may_access_locked_resources(
        accounts_base_url, web_base_url, selenium, teacher):
    """Test verified instructors may access locked resources."""
    # GIVEN: a user viewing the book details page
    # AND:  they have a valid instructor login and password
    # AND:  they are not logged into the website
    # AND:  the book has locked instructor resources
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    book = subjects.select_random_book(_from=Library.HAS_I_LOCK)

    # WHEN: they click on the "Instructor resources" tab
    # AND:  click on the "Click here to unlock" link
    book.select_tab(Web.INSTRUCTOR_RESOURCES)
    options = book.instructor.resources_by_option(Web.LOCKED)
    assert(options), 'No locked instructor resources found'
    option = options[Utility.random(0, len(options) - 1)]
    option_title = option.title
    option.select()
    accounts = AccountsHome(selenium, accounts_base_url)

    # THEN: the Accounts login page is displayed
    assert(accounts.is_displayed()), 'Accounts login page not displayed'
    assert('accounts' in accounts.location), \
        f'Not on an Accounts instance ({accounts.location})'

    # WHEN: they log into Accounts
    accounts.service_log_in(*teacher, Book, web_base_url)

    # THEN: the instructor resources tab on the book details page is displayed
    # AND:  the resource is no longer locked
    assert(book.instructor.is_displayed()), \
        f'Instructor resources not displayed ({book.location})'
    option = book.instructor.resource_by_name(option_title)
    assert(not option.is_locked), \
        '{option} is still locked'.format(option=option.title)
Пример #23
0
 def log_in(self):
     """Return to the login home page."""
     link = self.find_element(*self._sign_in_locator)
     Utility.click_option(self.driver, element=link)
     return go_to_(AccountsHome(self.driver, self.page.base_url))