def fab_should_not_see_collaborator( context: Context, supplier_alias: str, collaborators_aliases: str ): aliases = [alias.strip() for alias in collaborators_aliases.split(",")] supplier = get_actor(context, supplier_alias) response = fab.account_remove_collaborator.go_to(supplier.session) context.response = response for collaborator_alias in aliases: collaborator = get_actor(context, collaborator_alias) fab.account_remove_collaborator.should_not_see_collaborator( response, collaborator.email )
def fas_supplier_should_receive_message_from_buyer( context: Context, supplier_alias: str, buyer_alias: str ): buyer = get_actor(context, buyer_alias) supplier = get_actor(context, supplier_alias) context.response = get_email_notification( from_email=buyer.email, to_email=supplier.email, subject=FAS_MESSAGE_FROM_BUYER_SUBJECT, ) logging.debug( f"{supplier_alias} received a notification about a message from {buyer_alias}" )
def fas_should_see_different_png_logo_thumbnail(context: Context, actor_alias: str): """Will check if Company's Logo visible on FAS profile page is the same as the one uploaded on FAB. """ actor = get_actor(context, actor_alias) session = actor.session company = get_company(context, actor.company_alias) fas_logo_url = company.logo_url # Step 1 - Go to the FAS profile page & extract URL of visible logo image response = fas.profile.go_to(session, company.number) context.response = response fas.profile.should_be_here(response) visible_logo_url = extract_logo_url(response) placeholder = FAS_LOGO_PLACEHOLDER_IMAGE with assertion_msg( "Expected company logo but got image placeholder", visible_logo_url ): assert visible_logo_url != placeholder with assertion_msg( "Expected to see other logo thumbnail than the previous one '%s'.", visible_logo_url, ): assert visible_logo_url != fas_logo_url with assertion_msg("Expected PNG logo thumbnail, but got: %s", visible_logo_url): assert visible_logo_url.lower().endswith(".png")
def sso_should_be_signed_out_from_sso_account(context: Context, supplier_alias: str): """Sign out from SSO.""" actor = get_actor(context, supplier_alias) session = actor.session # Step 1 - Get to the Sign Out confirmation page next_param = URLs.PROFILE_LANDING.absolute response = sso.logout.go_to(session, next_param=next_param) context.response = response # Step 2 - check if Supplier is on Log Out page & extract CSRF token sso.logout.should_be_here(response) token = extract_csrf_middleware_token(response) update_actor(context, supplier_alias, csrfmiddlewaretoken=token) # Step 3 - log out next_param = URLs.PROFILE_LANDING.absolute response = sso.logout.logout(session, token, next_param=next_param) context.response = response # Step 4 - check if Supplier is on SSO landing page profile.about.should_be_here(response) profile.about.should_be_logged_out(response) # Step 5 - reset requests Session object reset_actor_session(context, supplier_alias)
def reg_should_get_verification_email( context: Context, alias: str, *, subject: str = None ): """Will check if the Supplier received an email verification message.""" logging.debug("Looking for an email verification message...") actor = get_actor(context, alias) link = get_verification_link(actor.email, subject=subject) update_actor(context, alias, email_confirmation_link=link)
def sud_should_see_options_to_manage_users(context: Context, actor_alias: str): actor = get_actor(context, actor_alias) session = actor.session context.response = profile.business_profile.go_to(session) profile.business_profile.should_be_here(context.response) profile.business_profile.should_see_options_to_manage_users(context.response) logging.debug("%s can see options to control user accounts", actor_alias)
def profile_should_get_request_for_becoming_owner( context: Context, new_owner_alias: str, company_alias: str ): actor = get_actor(context, new_owner_alias) company = get_company(context, company_alias) subject = PROFILE_INVITATION_MSG_SUBJECT.format(company_title=company.title.upper()) link = get_verification_link(actor.email, subject=subject) update_actor( context, new_owner_alias, ownership_request_link=link, company_alias=company_alias, )
def profile_should_see_company_details( context: Context, supplier_alias: str, page_name: str ): actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) page = get_page_object(page_name) has_action(page, "go_to") has_action(page, "should_see_details") if "company_number" in inspect.getfullargspec(page.go_to).args: context.response = page.go_to(actor.session, company_number=company.number) else: context.response = page.go_to(actor.session) page.should_see_details(company, context.response, context.table) logging.debug(f"{supplier_alias} can see all expected details on {page_name}")
def fas_check_profiles(context: Context, supplier_alias: str): actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) # Step 1 - go to company's profile page on FAS response = fas.profile.go_to(actor.session, company.number) context.response = response fas.profile.should_be_here(response) # Step 2 - check if links to online profile are visible fas.profile.should_see_online_profiles(company, response) logging.debug( "%s can see all expected links to Online Profiles on " "FAS Company's Directory Profile Page", supplier_alias, )
def fas_should_see_all_case_studies(context: Context, supplier_alias: str): """Check if Supplier can see all case studies on FAS profile page.""" actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) response = fas.profile.go_to(actor.session, company.number) context.response = response fas.profile.should_be_here(response) case_studies = get_company(context, actor.company_alias).case_studies fas.profile.should_see_case_studies(case_studies, response) logging.debug( "%s can see all %d Case Studies on FAS Company's " "Directory Profile Page", supplier_alias, len(case_studies), )
def should_not_be_able_to_access_page( context: Context, collaborator_alias: str, page_name: str ): collaborator = get_actor(context, collaborator_alias) page_object = get_page_object(page_name) response = page_object.go_to(collaborator.session) try: page_object.should_be_here(response) raise Exception("%s was able to access '%' page", collaborator_alias, page_name) except AssertionError: logging.debug( "As expected %s could not access '%s' page. Current URL is: %s", collaborator_alias, page_name, response.url, )
def sud_should_not_see_options_to_manage_users(context: Context, actor_alias: str): """ Due to bug ED-2268 the first time you visit SUD pages by going directly to SUD "Find a Buyer" page, then you're redirected to SUD "About" page To circumvent this behaviour we have to go to the "About" page first, and then visit the SUD "Find a Buyer" page """ actor = get_actor(context, actor_alias) session = actor.session context.response = profile.about.go_to(session, set_next_page=False) profile.about.should_be_here(context.response) context.response = profile.business_profile.go_to(session) profile.business_profile.should_be_here(context.response) profile.business_profile.should_not_see_options_to_manage_users(context.response) logging.debug("%s can't see options to control user accounts", actor_alias)
def sso_should_get_request_for_collaboration_email( context: Context, actor_aliases: str, company_alias: str ): actor_aliases = [alias.strip() for alias in actor_aliases.split(",")] for actor_alias in actor_aliases: actor = get_actor(context, actor_alias) company = get_company(context, company_alias) subject = PROFILE_INVITATION_MSG_SUBJECT.format( company_title=company.title.upper() ) link = get_verification_link(actor.email, subject=subject) update_actor( context, actor_alias, invitation_for_collaboration_link=link, company_alias=company_alias, )
def fas_supplier_cannot_be_found_using_case_study_details( context: Context, buyer_alias: str, company_alias: str, case_alias: str ): actor = get_actor(context, buyer_alias) session = actor.session company = get_company(context, company_alias) case_study = company.case_studies[case_alias] keys = SEARCHABLE_CASE_STUDY_DETAILS search_terms = {} for key in keys: if key == "keywords": for index, keyword in enumerate(case_study.keywords.split(", ")): search_terms[f"keyword #{index}"] = keyword else: search_terms[key] = getattr(case_study, key) logging.debug( "Now %s will try to find '%s' using following search terms: %s", buyer_alias, company.title, search_terms, ) for term_name in search_terms: term = search_terms[term_name] logging.debug( "Searching for '%s' using %s: %s", company.title, term_name, search_terms ) response = fas.search.go_to(session, term=term) context.response = response fas.search.should_be_here(response) found = fas.search.should_not_see_company(response, company.title) with assertion_msg( "Buyer found Supplier '%s' on FAS using %s: %s", company.title, term_name, term, ): assert found logging.debug( "Buyer was not able to find unverified Supplier '%s' on FAS using " "%s: %s", company.title, term_name, term, )
def profile_should_be_told_about_invalid_links(context: Context, supplier_alias: str): actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) facebook = True if company.facebook else False linkedin = True if company.linkedin else False twitter = True if company.twitter else False profile.edit_online_profiles.should_see_errors( context.response, facebook=facebook, linkedin=linkedin, twitter=twitter ) logging.debug( "%s was not able to set Company's Online Profile links using invalid " "URLs to: %s %s %s", supplier_alias, "Facebook" if facebook else "", "LinkedIn" if linkedin else "", "Twitter" if twitter else "", )
def profile_should_see_logo_picture(context: Context, supplier_alias: str): """Will check if Company's Logo visible on FAB profile page is the same as the uploaded one. """ actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) logo_url = company.logo_url logo_hash = company.logo_hash logo_picture = company.logo_picture logging.debug( "Fetching logo image visible on the %s's FAB profile page", company.title ) check_hash_of_remote_file(logo_hash, logo_url) logging.debug( "The Logo visible on the %s's FAB profile page is the same " "as uploaded %s", company.title, logo_picture, )
def fas_should_see_png_logo_thumbnail(context: Context, supplier_alias: str): """Will check if Company's PNG thumbnail logo visible on FAS profile.""" actor = get_actor(context, supplier_alias) session = actor.session company = get_company(context, actor.company_alias) # Step 1 - Go to the FAS profile page & extract URL of visible logo image response = fas.profile.go_to(session, company.number) context.response = response fas.profile.should_be_here(response) visible_logo_url = extract_logo_url(response) placeholder = FAS_LOGO_PLACEHOLDER_IMAGE with assertion_msg( "Expected company logo but got image placeholder '%s'", visible_logo_url ): assert visible_logo_url != placeholder with assertion_msg("Expected PNG logo thumbnail, but got: %s", visible_logo_url): assert visible_logo_url.lower().endswith(".png") set_company_logo_detail(context, actor.company_alias, url=visible_logo_url) logging.debug("Set Company's logo URL to: %s", visible_logo_url)
def profile_should_see_all_case_studies(context: Context, supplier_alias: str): """Check if Supplier can see all case studies on FAB profile page.""" actor = get_actor(context, supplier_alias) case_studies = get_company(context, actor.company_alias).case_studies profile.edit_company_profile.should_see_case_studies(case_studies, context.response)
def sso_should_get_password_reset_email(context: Context, supplier_alias: str): """Will check if the Supplier received an email verification message.""" logging.debug("Searching for a password reset email...") actor = get_actor(context, supplier_alias) link = get_password_reset_link(actor.email) update_actor(context, supplier_alias, password_reset_link=link)
def fas_should_be_on_profile_page(context, supplier_alias, company_alias): actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) fas.profile.should_be_here(context.response, number=company.number) logging.debug("%s is on the %s company's FAS page", supplier_alias, company_alias)
def generic_should_get_email_notifications(context: Context, alias: str, subject: str): actor = get_actor(context, alias) notifications = get_notifications_by_subject(actor.email, subject=subject) update_actor(context, alias, notifications=notifications)
def profile_should_see_online_profiles(context: Context, supplier_alias: str): """Check if Supplier can see all online Profiles on FAB Profile page.""" actor = get_actor(context, supplier_alias) company = get_company(context, actor.company_alias) response = context.response profile.edit_company_profile.should_see_online_profiles(company, response)
def fas_find_supplier_using_case_study_details( context: Context, buyer_alias: str, company_alias: str, case_alias: str, *, properties: Table = None, max_pages: int = 5, ): """Find Supplier on FAS using parts of the Case Study added by Supplier. :param context: behave `context` object :param buyer_alias: alias of the Actor used in the scope of the scenario :param company_alias: alias of the sought Company :param case_alias: alias of the Case Study used in the search :param properties: (optional) table containing the names of Case Study parts that will be used search. If not provided, then all parts will be used except 'alias'. :param max_pages: (optional) maximum number of search result pages to go through """ actor = get_actor(context, buyer_alias) session = actor.session company = get_company(context, company_alias) case_study = company.case_studies[case_alias] keys = SEARCHABLE_CASE_STUDY_DETAILS if properties: keys = [row["search using case study's"] for row in properties] search_terms = {} for key in keys: # if key == "keywords": # for index, keyword in enumerate(case_study.keywords.split(", ")): # search_terms[f"keyword #{index}"] = keyword # else: search_terms[key] = getattr(case_study, key.replace(" ", "_")) logging.debug( "Now %s will try to find '%s' using following search terms: %s", buyer_alias, company.title, search_terms, ) search_results = defaultdict() for term_type in search_terms: term = search_terms[term_type] logging.debug(f"Looking for '{company.title}' using '{term_type}': '{term}'") profile_link, context.response = can_find_supplier_by_term( session, company.title, term, term_type, max_pages=max_pages ) found = profile_link != "" search_results[term_type] = {"term": term, "found": found} logging.debug(f"Search results: {search_results}") not_found_by = { term_type: search_results for term_type, search_results in search_results.items() if not search_results["found"] } not_found_by_str = "; ".join( [f"{k} → {v['term']}" for k, v in not_found_by.items()] ) with assertion_msg( f"Couldn't find '{company.title}' on FAS using following case study " f"details: {not_found_by_str}" ): assert not not_found_by logging.debug( f"{buyer_alias} was able to find company '{company.title} using all " f"case study details: {search_terms}" )