def become_user(self): """Impersonate the user.""" become = self.find_element(*self._become_user_locator) Utility.click_option(self.driver, element=become) self.driver.switch_to_alert.accept() sleep(1.0) from pages.accounts.profile import Profile profile = Profile(self.driver, self.base_url) profile.open() return profile
def impersonate(self): """Log in as the user.""" impersonate = self.find_element(*self._impersonate_locator) Utility.click_option(self.driver, element=impersonate) self.driver.switch_to_alert().accept() sleep(1.0) from pages.accounts.profile import Profile profile = Profile(self.driver, self.page.base_url) profile.open() sleep(10) return profile
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 _continue(self, previous: Page = None, base_url: str = None, **kwargs) \ -> Page: """Click the Continue button. :param Page previous: (optional) the Page object for the initial page that sent the log in request :param str base_url: (optional) the base URL for the previous Page :param kwargs: (optional) additional keyword arguments for the Page :return: the log in page if there is an error, the profile page if remaining on Accounts, the terms of use or privacy policy if a new policy is available, or the previous page if logging on to another OpenStax resource (like Tutor or OpenStax.org) :rtype: :py:class:`~pypom.Page` """ current_page = self.page.location button = self.find_element(*self._continue_button_locator) Utility.click_option(self.driver, element=button) sleep(0.75) if self.driver.current_url == current_page: raise AccountsException( self.driver.execute_script( 'return document.querySelector(".invalid-message")' '.textContent;')) if previous: return go_to_(previous(self.driver, base_url, **kwargs)) source = self.driver.page_source policies = 'Terms of Use' in source or 'Privacy policy' in source if 'accounts' in self.page.location and policies: from pages.accounts.legal import AcceptTerms return go_to_(AcceptTerms(self.driver, self.page.base_url)) return go_to_(Profile(self.driver, self.page.base_url))
def log_in(self) -> Page: """Click the 'Log in' button. :return: the change password page if an error occurs or the user profile if the new password is accepted :rtype: :py:class:`~pages.accounts.reset.ChangePassword` or :py:class:`~pages.accounts.profile.Profile` """ button = self.find_element(*self._log_in_button_locator) Utility.click_option(self.driver, element=button) sleep(0.25) if 'password' in self.driver.current_url: return self.page from pages.accounts.profile import Profile return go_to_(Profile(self.driver, base_url=self.page.base_url))
def i_agree(self) -> Page: """Click the 'I AGREE' button. :return: the user's profile, another policy accept page, or the redirect back to the page that preceded the log in :rtype: :py:class:`~pypom.Page` """ another_contract = '&terms' in self.driver.current_url base_url = self.page.base_url button = self.find_element(*self._i_agree_button_locator) Utility.click_option(self.driver, element=button) if another_contract: return go_to_(AcceptTerms(self.driver, base_url=base_url)) sleep(1.0) if 'profile' in self.driver.current_url: from pages.accounts.profile import Profile return go_to_(Profile(self.driver, base_url=base_url)) return Page(self.driver)
def close_console(self): """Close the admin console and return to Accounts.""" close = self.find_element(*self._console_exit_link_locator) Utility.click_option(self.driver, element=close) from pages.accounts.profile import Profile return go_to_(Profile(self.driver))
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))