コード例 #1
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')
コード例 #2
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)
コード例 #3
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'
コード例 #4
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})'
コード例 #5
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'
コード例 #6
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'
コード例 #7
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)
コード例 #8
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')
コード例 #9
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))