def setup(): crawler = Crawler() with requests_mock.Mocker() as m: m.post(URL.login_url(), text=PostLoginPage.POST_LOGIN_PAGE) crawler.login("username", "password") return crawler
def search(session: Session, login_response, first_name, last_name, middle_name="", birth_date="") -> List[OeciCase]: search_url = URL.search_url() node_response = Crawler._fetch_search_page(session, search_url, login_response) oeci_search_result = Crawler._search_record(session, node_response, search_url, first_name, last_name, middle_name, birth_date) case_limit = 300 if len(oeci_search_result.cases) >= case_limit: raise ValueError( f"Found {len(oeci_search_result.cases)} matching cases, exceeding the limit of {case_limit}. Please add a date of birth to your search." ) else: # Parse search results (case detail pages) with ThreadPoolExecutor(max_workers=50) as executor: oeci_cases: List[OeciCase] = [] for oeci_case in executor.map( partial(Crawler._read_case, session), oeci_search_result.cases): oeci_cases.append(oeci_case) return oeci_cases
def create_ambiguous_record_with_questions( record=JohnDoe.RECORD_WITH_CLOSED_CASES, cases={ "X0001": CaseDetails.case_x(), "X0002": CaseDetails.case_x(), "X0003": CaseDetails.case_x() }, ) -> Tuple[Record, AmbiguousRecord, Dict[str, Question], List[str]]: base_url = "https://publicaccess.courts.oregon.gov/PublicAccessLogin/" with requests_mock.Mocker() as m: m.post(URL.login_url(), text=PostLoginPage.POST_LOGIN_PAGE) m.post("{}{}".format(base_url, "Search.aspx?ID=100"), [{ "text": SearchPageResponse.RESPONSE }, { "text": record }]) for key, value in cases.items(): m.get("{}{}{}".format(base_url, "CaseDetail.aspx?CaseID=", key), text=value) aliases = (Alias(first_name="John", last_name="Doe", middle_name="", birth_date=""), ) return RecordCreator.build_record( RecordCreator.build_search_results.__wrapped__, "username", "password", aliases, {})
def attempt_login(session: Session, username, password) -> str: url = URL.login_url() payload = Payload.login_payload(username, password) response = session.post(url, data=payload) if Crawler._succeed_login(response): return response.text elif "Oregon eCourt is temporarily unavailable due to maintenance" in response.text: raise OECIUnavailable else: raise InvalidOECIUsernamePassword
def setUp(self): self.crawler = Crawler() with requests_mock.Mocker() as m: m.post(URL.login_url(), text=PostLoginPage.POST_LOGIN_PAGE) self.crawler.login('username', 'password')