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'
Exemple #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'
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'
Exemple #4
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'
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')
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)
Exemple #7
0
def test_restmail_received_pin_email(google_signup):
    """Test a RestMail JSON email."""
    # GIVEN: A RestMail address with a verification PIN email
    username = '******'
    email = RestMail(username)
    email.empty()  # clear the message inbox

    send = SendMail(*google_signup, *GOOGLE)
    sender = ('OpenStax QA', '*****@*****.**')
    recipient = ('OpenStax Automation', '*****@*****.**')
    send.send_mail(recipient, sender, TEST_EMAIL_SUBJECT, TEST_EMAIL_BODY)

    # WHEN: Access the rest API
    box = email.get_mail()

    # THEN: Able to retrieve a fake confirmation PIN
    assert(box), 'No emails recovered'
    assert(box[-1].has_pin), 'PIN not found'
Exemple #8
0
    def student_signup(self,
                       first_name: str,
                       last_name: str,
                       password: str,
                       email: RestMail = None,
                       page: Page = None,
                       base_url: str = None) -> Page:
        """Register a new student user.

        :param str first_name: the user's first name
        :param str last_name: the user's last name
        :param str password: the user's selected password
        :param email: (optional) a provided RestMail address; if one is not
            given, an automatically generated one will be used
        :type email: :py:class:`~utils.email.RestMail`
        :param page: (optional) the expected page return
        :type page: :py:class:`~pypom.Page`
        :param str base_url: the template base URL for the returned page
        :return: the sign up page if there is an error, the user profile if the
            user signed up from Accounts, or the originating page if redirected
            from another OpenStax product
        :rtype: :py:class:`~pypom.Page`

        """
        sign_up = self.content.view_sign_up()
        student_signup = sign_up.content.sign_up_as_a_student().content
        student_signup.first_name = first_name
        student_signup.last_name = last_name
        if not email:
            email_user = (
                f'{first_name}.{last_name}.'
                f'{Utility.random_hex(Utility.random(3, 7))}').lower()
            email = RestMail(email_user)
        student_signup.email = email.address
        student_signup.password = password
        student_signup.i_agree()
        confirm_email = student_signup._continue().content
        box = email.wait_for_mail()
        pin = box[-1].pin
        confirm_email.pin = pin
        complete_signup = confirm_email.confirm_my_account().content.finish()
        if page:
            return go_to_(page(self.driver, base_url=base_url))
        return complete_signup
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)
Exemple #10
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'
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})'
Exemple #12
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'
Exemple #13
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))
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'
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)
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')
Exemple #17
0
    def account_signup(self,
                       email,
                       password=None,
                       role=Accounts.STUDENT,
                       provider=Accounts.RESTMAIL,
                       destination=None,
                       base_url=None,
                       **kwargs):
        """Single signup entry point."""
        import pprint
        pprint.PrettyPrinter(indent=2, width=140).pprint(kwargs)
        # branching prep
        non_student_role = role != Accounts.STUDENT
        instructor = role == Accounts.INSTRUCTOR

        # select the user type and initial email for verification
        self.sign_up.role = role
        self.sign_up.email = email
        self.sign_up.next()
        error = self.sign_up.email_error
        assert (not error), '{0}'.format(error)
        if non_student_role and not email.endswith('edu'):
            self.sign_up.next()

        # verify the email using the assigned pin number
        not_verified = True
        pause = 0.25
        while not_verified:
            email_password = None
            if provider == Accounts.RESTMAIL:
                account_name = email[:email.rfind('@')]
                mailer = RestMail(account_name)
            elif provider == Accounts.GOOGLE:
                pin = (GmailReader(
                    email[0:7]).read_mail().sort_mail().latest.get_pin)
                email_password = kwargs.get('email_password')
            elif provider == Accounts.GUERRILLA_MAIL:
                mailer = GuerrillaMail(self.driver)
            else:
                from utils.email import EmailVerificationError
                raise EmailVerificationError(
                    '{0} is not an accepted email provider'.format(provider))
            if provider != Accounts.GOOGLE:
                pin = self._get_pin(page=mailer,
                                    provider=provider,
                                    return_url=self.seed_url + '/verify_email',
                                    email=email,
                                    password=email_password)
            if not pin:
                raise ValueError('PIN not found')
            self.pin_verification.clear_pin()
            self.pin_verification.verify_pin = pin
            self.pin_verification.confirm()
            sleep(pause)
            error = self.pin_verification.pin_error
            if not error:
                not_verified = False
        assert (not error), '{0}'.format(error)

        # set the account password or social login
        if 'social' not in kwargs:
            # use a password
            self.password.password = password
            self.password.confirmation = password
            self.password.submit()
            errors = self.password.password_errors
            assert (not errors), '{0}'.format(' '.join(errors))
        elif kwargs.get('social') == Accounts.FACEBOOK:
            # use Facebook
            (self.password.use_social_login().user_facebook.log_in(
                kwargs.get('social_login'), kwargs.get('social_password')))
            sleep(3)
        else:
            # use Google
            (self.password.use_social_login().use_google.log_in(
                kwargs.get('social_login'), kwargs.get('social_password')))
            sleep(3)
        self.wait.until(
            lambda _: 'accounts' in urlparse(self.driver.current_url).netloc)

        # enter the first page profile information
        sleep(2)
        if 'social' not in kwargs:
            _, first, last, _ = kwargs.get('name')
            self.profile.first_name = first
            self.profile.last_name = last
        if non_student_role:
            self.profile.phone_number = kwargs.get('phone')
        self.profile.school_name = kwargs.get('school')
        if non_student_role:
            self.profile.webpage = kwargs.get('webpage')
            use = kwargs.get('use')
            self.profile.using_openstax(use)
        self.profile.next()

        # enter the second page courseware information
        if non_student_role:
            subjects = kwargs.get('subjects', {})
            subjects_to_select = []
            for subject, name in Accounts.SUBJECTS:
                if name in subjects:
                    subjects_to_select.append(name)
            if subjects_to_select:
                self.courseware.select_subjects(subjects_to_select)
                self.courseware.set_using(subjects)
        if instructor and use == Accounts.RECOMMENDED:
            self.courseware.students = kwargs.get('students')
        if not kwargs.get('news'):
            self.courseware.no_newsletter()
        self.courseware.agree_to_policies()
        self.courseware.create_account()
        errors = self.profile.profile_errors
        assert (not errors), '{0}'.format(' '.join(errors))
        error = self.courseware.book_error
        assert (not error), '{0}'.format(error)

        # register for a confirmation upon approval
        if non_student_role:
            if kwargs.get('access_notice'):
                self.instructor_access.receive_instructor_access_notice()
            self.instructor_access.ok()

        # return to submitted destination
        if destination:
            return go_to_(destination(self.driver, base_url=base_url))
        # or the user's new profile
        from pages.accounts.profile import Profile
        return go_to_(Profile(self.driver, self.base_url))