Exemple #1
0
def test_sso_api_health_check(url, basic_auth):
    """This endpoint still uses session auth"""
    params = {"token": TOKEN}
    get_and_assert(url=url,
                   params=params,
                   status_code=HTTP_200_OK,
                   auth=basic_auth)
def test_case_study_200(basic_auth):
    # case study 6 must exist on the environment the tests are ran against.
    url = URLs.FAS_CASE_STUDY.absolute_template.format(number="6")
    get_and_assert(url=url,
                   status_code=HTTP_200_OK,
                   auth=basic_auth,
                   allow_redirects=True)
Exemple #3
0
def test_access_soo_endpoints_without_trailing_slash(url, basic_auth):
    # get rid of trailing slash
    if url.endswith("/"):
        url = url[:-1]
    get_and_assert(url=url,
                   status_code=HTTP_301_MOVED_PERMANENTLY,
                   auth=basic_auth)
Exemple #4
0
def get_all_market_slugs(
    *, auth: tuple = (BASICAUTH_USER, BASICAUTH_PASS)) -> list:
    start_page = f"{URLs.SOO_SEARCH_RESULTS.absolute}?category_id=&country_id=&commit="
    response = get_and_assert(url=start_page,
                              status_code=HTTP_200_OK,
                              auth=auth)
    content = response.content.decode("UTF-8")
    hrefs = extract_attributes_by_css(content,
                                      "a.market-header-link",
                                      attrs=["href"],
                                      text=False)

    last_page_number = int(
        extract_by_css(content,
                       "nav.pagination > ol > li:last-of-type > a::text"))
    if last_page_number > 1:
        for page_number in range(2, last_page_number + 1):
            url = f"{start_page}&page={page_number}"
            response = get_and_assert(url=url,
                                      status_code=HTTP_200_OK,
                                      auth=auth)
            content = response.content.decode("UTF-8")
            hrefs += extract_attributes_by_css(content,
                                               "a.market-header-link",
                                               attrs=["href"],
                                               text=False)
    # flatten the results and return only the market's slug value e.g. tthigo
    # results format is:
    # [{'href': '/selling-online-overseas/markets/details/tthigo/'}, ...]
    slugs = [href["href"].split("/")[-2] for href in hrefs]
    return slugs
def test_supplier_contact_200(basic_auth):
    # company 09466005 must exist on the environment the tests are ran against.
    url = URLs.FAS_CONTACT_SUPPLIER.absolute_template.format(
        ch_number="09400376")
    get_and_assert(url=url,
                   status_code=HTTP_200_OK,
                   auth=basic_auth,
                   allow_redirects=True)
def test_access_contact_us_organisation_endpoints_prod(market):
    params = {"market": market}
    get_and_assert(
        url=URLs.CONTACT_US_SOO_ORGANISATION.absolute,
        params=params,
        allow_redirects=True,
        status_code=HTTP_200_OK,
    )
def test_search_supplier_200(basic_auth):
    sector = choice(SECTORS)
    url = URLs.FAS_SEARCH.absolute_template.format(query=rare_word(),
                                                   industries=sector)
    get_and_assert(url=url,
                   status_code=HTTP_200_OK,
                   auth=basic_auth,
                   allow_redirects=True)
Exemple #8
0
def test_fab_302_redirects_after_removing_trailing_slash_for_anon_user(
        url, basic_auth):
    # get rid of trailing slash
    if url[-1] == "/":
        url = url[:-1]
    get_and_assert(
        url=url,
        allow_redirects=False,
        status_code=HTTP_301_MOVED_PERMANENTLY,
        auth=basic_auth,
    )
Exemple #9
0
def test_fab_redirects_for_health_check_endpoints(url, basic_auth):
    params = {"token": TOKEN}
    # get rid of trailing slash
    if url[-1] == "/":
        url = url[:-1]
    get_and_assert(
        url=url,
        params=params,
        allow_redirects=False,
        status_code=HTTP_301_MOVED_PERMANENTLY,
        auth=basic_auth,
    )
Exemple #10
0
def test_search_works(categories, countries, basic_auth):
    url = URLs.SOO_SEARCH_RESULTS.absolute
    params = {
        "product_categories": categories,
        "operating_countries": countries
    }
    get_and_assert(
        url=url,
        params=params,
        allow_redirects=True,
        status_code=HTTP_200_OK,
        auth=basic_auth,
    )
Exemple #11
0
def test_invest_pages_redirect_to_international_dev(url, redirected,
                                                    basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth,
                              allow_redirects=True)
    error = f"Expected {url} to redirect to {redirected} instead got to {response.url}"
    assert response.url == redirected, error
Exemple #12
0
def test_non_existing_invest_pages_redirect_to_international_stage(
        url, redirected, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_404_NOT_FOUND,
                              auth=basic_auth,
                              allow_redirects=True)
    error = f"Expected {url} to redirect to {redirected} instead got to {response.url}"
    assert response.url == redirected, error
Exemple #13
0
def test_invest_pages_redirects(url, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_302_FOUND,
                              auth=basic_auth,
                              allow_redirects=False)
    location = response.headers["location"]
    error = f"Expected redirect to https://... URL but got {location}"
    assert location.startswith("https://"), error
