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)
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})'
def _course_selection(self, option, value, ignore_case=False, latest=False): """Select a specific or random course matching a particular option. :param str option: the data option to retrieve :param str value: the expected value to match a course against :param bool ignore_case: (optional) match the value in a unicode-safe, case-blind match :param bool latest: (optional) select the newest course :return: the calendar (teacher) or current week (student) page for the selected course :rtype: :py:class:`~pages.tutor.calendar.Calendar` or :py:class:`~pages.tutor.course.StudentCourse` :noindex: """ value = value.casefold() if ignore_case else value course_options = [] for course in self.courses: if value == course._get_data_option(option): course_options.append(course) assert(course_options), \ "No courses found for {0}:{1}".format(option, value) course = 0 if latest else Utility.random(end=len(course_options)) return course_options[course].go_to_course()
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_selecting_a_partner_logo_scrolls_to_the_partner_summary( web_base_url, selenium): """Clicking a partner logo scrolls the page to the partner summary.""" # GIVEN: a user viewing the partners page home = WebHome(selenium, web_base_url).open() partners = home.web_nav.technology.view_partners() logo = partners.companies[Utility.random(end=len(partners.companies) - 1)] summary = partners.summary_by_name(logo.name) # WHEN: they click on a partner logo logo.view() # THEN: the page scrolls until the partner summary is displayed # AND: the summary contains a partner description # AND: supported subjects or books # AND: a "Return to top" link assert (Utility.in_viewport(selenium, element=summary.header, ignore_bottom=True)) assert (summary.description) if summary.name != TechProviders.OPEN_TEXTBOOK_NETWORK: # the partner supports one or more OpenStax titles/subjects assert (summary.availability) assert (summary.return_to_top_link) # WHEN: they click on the "Return to top" link summary.return_to_top() # THEN: the partner filter list is displayed assert (Utility.in_viewport(selenium, element=logo.logo))
def test_supported_topics_link_to_the_subjects_page_or_a_book_details_page( web_base_url, selenium): """Clicking a supported content link loads the subject or book details.""" # GIVEN: a user viewing the partners page home = WebHome(selenium, web_base_url).open() partners = home.web_nav.technology.view_partners() logo = partners.companies[Utility.random(end=len(partners.companies) - 1)] summary = partners.summary_by_name(logo.name) # WHEN: they view a partner summary logo.view() # THEN: "full catalog of content." links to the subjects # page, "mathematics titles" links to the math # subject page, or a collection of book titles # linking to the respective book details page name = summary.name if name in TechProviders.full_catalog: assert(summary.availability[0] .get_attribute('href').endswith('/subjects')), \ '{0} not linked to the Subjects page.'.format(name) elif name in TechProviders.math_titles: assert(summary.availability[0] .get_attribute('href').endswith('/math')), \ '{0} not linked to the Subject math page.'.format(name) elif name in TechProviders.no_titles: assert (not summary.availability) else: assert(summary.availability), \ '{0} missing resource availability'.format(name) for option in summary.availability: assert('/details' in option.get_attribute('href')), \ '{0} not using "/details"'.format(option.text)
def get_date_times(driver: Webdriver, option: Union[str, DateFormat, FullDateTime]) \ -> Tuple[str]: """Return Tutor-ready date and time strings. Take various formats of dates and times for assignment open/due requirements and return Tutor ``send_key``-ready strings. :param option: the requested date/time option for a section :type option: str or tuple(str, str) or tuple(tuple(str, str), tuple(str, str)) or datetime or tuple(datetime, datetime) :return: the list of values (open date, open time, due date, due time); if a time is not needed the time field will be an empty string :rtype: tuple(str) """ # Handle a random date in the future or today if option == Tutor.RANDOM: base_date = driver.find_element(By.CSS_SELECTOR, '[id*="open-date"]') _open = datetime.strptime( '{date} {time}'.format(date=base_date.get_attribute('value'), time='12:01 AM'), '%m/%d/%Y %I:%M %p') _open = _open + timedelta(days=Utility.random(0, 7), minutes=Utility.random(0, 60 * 24 - 2)) _due = _open + timedelta(days=Utility.random(1, 7), minutes=Utility.random(0, 60 * 24)) option = (_open, _due) elif option == Tutor.TODAY: # open now option = datetime.now() # Change from a single option to open and due values if isinstance(option, datetime): open_on = option # Set a random end date if one wasn't included due_on = option + timedelta(days=Utility.random(1, 7)) else: open_on, due_on = option open_on, open_at = to_date_time_string(open_on) due_on, due_at = to_date_time_string(due_on) return (open_on, open_at, due_on, due_at)
def subject_list(size=1): """Return a list of subjects for an elevated signup.""" subjects = len(Accounts.SUBJECTS) if size > subjects: size = subjects book = '' group = [] if Accounts.accounts_old else {} while len(group) < size: book = (Accounts.SUBJECTS[Utility.random(0, subjects - 1)])[1] if book not in group: if Accounts.accounts_old: group.append(book) else: group[book] = { 'status': Accounts.randomized_use(), 'students': Utility.random(), } return group
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)
def test_selecting_a_team_member_opens_their_bio(web_base_url, selenium): """Test clicking on a staff member's card.""" # GIVEN: a user viewing the team page home = WebHome(selenium, web_base_url).open() team = home.web_nav.openstax.view_team() # WHEN: they click on an OpenStax team member with a biography person = team.people[Utility.random(end=len(team.people) - 1)] while (not person.has_bio): person = team.people[Utility.random(end=len(team.people) - 1)] person.select() print(person.name) # THEN: a pop out pane displays the team member's bio assert (person.bio), 'Biography missing' # WHEN: they click on the team member again person.select() # THEN: the pop out pane is closed assert (not person.bio_visible)
def subject_list(size=1): """Return a list of subjects for an elevated signup.""" subjects = len(Accounts.SUBJECTS) if size > subjects: size = subjects book = '' group = [] while len(group) < size: book = (Accounts.SUBJECTS[Utility.random(0, subjects - 1)])[1] if book not in group: group.append(book) return group
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_mobile_users_are_presented_bars(web_base_url, selenium): """On mobile, group tabs are replaced by accordion menus.""" # GIVEN: a user viewing the research page # AND: the screen width is 600 pixels home = WebHome(selenium, web_base_url) home.resize_window(width=600) home.open() home.web_nav.meta.toggle_menu() research = home.web_nav.openstax.view_research() for position, group in enumerate(research.bars): print(position, group.name) # WHEN: they click on the group bar group.toggle() # THEN: the team member tiles are displayed assert (group.is_open) if position == Web.ALUMNI: person = Utility.random(end=len(research.alumni) - 1) research.alumni[person].view() assert (research.alumni[person].is_visible) elif position == Web.CURRENT_MEMBERS: person = Utility.random(end=len(research.team) - 1) research.team[person].view() assert (research.team[person].is_visible) elif position == Web.EXTERNAL_COLLABORATORS: person = Utility.random(end=len(research.external) - 1) research.external[person].view() assert (research.external[person].is_visible) else: assert(False), \ '"{0}" is not a recognized group'.format(group.name) # WHEN: they click on the group bar group.toggle() # THEN: the team member section is closed assert (not group.is_open)
def test_mobile_users_are_presented_bars(web_base_url, selenium): """On mobile, group tabs are replaced by accordion menus.""" # GIVEN: a user viewing the team page # AND: the screen width is 600 pixels home = WebHome(selenium, web_base_url) home.resize_window(width=600) home.open() home.web_nav.meta.toggle_menu() team = home.web_nav.openstax.view_team() for position, group in enumerate(team.bars): print(position, group.name) # WHEN: they click on the group bar group.toggle() # THEN: the team member tiles are displayed assert (group.is_open) if position == Web.OPENSTAX_TEAM: person = Utility.random(end=len(team.people) - 1) team.people[person].view() assert (team.people[person].is_visible) elif position == Web.STRATEGIC_ADVISORS: person = Utility.random(end=len(team.advisors) - 1) team.advisors[person].view() assert (team.advisors[person].is_visible) elif position == Web.ADVISORY_BOARD: person = Utility.random(end=len(team.fab) - 1) team.fab[person].view() assert (team.fab[person].is_visible) else: assert(False), \ '"{0}" is not a recognized group'.format(group.name) # WHEN: they click on the group bar group.toggle() # THEN: the team member section is closed assert (not group.is_open)
def random_answer(self) -> None: """Select a random answer for the question. :return: None :raises: :py:class:`~utils.tutor.TutorException` if no multiple choice answers are available """ sleep(0.25) answers = self.answers if not answers: raise TutorException('No answers found') answers[Utility.random(0, len(answers) - 1)].select() sleep(0.25)
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_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()
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)))
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 select_random_book(self, _from=Library.OPENSTAX, filter_current=False): """Return a random book from the active list.""" using = { Library.ALL_BOOKS: self._active_books, Library.AP: self.ap_books, Library.AVAILABLE: self.available_books, Library.BOOKSHARE: self.bookshare_books, Library.BUSINESS: self.business_books, Library.COMP_COPY: self.comp_copy, Library.CURRENT: self.current_books, Library.HAS_I_LOCK: self.locked_instructor, Library.HAS_I_UNLOCK: self.unlocked_instructor, Library.HAS_S_LOCK: self.locked_student, Library.HAS_S_UNLOCK: self.unlocked_student, Library.HIGH_SCHOOL: self.high_school, Library.HUMANITIES: self.humanities_books, Library.ITUNES: self.itunes_books, Library.KINDLE: self.kindle_books, Library.MATH: self.math_books, Library.OPENSTAX: self.openstax_books, Library.POLISH: self.polish_books, Library.PRINT_COPY: self.print_books, Library.SCIENCE: self.science_books, Library.SOCIAL: self.social_sciences_books, Library.SUPERSEDED: self.old_book_editions, }.get(_from) if filter_current: using = list( filter(lambda book: book.title not in Library.OLD_EDITIONS, using)) total = len(using) if total <= 0: raise WebException('No books are available for selection') book = Utility.random(0, total - 1) selected = using[book] print('Selected book: {0}'.format(selected.title)) destination = selected.url_append selected.select() sleep(1.0) from pages.web.book import Book as Details return go_to_(Details(self.driver, book_name=destination))
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'
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')
def view_post(self, title=None, index=None): """Open a blog entry to view the full article. If no title or index is provided, return a random blog article :param str title: (optional) select an article to view by its title :param int index: (optional) select an article by it list index :return: a blog article :rtype: :py:class:`~pages.web.blog.Article` """ # select an article by its title if title: for article in self.articles: if article.title == title: return article.view() # or select an article by its position with 0 being the newest and n-1 # being the oldest if index: return self.other_posts[index].view() # or select a random article return self.articles[Utility.random(0, len(self.articles) - 1)].view()
def test_verified_instructors_may_access_locked_resources( accounts_base_url, web_base_url, selenium, teacher): """Test verified instructors may access locked resources.""" # GIVEN: a user viewing the book details page # AND: they have a valid instructor login and password # AND: they are not logged into the website # AND: the book has locked instructor resources 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 # AND: click on the "Click here to unlock" link book.select_tab(Web.INSTRUCTOR_RESOURCES) options = book.instructor.resources_by_option(Web.LOCKED) assert(options), 'No locked instructor resources found' option = options[Utility.random(0, len(options) - 1)] option_title = option.title option.select() accounts = AccountsHome(selenium, accounts_base_url) # THEN: the Accounts login 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 log into Accounts accounts.service_log_in(*teacher, Book, web_base_url) # THEN: the instructor resources tab on the book details page is displayed # AND: the resource is no longer locked assert(book.instructor.is_displayed()), \ f'Instructor resources not displayed ({book.location})' option = book.instructor.resource_by_name(option_title) assert(not option.is_locked), \ '{option} is still locked'.format(option=option.title)
def test_random(): """Get a random number between 0 and 50, inclusive, 10 times.""" for _ in range(10): value = Utility.random(0, 50) assert (value >= 0 and value <= 50)
def randomized_use(cls): """Return a random book use.""" return Accounts.USE[Utility.random(0, len(Accounts.USE) - 1)]
def test_verified_instructors_may_request_a_comped_ibook( web_base_url, selenium, teacher): """Test verified instructors may request a complimentary iBook copy.""" # GIVEN: a user viewing the book details page # AND: the book has comp copies available home = WebHome(selenium, web_base_url).open() subjects = home.web_nav.subjects.view_all() book = subjects.select_random_book(_from=Library.COMP_COPY) book.web_nav.login.log_in(*teacher, Book, web_base_url) # WHEN: they click on the "Instructor resources" tab # AND: click on the "iBooks Comp Copy" tile book.select_tab(Web.INSTRUCTOR_RESOURCES) comp_copy = book.instructor.resource_by_name( 'Apple iBooks Comp Copy').select() # THEN: the comp copy modal is displayed assert(comp_copy.is_displayed()), 'Comp copy modal not displayed' # WHEN: they click "Request iBook" comp_copy.submit() # THEN: a "Please enter a number." pop up appears below # the "How many students will be using <book> # this semester?" input box error = comp_copy.get_error() expected_error_messages = [ 'Please enter a number.', 'Please fill out this field.', 'Fill out this field'] assert(error in expected_error_messages), \ f'Unexpected message displayed: {error}' # WHEN: they click on the "Cancel" button comp_copy.cancel() # THEN: the comp copy modal is closed assert(not comp_copy.is_displayed()), \ 'The comp copy modal did not close' # WHEN: they click on the "iBooks Comp Copy" tile # AND: click on the 'X' icon comp_copy = book.instructor.resource_by_name( 'Apple iBooks Comp Copy').select() comp_copy.close() # THEN: the comp copy modal is closed assert(not comp_copy.is_displayed()), \ 'The comp copy modal did not close' # WHEN: they click on the "iBooks Comp Copy" tile # AND: enter a zero or greater number in the input box # AND: click on the "Request iBook" button comp_copy = book.instructor.resource_by_name( 'Apple iBooks Comp Copy').select() comp_copy.students = Utility.random() comp_copy_receipt = comp_copy.submit() # THEN: "Your request was submitted!" is displayed assert('Your request was submitted!' in comp_copy_receipt.text), \ 'The comp copy request confirmation was not shown' # WHEN: they click on the "Close" button comp_copy_receipt.close() # THEN: the comp copy modal is closed assert(not comp_copy_receipt.is_displayed()), \ 'The comp copy modal did not close'