コード例 #1
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'
コード例 #2
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'
コード例 #3
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'
コード例 #4
0
def test_adoption_form_requires_at_least_one_book_selection(
        web_base_url, selenium):
    """Test that the adoption form requires at least one book selection."""
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    _, first_name, last_name, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{rand}'.format(
        first=first_name, last=last_name, rand=Utility.random_hex(5)).lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'

    # GIVEN: a user viewing the adoption page
    adoption = Adoption(selenium, web_base_url).open()

    # WHEN: they select a non-Student role from the drop down menu
    # AND:  fill out the contact form fields
    # AND:  click on the "Next" button
    # AND:  click on the "Next" button
    with pytest.raises(WebException) as error:
        adoption.submit_adoption(user_type=user_type,
                                 first=first_name,
                                 last=last_name,
                                 email=email.address,
                                 phone=phone,
                                 school=school,
                                 books={})

    # THEN: the textbook selection list is still displayed
    # AND:  an error message "Please select at least one book" is displayed
    assert ('Please select at least one book'
            in Utility.get_error_information(error)), (
                'The book error was not displayed')
コード例 #5
0
def test_non_student_users_submit_the_adoption_form(web_base_url, selenium):
    """Test that a non-student user is able to submit the adoption form.

    Salesforce verification of the form is not tested.
    """
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    _, first_name, last_name, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{rand}'.format(
        first=first_name, last=last_name, rand=Utility.random_hex(3)).lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'
    book_list = Library().random_book()
    books = {}
    for book in book_list:
        books[book] = {
            'status':
            Web.USING_STATUS[Utility.random(0,
                                            len(Web.USING_STATUS) - 1)],
            'students':
            Utility.random(Web.STUDENT_MIN, Web.STUDENT_MAX)
        }
    tech_providers = TechProviders.get_tech(Utility.random(0, 3))
    if TechProviders.OTHER in tech_providers:
        other = 'Another product provider'
    else:
        other = None

    # GIVEN: a user viewing the adoption page
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    initial_book = choice(list(books.keys()))
    book = subjects.select_book(initial_book)
    adoption = book.is_using()

    # WHEN: they select a non-Student role from the drop down menu
    # AND:  fill out the contact form fields
    # AND:  click on the "Next" button
    # AND:  select a book subject
    # AND:  select a radio option from "How are you using <book>?"
    # AND:  enter a number of students
    # AND:  click on the "Next" button
    # AND:  select a technology provider
    # AND:  click on the "Submit" button
    book = adoption.submit_adoption(user_type=user_type,
                                    first=first_name,
                                    last=last_name,
                                    email=email.address,
                                    phone=phone,
                                    school=school,
                                    books=books,
                                    tech_providers=tech_providers,
                                    other_provider=other)

    # THEN: the book's instructor resources page is displayed
    assert (book.is_displayed())
    assert ('books' in book.location)
コード例 #6
0
def test_sign_up_as_an_instructor(accounts_base_url, selenium):
    """Test non-student user signup."""
    # SETUP:
    from pages.accounts.profile import Profile as profile
    name = Utility.random_name()
    email = RestMail((f'{name[Accounts.FIRST]}.{name[Accounts.LAST]}.'
                      f'{Utility.random_hex(4)}').lower())
    email.empty()
    address = email.address
    password = Utility.random_hex(20)

    # GIVEN: a user with a valid email address viewing the home page
    home = Home(selenium, accounts_base_url).open()

    # WHEN: they click the "Sign up" tab
    # AND:  click the "Educator" box
    # AND:  selects "Instructor" from the drop down menu
    # AND:  enters the email address
    # AND:  clicks the "NEXT" button (a second click may be required if the
    #       email does not end in ".edu")
    # AND:  enters the supplied PIN
    # AND:  clicks the "CONFIRM" button
    # AND:  enters the password in both input boxes
    # AND:  clicks "SUBMIT"
    # AND:  enters data in the various user and course profile boxes
    # AND:  clicks the checkbox next to "I agree to the Terms of Use and the
    #       Privacy Policy."
    # AND:  clicks the "CREATE ACCOUNT" button
    # AND:  clicks the "OK" button
    sign_up = home.content.view_sign_up()

    educator = sign_up.content.sign_up_as_an_educator()

    profile = educator.sign_up(
        first=name[1],
        last=name[2],
        email=email,
        password=password,
        phone=Utility.random_phone(),
        school='Automation',
        page=profile,
        base_url=accounts_base_url)

    # THEN: their new account profile is displayed
    full_name = profile.content.name.full_name
    addresses = [entry.email for entry in profile.content.emails.emails]
    assert('profile' in profile.location), \
        'account profile not displayed'
    assert(name[Accounts.FIRST] in full_name), \
        'first name does not match sign up'
    assert(name[Accounts.LAST] in full_name), \
        'last name does not match sign up'
    assert(address in addresses), \
        'sign up email not found'