Exemple #14
0
def test_some_legacy_invest_industry_pages_redirect_to_various_pages(
        url, redirected, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth,
                              allow_redirects=True)
    error = f"Expected {url} to redirect to {redirected} instead got to {response.url}"
    assert response.url == redirected, error
Exemple #15
0
def test_domestic_home_page_might_redirect_to_international(url, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth,
                              allow_redirects=True)
    if response.history:
        last_redirect = response.history[-1]
        assert last_redirect.headers[
            "location"] == "/international/?lang=en-gb"
Exemple #16
0
def test_ed_4152_redirect_on_stage_from_old_industry_page(
        old_url, to_new_endpoint, basic_auth):
    response = get_and_assert(url=old_url,
                              status_code=HTTP_302_FOUND,
                              auth=basic_auth,
                              allow_redirects=False)

    error_msg = (f"Expected request to '{old_url}' to be redirected to "
                 f"'{to_new_endpoint}' but instead it was redirected to "
                 f"'{response.headers['Location']}'")
    assert response.headers["Location"] == to_new_endpoint, error_msg
Exemple #17
0
def test_301_redirects_after_removing_trailing_slash_for_anon_user(
        url, basic_auth):
    # get rid of trailing slash
    if url[-1] == "/":
        url = url[:-1]
    response = get_and_assert(
        url=url,
        allow_redirects=False,
        status_code=HTTP_301_MOVED_PERMANENTLY,
        auth=basic_auth,
    )
    assert response.headers["location"] == "/find-a-buyer/verify/"
Exemple #18
0
def test_redirects_to_profile_pages(url, destination, basic_auth):
    # get rid of trailing slash -> see TT-1543
    if url[-1] == "/":
        url = url[:-1]
    response = get_and_assert(url=url,
                              allow_redirects=False,
                              status_code=HTTP_302_FOUND,
                              auth=basic_auth)
    location = response.headers["location"]
    error = (f"Expected '{url}' to return a redirect which would get us to "
             f"'{destination}' but got redirect to '{location}'")
    assert destination.endswith(location), error
def test_check_sitemap_schema_and_if_it_contains_urls(url, basic_auth):
    schema = "http://www.sitemaps.org/schemas/sitemap/0.9"
    response = get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth)
    xml_soup = BeautifulSoup(markup=response.content, features="lxml")

    assert xml_soup.urlset["xmlns"] == schema

    sitemap_urls = [location.text for location in xml_soup.find_all("loc")]
    error = (
        f"Expected to find at least 1 URL location in {url} but found an empty "
        f"sitemap.xml"
    )
    assert sitemap_urls, error
def get_urls_from_sitemap(sitemap_url: str, *, ignore_404: bool = False) -> list:
    result = []
    try:
        response = get_and_assert(
            url=sitemap_url,
            status_code=HTTP_200_OK,
            auth=(BASICAUTH_USER, BASICAUTH_PASS),
        )
        xml_soup = BeautifulSoup(response.content, "xml")
        if xml_soup.find_all("loc"):
            result = [location.text for location in xml_soup.find_all("loc")]
    except AssertionError:
        if not ignore_404:
            pass
        else:
            raise
    return result
def test_secure_cookie_flag_is_set_for_public_pages_on_soo(url, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth)
    assert_secure_cookie_flag_is_set(response)
Exemple #22
0
def test_in_region_pages_and_uk_setup_guide_pages(url, basic_auth):
    get_and_assert(url=url,
                   status_code=HTTP_200_OK,
                   auth=basic_auth,
                   allow_redirects=True)
Exemple #23
0
def test_invest_pages_uat(url, basic_auth):
    get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth)
def test_http_only_cookie_flag_is_set_for_public_sso_pages_dev(url, basic_auth):
    response = get_and_assert(
        url=url, status_code=HTTP_200_OK, auth=basic_auth, headers=USER_AGENT
    )
    assert_httponly_cookie_flag_is_set(response)
def test_secure_cookie_flag_is_present_on_soo_stage(url, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth)
    assert_secure_cookie_flag_is_set(response)
Exemple #26
0
def test_access_sso_endpoints_as_anonymous_user_yields_200(url, basic_auth):
    get_and_assert(
        url=url, allow_redirects=True, status_code=HTTP_200_OK, auth=basic_auth
    )
def test_industry_pages_stage(url, basic_auth):
    get_and_assert(url=url,
                   status_code=HTTP_200_OK,
                   auth=basic_auth,
                   allow_redirects=True)
def test_access_contact_us_endpoints(url, basic_auth):
    get_and_assert(
        url=url, allow_redirects=True, status_code=HTTP_200_OK, auth=basic_auth
    )
def test_http_only_cookie_flag_is_present_on_soo_stage(url, basic_auth):
    response = get_and_assert(
        url=url, status_code=HTTP_200_OK, auth=basic_auth, headers=USER_AGENT
    )
    assert_httponly_cookie_flag_is_set(response)
def test_secure_cookie_flag_is_present_export_opportunities_dev(
        url, basic_auth):
    response = get_and_assert(url=url,
                              status_code=HTTP_200_OK,
                              auth=basic_auth)
    assert_secure_cookie_flag_is_set(response)