def should_see_profile_is_not_verified(response: Response, *, ch_company: bool = True): if ch_company: expected = EXPECTED_STRINGS + EXPECTED_STRINGS_NOT_VERIFIED else: expected = EXPECTED_STRINGS + EXPECTED_STRINGS_REQUEST_VERIFICATION check_response(response, 200, body_contains=expected) logging.debug("Supplier is on Unverified Company's Profile page")
def should_be_here(response: Response, *, have_collaborators: bool = True): if have_collaborators: check_response(response, 200, body_contains=EXPECTED_STRINGS) else: check_response(response, 200, body_contains=EXPECTED_STRINGS_NO_COLLABORATORS)
def create_test_isd_company(context: Context) -> dict: """Creates an unpublished test ISD company""" response = DIRECTORY_TEST_API_CLIENT.post( "testapi/isd_company/", authenticator=BASIC_AUTHENTICATOR) context.response = response check_response(response, 201) return response.json()
def should_be_here( response: Response, *, user_added: bool = False, owner_transferred: bool = False, user_removed: bool = False, ): """Check if Supplier is on Profile 'Find a Buyer' page. NOTE: Supplier has to be logged in to get to this page. """ check_response(response, 200, body_contains=EXPECTED_STRINGS) expected_query = None expected_strings = None if user_added: expected_query = "?user-added" expected_strings = EXPECTED_STRINGS_USER_ADDED if owner_transferred: expected_query = "?owner-transferred" expected_strings = EXPECTED_STRINGS_OWNER_TRANSFERRED if user_removed: expected_query = "?user-removed" expected_strings = EXPECTED_STRINGS_USER_REMOVED if expected_strings: error = (f"Expected to see '{expected_query}' in the URL but got: " f"'{response.url}' instead") with assertion_msg(error): assert expected_query in response.url check_response(response, 200, body_contains=expected_strings) logging.debug("Successfully got to the Profile 'Find a Buyer' page")
def should_be_here(response: Response): check_url(response, URL) check_response( response, 200, body_contains=EXPECTED_STRINGS, unexpected_strings=UNEXPECTED_STRINGS, )
def should_be_here(response: Response, *, invitation_sent: bool = False): check_response(response, 200, body_contains=EXPECTED_STRINGS) expected_strings = None if invitation_sent: expected_strings = EXPECTED_STRINGS_INVITATION_SENT if expected_strings: check_response(response, 200, body_contains=expected_strings)
def flag_sso_account_as_verified(context: Context, email_address: str): response = SSO_TEST_API_CLIENT.patch( url=f"testapi/user-by-email/{email_address}/", data={"is_verified": True}, authenticator=BASIC_AUTHENTICATOR, ) context.response = response check_response(response, 204) logging.debug(f"Account for {email_address} was flagged as verified")
def get_published_companies(context: Context) -> list: """Get a List of dicts with published companies. :return: a list of dictionaries with published companies """ response = DIRECTORY_TEST_API_CLIENT.get(url=url_published_companies, authenticator=BASIC_AUTHENTICATOR) context.response = response check_response(response, 200) return response.json()
def verify_non_ch_company(context: Context, company: Company): """Verify company which requested manual verification.""" url = URLs.DIR_API_TEST_API_COMPANY.absolute_template.format( ch_id_or_name=company.title) data = {"verified_with_identity_check": True} context.response = DIRECTORY_TEST_API_CLIENT.patch( url, data, authenticator=BASIC_AUTHENTICATOR) check_response(context.response, 204) logging.debug( f"Successfully flagged '{company.title}' as verified with identity check" )
def is_verification_letter_sent(context: Context, company_number: str) -> bool: """Check if verification letter was sent. :return: True if letter was sent and False if it wasn't """ response = DIRECTORY_TEST_API_CLIENT.get( url=url_company_by_ch_id.format(companies_house_number=company_number), authenticator=BASIC_AUTHENTICATOR, ) context.response = response check_response(response, 200) result = response.json()["is_verification_letter_sent"] return result
def get_verification_code(context: Context, company_number: str): """Will get the verification code (sent by post) for specified company. :return: verification code sent by post """ response = DIRECTORY_TEST_API_CLIENT.get( url=url_company_by_ch_id.format(companies_house_number=company_number), authenticator=BASIC_AUTHENTICATOR, ) context.response = response check_response(response, 200) verification_code = response.json()["letter_verification_code"] logging.debug(f"GET verification code: {response.json()}") return verification_code
def get_published_companies_with_n_sectors(context: Context, number_of_sectors: int) -> list: """Get a List of published companies with at least N associated sectors. :return: a list of dictionaries with matching published companies """ params = {} if number_of_sectors: params['"minimal_number_of_sectors"'] = number_of_sectors response = DIRECTORY_TEST_API_CLIENT.get(url=url_published_companies, params=params, authenticator=BASIC_AUTHENTICATOR) context.response = response check_response(response, 200) return response.json()
def should_be_here( response: Response, *, profile_building: bool = False, letter_verification: bool = False ): """Check if Supplier is on FAB Confirm your Identity page. :param profile_building: (optional) if True, then it will look for specific strings displayed when building company's profile :param letter_verification: (optional) if True, then it will look for specific strings displayed when verifying the identity with a code from a letter :param response: response object """ expected = copy(EXPECTED_STRINGS) if profile_building: expected += EXPECTED_STRINGS_DURING_PROFILE_BUILDING if letter_verification: expected += EXPECTED_STRINGS_WHILE_LETTER_VERIFICATION check_response(response, 200, body_contains=expected) logging.debug("Successfully got to the FAB Confirm your Identity page")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the International - Landing page")
def should_be_here(response: Response): check_url(response, URL, startswith=False) check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug( "Successfully got to the FAB Confirm your collaboration page")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug( "Supplier is on 'Create case study or project' - images page")
def should_see_no_results(response: Response, *, term: str = None): expected = ENTER_SEARCH_TERM_OR_USE_FILTERS if term: expected += term check_response(response, 200, body_contains=expected)
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the Domestic - Home page")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the SSO Verify your email page")
def should_see_no_matches(response: Response, *, term: str = None): expected = NO_MATCH if term: expected += term check_response(response, 200, body_contains=expected)
def should_not_see_options_to_manage_users(response: Response): check_response(response, 200, unexpected_strings=MANAGE_USER_ACCOUNTS_STRINGS) logging.debug("User can't see options to manage FAB profile user accounts")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the SSO Registration page")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the FAB Upload Logo page")
def should_see_errors(response): check_response(response, 200, body_contains=EXPECTED_STRINGS_ERRORS) logging.debug("Buyer was presented with Feedback submission errors.")
def should_be_here(response, *, number=None): expected = EXPECTED_STRINGS + [number] if number else EXPECTED_STRINGS check_response(response, 200, body_contains=expected) logging.debug("Buyer is on the ISD Find a UK Supplier page")
def should_be_here(response: Response): check_url(response, URL, startswith=True) check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the Profile About page")
def should_be_here(response: Response): check_url(response, URL) check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Supplier is on FAS Tech Industry page")
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Got to the SSO Invalid Password Reset Link page")
def should_be_here(response: Response): check_url(response, URL) check_response(response, 200, body_contains=EXPECTED_STRINGS)
def should_be_here(response: Response): check_response(response, 200, body_contains=EXPECTED_STRINGS) logging.debug("Successfully got to the SSO Change Password page")