コード例 #7
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))
コード例 #8
0
def test_sign_up_as_a_student_user(accounts_base_url, selenium):
    """Test student user signup."""
    # SETUP:
    name = Utility.random_name()
    email = RestMail((f'{name[Accounts.FIRST]}.{name[Accounts.LAST]}.'
                      f'{Utility.random_hex(3)}').lower())
    email.empty()
    address = email.address
    password = Utility.random_hex(20)

    # GIVEN: a user with a valid email address viewing the home page
    home = Home(selenium, accounts_base_url).open()

    # WHEN: they click the "Sign up" tab
    # AND:  click the "Student" box
    # AND:  enter their first name, last name, email address and password,
    #       click the "I agree to the Terms of Use and Privacy Policy",
    #       checkbox, click the "Continue" button
    # AND:  enter the confirmation PIN number and click the "Confirm my
    #       account" button
    # AND:  click the "Finish" button
    sign_up = home.content.view_sign_up()

    student_sign_up = sign_up.content.sign_up_as_a_student().content

    student_sign_up.first_name = name[Accounts.FIRST]
    student_sign_up.last_name = name[Accounts.LAST]
    student_sign_up.email = address
    student_sign_up.password = password
    student_sign_up.i_agree()
    confirm_email = student_sign_up._continue().content

    pin = email.wait_for_mail()[-1].pin
    confirm_email.pin = pin
    complete_sign_up = confirm_email.confirm_my_account().content

    profile = complete_sign_up.finish()

    # THEN: their new account profile is displayed
    full_name = profile.content.name.full_name
    addresses = [entry.email for entry in profile.content.emails.emails]
    assert('profile' in profile.location), \
        'account profile not displayed'
    assert(name[Accounts.FIRST] in full_name), \
        'first name does not match sign up'
    assert(name[Accounts.LAST] in full_name), \
        'last name does not match sign up'
    assert(address in addresses), \
        'sign up email not found'
コード例 #9
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'
コード例 #10
0
def test_a_book_is_preselected_when_a_book_details_interest_link_is_used(
        web_base_url, selenium):
    """Test the book is already selected when passed in the URL."""
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    _, first_name, last_name, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{rand}'.format(
        first=first_name, last=last_name, rand=Utility.random_hex(4)).lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'
    book, short, full, detail_append = Library().get_name_set()
    books = [short]
    students = ''

    # GIVEN: a user viewing a book page
    book_details = Book(selenium, web_base_url, book_name=detail_append).open()

    # WHEN: they click on the "Sign up to learn more" link
    # AND:  select a non-Student role from the drop down menu
    # AND:  fill out the contact form fields
    # AND:  click on the "Next" button
    interest = book_details.is_interested()
    if interest.survey.is_displayed():
        interest.survey.close()
    if interest.privacy_notice.is_displayed():
        interest.privacy_notice.got_it()
    with pytest.raises(WebException) as error:
        interest.submit_interest(user_type=user_type,
                                 first=first_name,
                                 last=last_name,
                                 email=email.address,
                                 phone=phone,
                                 school=school,
                                 books=books,
                                 students=students,
                                 additional_resources=Web.resources(),
                                 heard_on=Web.heard_by())

    # THEN: the book is selected
    selection = interest.form.selection
    assert(short in selection), \
        f'{short} not in the current selection ({selection})'
    assert('Using error' in Utility.get_error_information(error)), \
        'No book is preselected'
