def should_see_company(response: Response, company_title: str) -> bool: content = extract_page_contents(response.content.decode("utf-8")).lower() no_match = NO_UK_BUSINESS_MATCH.lower() in content contains_company_title = company_title.lower() in content if not contains_company_title: contains_company_title = escape_html(company_title).lower() in content if not contains_company_title: logging.debug( f"Could not find company: '{escape_html(company_title).lower()}'") return contains_company_title and not no_match
def get_profile_links(page_content: str) -> List[tuple]: profile_selector = "#companies-column > ul > li a" profile_links = Selector(text=page_content).css(profile_selector).extract() results = [] for link in profile_links: href = Selector(text=link).css("a::attr(href)").extract()[0] company_title = Selector(text=link).css("h3::text").extract()[0] clean_company_title = escape_html(company_title.replace(" ", " ")).lower() results.append((clean_company_title, href)) return results
def should_see_details(company: Company, response: Response, table_of_details: Table): """Supplier should see all expected Company details of Profile page.""" visible_details = [row["detail"] for row in table_of_details] content = response.content.decode("utf-8") title = DETAILS["NAME"] in visible_details keywords = DETAILS["KEYWORDS"] in visible_details website = DETAILS["WEBSITE"] in visible_details size = DETAILS["SIZE"] in visible_details sector = DETAILS["SECTOR"] in visible_details if title: with assertion_msg( "Couldn't find company's title '%s' in the response", company.title ): assert company.title in content if keywords: for keyword in company.keywords.split(", "): with assertion_msg("Couldn't find keyword '%s' in the response", keyword): assert escape_html(keyword.strip()) in content if website: with assertion_msg( "Couldn't find company's website '%s' in the response", company.website ): assert company.website in content if size: with assertion_msg( "Couldn't find the size of the company '%s' in the response", company.no_employees, ): if company.no_employees == "10001+": assert "10,001+" in content elif company.no_employees == "1001-10000": assert "1,001-10,000" in content elif company.no_employees == "501-1000": assert "501-1,000" in content else: assert company.no_employees in content if sector: with assertion_msg( "Couldn't find company's sector '%s' in the response", SECTORS_WITH_LABELS[company.sector], ): assert SECTORS_WITH_LABELS[company.sector].lower() in content.lower()
def find_profile_link(response: Response, company_title: str) -> str: raw_content = response.content.decode("utf-8") content = extract_page_contents(raw_content).lower() no_match = NO_UK_BUSINESS_MATCH.lower() in content if no_match: logging.warning(NO_UK_BUSINESS_MATCH) return "" profile_links = get_profile_links(raw_content) logging.debug(f"List of found profiles: {profile_links}") clean_company_title = escape_html(company_title.replace(" ", " ")).lower() for title, href in profile_links: if title == clean_company_title: logging.debug( f"Found link to '{clean_company_title}' profile: {href}") return href return ""
def should_not_see_company(response: Response, company_title: str) -> bool: content = extract_page_contents(response.content.decode("utf-8")).lower() return escape_html(company_title).lower() not in content
def should_see_that_message_has_been_sent(company: Company, response: Response): clean_name = escape_html(company.title.replace(" ", " ")) expected = EXPECTED_STRINGS_MESSAGE_SENT + [clean_name] check_response(response, 200, body_contains=expected) logging.debug("Buyer was told that the message has been sent")
def should_be_here(response, *, name=None): extra_strings_to_check = [escape_html(name)] if name else EXPECTED_STRINGS expected = EXPECTED_STRINGS + extra_strings_to_check check_response(response, 200, body_contains=expected) logging.debug("Supplier is on FAS Contact Company page")