Ejemplo n.º 1
0
def test_random_name():
    """Test the random name generator list."""
    for _ in range(25):
        name = Utility.random_name()
        assert (len(name) == 4), 'Incorrect length'
        assert (len(name[1]) > 0), 'Missing first name'
        assert (len(name[2]) > 0), 'Missing last name'
    name = Utility.random_name(is_male=True)
    assert (len(name) == 4), 'Incorrect length'
    assert (len(name[1]) > 0), 'Missing first name'
    assert (len(name[2]) > 0), 'Missing last name'
    name = Utility.random_name(is_female=True)
    assert (len(name) == 4), 'Incorrect length'
    assert (len(name[1]) > 0), 'Missing first name'
    assert (len(name[2]) > 0), 'Missing last name'
Ejemplo n.º 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'
Ejemplo n.º 3
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')
Ejemplo n.º 4
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)
Ejemplo n.º 5
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'
Ejemplo n.º 6
0
def test_non_students_may_fill_out_the_form(web_base_url, selenium):
    """Test non-students may fill out and submit the interest 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(
        f'{first_name}.{last_name}.{Utility.random_hex(3)}'.lower())
    phone = Utility.random_phone(713, False)
    school = 'Automation'
    books = Library().random_book(Utility.random(start=2, end=5))
    students = Utility.random(Web.STUDENT_MIN, Web.STUDENT_MAX)
    tech_providers = TechProviders.get_tech(Utility.random(0, 3))
    other = 'Another product provider' \
        if TechProviders.OTHER in tech_providers else None

    # 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:  select a book subject
    # AND:  enter a number of students
    # AND:  select zero to three partner options
    # AND:  select zero to eight "How did you hear?" options
    # AND:  click on the "Next" button
    # AND:  select zero or more technology options
    # AND:  click on the "Submit" button
    partners = 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(),
                                        tech_providers=tech_providers,
                                        other_provider=other)

    # THEN: the partners page is displayed
    assert(partners.is_displayed()), \
        'Partners page not displayed'
    assert('partners' in partners.location), \
        f'Not at the interest confirmation page ({partners.location})'
Ejemplo n.º 7
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'
Ejemplo n.º 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'
Ejemplo n.º 9
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'
Ejemplo n.º 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'
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'
Ejemplo n.º 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')
Ejemplo n.º 15
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))