def generic_should_see_prepopulated_fields(context: Context, actor_alias: str, table: Table): table.require_columns(["form", "fields"]) expected_form_fields = { row.get("form"): [field.strip() for field in row.get("fields").split(",") if field] for row in table } error = f"Expected to check at least 1 list of form fields but got 0" assert expected_form_fields, error actor = get_actor(context, actor_alias) page = get_last_visited_page(context, actor_alias) field_values_to_check = {} for form_name, fields in expected_form_fields.items(): form_page_object = get_page_object(form_name) form_full_page_name = get_full_page_name(form_page_object) submitted_form_data = actor.forms_data[form_full_page_name] for field in fields: field_values_to_check[field] = submitted_form_data[field] logging.debug( f"Will check if form on '{get_full_page_name(page)}' is populated with " f"following values: {field_values_to_check}") has_action(page, "check_if_populated") page.check_if_populated(context.driver, field_values_to_check)
def erp_should_see_correct_data_on_summary_page(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) take_screenshot(context.driver, "should_see_correct_data_on_summary_page") erp.summary.should_see_correct_data_on_summary_page( context.driver, actor.forms_data) logging.debug( f"{actor_alias} saw: all expected data on the ERP Summary page")
def hpo_should_receive_enquiry_confirmation_email(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) get_email_confirmations_with_matching_string( recipient_email=actor.email, subject=HPO_ENQUIRY_CONFIRMATION_SUBJECT, strings=HPO_PDF_URLS, )
def forms_confirmation_email_should_not_be_sent(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) submissions = find_form_submissions(actor.email) assert submissions, f"No form submissions found for {actor_alias}" error = ( f"Expected to find an unsent submission for {actor_alias} but found a sent" f" one. Check spam filters") assert not submissions[0]["is_sent"], error
def generic_contact_us_should_receive_confirmation_email_containing_message( context: Context, actor_alias: str, subject: str, message: str): actor = get_actor(context, actor_alias) confirmation = get_email_confirmations_with_matching_string( recipient_email=actor.email, subject=subject, strings=[message]) assert confirmation logging.debug( f"Found an email notification containing expected message: '{message}' send to " f"{actor.email}")
def hpo_agent_should_receive_enquiry_email(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) logging.debug( f"Looking for a notification sent to HPO agent: {HPO_AGENT_EMAIL_ADDRESS}" ) get_email_confirmations_with_matching_string( recipient_email=HPO_AGENT_EMAIL_ADDRESS, subject=HPO_AGENT_EMAIL_SUBJECT, strings=[actor.email] + HPO_PDF_URLS, )
def soo_contact_form_should_be_prepopulated(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) page = get_last_visited_page(context, actor_alias) form_po = profile.enrol_enter_your_business_details_step_2 form_data_key = f"{form_po.SERVICE} - {form_po.NAME} - {form_po.TYPE}" form_data = actor.forms_data[form_data_key] has_action(page, "check_if_populated") page.check_if_populated(context.driver, form_data)
def erp_should_receive_email_with_link_to_restore_saved_progress( context: Context, actor_alias: str): avoid_browser_stack_idle_timeout_exception(context.driver) actor = get_actor(context, actor_alias) link = get_verification_link(actor.email, subject=EMAIL_ERP_PROGRESS_SAVED_MSG_SUBJECT) with assertion_msg( f"Could not find an email with link to restore saved progress"): assert link update_actor(context, actor_alias, saved_progress_link=link)
def generic_contact_us_should_receive_confirmation_email( context: Context, actor_alias: str, subject: str, *, service: str = None): avoid_browser_stack_idle_timeout_exception(context.driver) actor = get_actor(context, actor_alias) confirmation = get_email_confirmation_notification(email=actor.email, subject=subject, service=service) assert confirmation
def fas_buyer_should_be_signed_up_for_email_updates(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) response = DIRECTORY_TEST_API_CLIENT.get( f"testapi/buyer/{actor.email}/", authenticator=BASIC_AUTHENTICATOR, ) with assertion_msg( f"Expected 200 OK but got {response.status_code} from {response.url}" ): assert response.status_code == 200 assert response.json()["email"] == actor.email assert response.json()["name"] == actor.alias assert response.json()["company_name"] == "AUTOMATED TESTS" logging.debug(f"{actor_alias} successfully signed up for email updates. " f"Here's Buyer's data: {response.json()}")
def generic_a_notification_should_be_sent(context: Context, actor_alias: str, action: str, subject: str): actor = get_actor(context, actor_alias) submissions = find_form_submissions_by_subject_and_action( email=actor.email, subject=subject, action=action) logging.debug(f"Email submissions from '{actor.email}': {submissions}") error = ( f"Expected to find 1 '{action}' notification entitled '{subject}' sent to " f"'{actor.email}', but found {len(submissions)}") assert len(submissions) == 1, error if not submissions[0]["is_sent"]: message = ( f"A '{action}' notification entitled '{subject}' was NOT sent to " f"'{actor.email}' yet!") logging.warning(message) blue(message)
def generic_a_notification_should_be_sent_to_specific_dit_office( context: Context, actor_alias: str, mailbox_name: str): actor = get_actor(context, actor_alias) mailbox_email = FORMS_API_MAILBOXES[mailbox_name] submissions = find_form_submissions_for_dit_office(mailbox=mailbox_email, sender=actor.email) logging.debug( f"Email submissions from '{actor.email}' to '{mailbox_email}': {submissions}" ) error = ( f"Expected to find 1 notification sent to '{mailbox_email}' about contact " f"enquiry from {actor.email}, but found {len(submissions)}") assert len(submissions) == 1, error error = ( f"A notification about enquiry from '{actor.email}' was NOT sent to " f"{mailbox_name} mailbox: '{mailbox_email}'!") assert submissions[0]["is_sent"], error logging.debug( f"A notification about enquiry from {actor.email} was successfully sent to " f"{mailbox_name} mailbox: {mailbox_email}")
def generic_a_notification_should_not_be_sent_to_specific_dit_office( context: Context, actor_alias: str, mailbox_name: str): actor = get_actor(context, actor_alias) forms_data = actor.forms_data uuid = None for data in forms_data.values(): if "full name" in data: uuid = data["full name"] break if "family name" in data: uuid = data["family name"] break if "last name" in data: uuid = data["last name"] break if "lastname" in data: uuid = data["lastname"] break assert uuid, f"Could not find last name UUID in user's form data: {forms_data}" mailbox_email = FORMS_API_MAILBOXES[mailbox_name] submissions = find_form_submissions_for_dit_office(mailbox=mailbox_email, sender=actor.email, uuid=uuid) logging.debug( f"Email submissions from '{actor.email}' to '{mailbox_email}': {submissions}" ) error = ( f"Expected to find at least 1 notification sent to '{mailbox_email}' about " f"contact enquiry from blocked email address: {actor.email}, but found " f"{len(submissions)}") assert len(submissions) >= 1, error error = ( f"An unnecessary notification about enquiry from '{actor.email}' was sent to " f"'{mailbox_name}': '{mailbox_email}'!") assert not submissions[0]["is_sent"], error logging.debug( f"Unfortunately a notification about enquiry from {actor.email} was sent to " f"{mailbox_name} mailbox: {mailbox_email}")