예제 #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_interest_form_identity_fields_are_required(web_base_url, selenium):
    """Test interest form identity input fields are required."""
    # GIVEN: a user viewing the interest page
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]
    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:  click on the "Next" button
    with pytest.raises(WebException) as error:
        interest.submit_interest(user_type=user_type,
                                 first='',
                                 last='',
                                 email='',
                                 phone='',
                                 school='',
                                 books='',
                                 students='',
                                 additional_resources=None,
                                 heard_on='')

    # THEN: the contact form fields are shaded red
    # AND:  "Please fill out this field." is below each
    #       contact form field input box
    browser = selenium.capabilities.get('browserName').lower()
    expected_error = (': {browser_front}ill out this field'.format(
        browser_front='F' if browser == 'safari' else 'Please f'))
    data_issues = Utility.get_error_information(error)
    first = ('first_name' + expected_error) in data_issues
    last = ('last_name' + expected_error) in data_issues
    email = ('email' + expected_error) in data_issues
    phone = ('phone' + expected_error) in data_issues
    school = ('school' + expected_error) in data_issues
    assert (first and last and email and phone
            and school), ('Errors not all shown: '
                          f'{"First name  " if first else ""}'
                          f'{"Last name  " if last else ""}'
                          f'{"Email  " if email else ""}'
                          f'{"Phone  " if phone else ""}'
                          f'{"School" if school else ""}').strip()
예제 #3
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'
예제 #4
0
def test_adoption_form_identity_fields_are_required(web_base_url, selenium):
    """Test for error messages for all identification fields."""
    # SETUP:
    user_type = Web.USERS[Utility.random(1, len(Web.USERS) - 1)]

    # GIVEN: a user viewing the adoption 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 select a non-Student role from the drop down menu
    # AND:  click on the "Next" button
    with pytest.raises(WebException) as error:
        adoption.submit_adoption(user_type=user_type,
                                 first='',
                                 last='',
                                 email='',
                                 phone='',
                                 school='',
                                 books={})

    # THEN: the contact form fields are shaded red
    # AND:  "Please fill out this field." is below each
    #       contact form field input box
    browser = selenium.capabilities.get('browserName').lower()
    expected_error = (': {browser_front}ill out this field'.format(
        browser_front='F' if browser == 'safari' else 'Please f'))
    data_issues = Utility.get_error_information(error)
    first = ('first_name' + expected_error) in data_issues
    last = ('last_name' + expected_error) in data_issues
    email = ('email' + expected_error) in data_issues
    phone = ('phone' + expected_error) in data_issues
    school = ('school' + expected_error) in data_issues
    assert (first and last and email and phone
            and school), ('Errors not all shown:\n{errors}\n'.format(
                errors=data_issues)(
                    '{first} {last} {email} {phone} {school}'.format(
                        first=first,
                        last=last,
                        email=email,
                        phone=phone,
                        school=school)))
예제 #5
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)
예제 #6
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')