コード例 #11
0
def test_a_book_is_preselected_when_a_book_details_adoption_link_is_used(
        web_base_url, selenium):
    """Test using a book details page adoption link prefills the book."""
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    _, first_name, last_name, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{rand}'.format(
        first=first_name, last=last_name, rand=Utility.random_hex(4)).lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'
    book, short, full, detail_append = Library().get_name_set()
    books = {
        short: {
            'status': '',
            'students': '',
        }
    }

    # GIVEN: a user viewing a book page
    home = WebHome(selenium, web_base_url).open()
    subjects = home.web_nav.subjects.view_all()
    book = subjects.select_random_book(_from=Library.AVAILABLE)
    adoption = book.is_using()

    # WHEN: they click on the "Using this book? Let us know." link
    # AND:  select a non-Student role from the drop down menu
    # AND:  fill out the contact form fields
    # AND:  click on the "Next" button
    with pytest.raises(WebException) as error:
        adoption.submit_adoption(user_type=user_type,
                                 first=first_name,
                                 last=last_name,
                                 email=email.address,
                                 phone=phone,
                                 school=school,
                                 books=books)

    # THEN: the book is selected
    # AND:  the using questions for the book are displayed
    assert(short in Utility.get_error_information(error)), \
        '{book} ({short}) not preselected'.format(book=full, short=short)
コード例 #12
0
def test_a_user_may_submit_a_message(web_base_url, selenium):
    """A user may use the contact form to message OpenStax."""
    # GIVEN: a user viewing the contact form page
    topic = Web.TOPICS[Utility.random(end=len(Web.TOPICS) - 1)]
    _, first, last, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{id}'.format(
        first=first, last=last, id=Utility.random_hex(5)).lower())
    email.empty()
    message = chomsky(Utility.random(1, 3))
    home = WebHome(selenium, web_base_url).open()
    contact = home.footer.directory.contact_us()

    # WHEN: they select a question topic from the drop down
    #       menu
    # AND:  enter a name
    # AND:  enter an e-mail address
    # AND:  enter a message
    # AND:  click on the "Send" button
    contact.form.topic = topic
    contact.form.name = '{0} {1}'.format(first, last)
    contact.form.email = email.address
    contact.form.message = message
    confirmation = contact.form.send()

    # THEN: the contact confirmation page is displayed
    # AND:  a "Thank you for contacting OpenStax!" email is
    #       received
    assert (confirmation.is_displayed())
    assert ('confirmation' in confirmation.location)
    ''' auto-emails are disabled in the TutorQA sandbox
    email.wait_for_mail(60)
    assert('Thank you for contacting OpenStax!'
           in email.get_mail[-1].subject)'''

    # WHEN: they click on the "Check out our subjects"
    #       button
    subjects = confirmation.view_subjects()

    # THEN: the subjects page is displayed
    assert (subjects.is_displayed())
    assert ('subjects' in subjects.location)
コード例 #13
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'
コード例 #14
0
def test_interest_form_requires_at_least_one_book_selection(
        web_base_url, selenium):
    """Test at least one book must be selected before submitting the form."""
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    _, first_name, last_name, _ = Utility.random_name()
    email = RestMail('{first}.{last}.{rand}'.format(
        first=first_name, last=last_name, rand=Utility.random_hex(5)).lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'

    # GIVEN: a user viewing the interest page
    interest = Interest(selenium, web_base_url).open()
    if interest.survey.is_displayed():
        interest.survey.close()
    if interest.privacy_notice.is_displayed():
        interest.privacy_notice.got_it()

    # WHEN: they select a non-Student role from the drop down menu
    # AND:  fill out the contact form fields
    # AND:  click on the "Next" button
    # AND:  click on the "Next" button
    with pytest.raises(WebException) as error:
        interest.submit_interest(user_type=user_type,
                                 first=first_name,
                                 last=last_name,
                                 email=email.address,
                                 phone=phone,
                                 school=school,
                                 books=[],
                                 students='',
                                 additional_resources=None,
                                 heard_on=None)

    # THEN: the textbook selection list is still displayed
    # AND:  an error message "Please select at least one book" is displayed
    assert ('Please select at least one book'
            in Utility.get_error_information(error)), (
                'The book error was not displayed')