# -*- coding: utf-8 -*- import pytest from requests import Response from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("Secure Cookie flag"), allure.feature("Secure Cookie flag"), allure.description( "The Secure flag should be set on all cookies that are used for transmitting " "sensitive data when accessing content over HTTPS. If cookies are used to " "transmit session"), ] @allure.step("Assert that Secure Cookie flag is set") def assert_secure_cookie_flag_is_set(response: Response): cookie_dict = {c.name: c.__dict__ for c in response.cookies} insecure_cookies = [c.name for c in response.cookies if not c.secure] error = (f"Not all cookies on {response.url} are set with 'Secure' flag: " f"{insecure_cookies} → {cookie_dict}") assert all(c.secure for c in response.cookies), error @allure.issue("TT-1614", "Cookies Not Set With Secure Flag") @pytest.mark.parametrize( "url",
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_301_MOVED_PERMANENTLY import allure from directory_tests_shared import URLs from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER from directory_tests_shared.utils import extract_attributes_by_css, extract_by_css from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("Selling Online Overseas"), allure.feature("Selling Online Overseas"), ] @allure.step("Get slugs for all marketplaces") 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,
"""APP API methods checks""" from typing import List import pytest import allure from tests.test_data.generators import TestData, get_data_for_methods_check from tests.test_data.db_filler import DbFiller pytestmark = [allure.suite("Allowed methods tests")] @pytest.fixture(params=get_data_for_methods_check()) def prepare_data(request, app_fs): """ Generate request body here since it depends on actual APP instance and can't be determined when generating """ test_data_list: List[TestData] = request.param for test_data in test_data_list: request_data = DbFiller(app=app_fs).generate_valid_request_data( endpoint=test_data.request.endpoint, method=test_data.request.method) test_data.request.data = request_data["data"] test_data.request.object_id = request_data.get("object_id") return app_fs, test_data_list
import pytest from tests.api.test_body import _test_patch_put_body_positive from tests.api.testdata.generators import ( get_positive_data_for_patch_body_check, get_negative_data_for_patch_body_check, TestDataWithPreparedBody, ) from tests.api.testdata.db_filler import DbFiller from tests.api.utils.api_objects import ADCMTestApiWrapper from tests.api.utils.types import get_fields from tests.api.utils.methods import Methods pytestmark = [ allure.suite("PATCH"), ] @allure.title("Prepare patch body data") @pytest.fixture() def prepare_patch_body_data(request, adcm_api_fs: ADCMTestApiWrapper): """ Fixture for preparing test data for PATCH request, depending on generated test datasets """ test_data_list: List[TestDataWithPreparedBody] = request.param dbfiller = DbFiller(adcm=adcm_api_fs) valid_data = dbfiller.generate_valid_request_data( endpoint=test_data_list[0].test_data.request.endpoint, method=Methods.PATCH) full_item = deepcopy(valid_data["full_item"])
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_302_FOUND, HTTP_404_NOT_FOUND import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("Invest"), allure.feature("Invest")] @pytest.mark.dev @pytest.mark.parametrize( "url", [ URLs.INVEST_INDUSTRIES_AEROSPACE.absolute, URLs.INVEST_INDUSTRIES_AUTOMOTIVE.absolute, URLs.INVEST_INDUSTRIES_CREATIVE_INDUSTRIES.absolute, URLs.INVEST_INDUSTRIES_HEALTH_AND_LIFE_SCIENCES.absolute, URLs.INVEST_INDUSTRIES_TECHNOLOGY.absolute, ], ) 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
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_301_MOVED_PERMANENTLY import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [allure.suite("SSO"), allure.feature("SSO")] @pytest.mark.session_auth @pytest.mark.parametrize( "url", [URLs.SSO_LANDING.absolute, URLs.SSO_LOGIN.absolute, URLs.SSO_SIGNUP.absolute], ) def test_access_sso_endpoints_as_logged_in_user_w_redirect_to_sud( logged_in_session, url, basic_auth ): response = logged_in_session.get(url, allow_redirects=True, auth=basic_auth) assert response.status_code == HTTP_200_OK, status_error(HTTP_200_OK, response) @pytest.mark.prod @pytest.mark.parametrize( "url", [ URLs.SSO_LOGOUT.absolute, URLs.SSO_PASSWORD_CHANGE.absolute, URLs.SSO_PASSWORD_SET.absolute, URLs.SSO_PASSWORD_RESET.absolute,
def smoke(func): return pytest.mark.smoke(allure.suite('smoke')(func))
# -*- coding: utf-8 -*- import pytest import requests from rest_framework.status import ( HTTP_200_OK, HTTP_301_MOVED_PERMANENTLY, HTTP_302_FOUND, ) import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("Letter links"), allure.feature("Letter links"), allure.description( "Links to legacy pages which were used in physical letters sent to our users " "should redirect to appropriate new pages"), ] @pytest.mark.stage @pytest.mark.parametrize("url", [URLs.FAB_CONFIRM_IDENTITY.absolute]) def test_302_redirects_for_anon_user(url, basic_auth): get_and_assert(url=url, allow_redirects=False, status_code=HTTP_302_FOUND, auth=basic_auth)
import allure import pytest from tests.api.test_body import _test_patch_put_body_positive from tests.api.testdata.generators import ( get_positive_data_for_put_body_check, get_negative_data_for_put_body_check, TestDataWithPreparedBody, ) from tests.api.testdata.db_filler import DbFiller from tests.api.utils.api_objects import ADCMTestApiWrapper from tests.api.utils.types import get_fields from tests.api.utils.methods import Methods pytestmark = [ allure.suite("PUT"), ] @allure.title("Prepare put body data") @pytest.fixture() def prepare_put_body_data(request, adcm_api_fs: ADCMTestApiWrapper): """ Fixture for preparing test data for PUT request, depending on generated test datasets """ test_data_list: List[TestDataWithPreparedBody] = request.param dbfiller = DbFiller(adcm=adcm_api_fs) endpoint = test_data_list[0].test_data.request.endpoint valid_data = dbfiller.generate_valid_request_data(endpoint=endpoint, method=Methods.PUT) full_item = deepcopy(valid_data["full_item"])
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ADCM API urls checks""" # pylint: disable=redefined-outer-name from typing import List import allure import pytest from tests.api.testdata.db_filler import DbFiller from tests.api.testdata.generators import get_data_for_urls_check, TestDataWithPreparedPath, TestData pytestmark = [ allure.suite("API Urls tests"), ] @allure.title("Prepare data for urls tests") @pytest.fixture(params=get_data_for_urls_check()) def prepare_data(request, adcm_api_fs): """ Generate request body here since it depends on actual ADCM instance and can't be determined when generating """ test_data_list: List[TestDataWithPreparedPath] = request.param final_test_data: List[TestData] = [] for td_with_url in test_data_list: test_data, path = td_with_url.test_data, td_with_url.request_path request_data = DbFiller(adcm=adcm_api_fs).generate_valid_request_data(
HTTP_404_NOT_FOUND, ) from retrying import retry import allure from directory_tests_shared import URLs from directory_tests_shared.clients import ( BASIC_AUTHENTICATOR, CMS_API_CLIENT, SSO_API_CLIENT, ) from directory_tests_shared.settings import DIRECTORY_API_HEALTH_CHECK_TOKEN as TOKEN from directory_tests_shared.utils import retriable_error from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [allure.suite("Health checks"), allure.feature("Health checks")] @pytest.mark.sso_api @pytest.mark.parametrize( "url", [URLs.SSO_API_HEALTHCECK.absolute, URLs.SSO_API_HEALTHCHECK_PING.absolute]) 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)
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK, HTTP_302_FOUND import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("Domestic site"), allure.feature("Domestic site")] @pytest.mark.parametrize( "url", [ URLs.DOMESTIC_LANDING_UK.absolute, URLs.DOMESTIC_INTERNATIONAL.absolute, URLs.DOMESTIC_INTERNATIONAL_UK.absolute, URLs.DOMESTIC_INTERNATIONAL_ZH.absolute, URLs.DOMESTIC_INTERNATIONAL_DE.absolute, URLs.DOMESTIC_INTERNATIONAL_JA.absolute, URLs.DOMESTIC_INTERNATIONAL_ES.absolute, URLs.DOMESTIC_INTERNATIONAL_PT.absolute, URLs.DOMESTIC_INTERNATIONAL_AR.absolute, URLs.DOMESTIC_TRIAGE_SECTOR.absolute, URLs.DOMESTIC_TRIAGE_EXPORTED_BEFORE.absolute, URLs.DOMESTIC_TRIAGE_REGULAR_EXPORTER.absolute, URLs.DOMESTIC_TRIAGE_ONLINE_MARKETPLACE.absolute, URLs.DOMESTIC_TRIAGE_COMPANIES_HOUSE.absolute, URLs.DOMESTIC_TRIAGE_COMPANY.absolute, URLs.DOMESTIC_TRIAGE_SUMMARY.absolute, URLs.DOMESTIC_CUSTOM.absolute,
# See the License for the specific language governing permissions and # limitations under the License. """ Tests for plugin steps. WARNING: don't run this test with xdist!!! """ import allure import pytest from adcm_pytest_plugin.exceptions.bundles import BundleError from adcm_pytest_plugin.exceptions.infrastructure import InfrastructureProblem from adcm_pytest_plugin.steps.actions import run_cluster_action_and_assert_result from adcm_pytest_plugin.utils import get_data_dir from adcm_pytest_plugin.plugin import options pytestmark = [allure.suite("Plugin steps")] @pytest.mark.parametrize("bundle_dir", ["fail_action_cluster", "fail_multijob_cluster"]) def test_fail_action(sdk_client_fs, bundle_dir): """Run fail action and assert result""" bundle_dir_full = get_data_dir(__file__, bundle_dir) bundle = sdk_client_fs.upload_from_fs(bundle_dir_full) cluster = bundle.cluster_create("test_cluster") with pytest.raises(AssertionError) as action_run_exception: run_cluster_action_and_assert_result(cluster=cluster, action="fail_action") assert "Meant to fail" in str( action_run_exception.value ), "No ansible error in AssertionError message"
"""Set package-wise test properties""" import allure pytestmark = [allure.parent_suite("API"), allure.suite("Body tests")]
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_302_FOUND import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("FAS redirects"), allure.feature("FAS redirects")] @allure.issue("CMS-1834", "Links to legacy industry pages redirect to wrong place") @allure.issue("ED-4152", "404s on old industry pages & contact-us page") @pytest.mark.parametrize( "old_url,to_new_endpoint", [ ( URLs.FAS_INDUSTRIES_HEALTH.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/health"), ), ( URLs.FAS_INDUSTRIES_TECH.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/tech"), ), ( URLs.FAS_INDUSTRIES_CREATIVE.absolute, URLs.FAS_INCOMING_REDIRECT.absolute_template.format( endpoint="industries/creative"),
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("Export Opportunities"), allure.feature("Export Opportunities"), ] @pytest.mark.parametrize( "url", [ URLs.EXOPPS_LANDING.absolute, URLs.EXOPPS_OPPORTUNITY.absolute_template.format(slug="furniture-498"), URLs.EXOPPS_SEARCH.absolute_template.format(term="food"), ], ) def test_exopps_pages(url, basic_auth): get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth)
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ADCM API methods checks""" # pylint: disable=redefined-outer-name from typing import List import pytest import allure from tests.api.testdata.generators import TestData, get_data_for_methods_check from tests.api.testdata.db_filler import DbFiller pytestmark = [ allure.suite("API Methods tests"), ] @allure.title("Prepare data for methods tests") @pytest.fixture(params=get_data_for_methods_check()) def prepare_data(request, adcm_api_fs): """ Generate request body here since it depends on actual ADCM instance and can't be determined when generating """ test_data_list: List[TestData] = request.param for test_data in test_data_list: request_data = DbFiller(adcm=adcm_api_fs).generate_valid_request_data( endpoint=test_data.request.endpoint, method=test_data.request.method)
# -*- coding: utf-8 -*- import pytest from rest_framework.status import ( HTTP_200_OK, HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND, HTTP_405_METHOD_NOT_ALLOWED, ) import allure from directory_tests_shared import URLs from directory_tests_shared.clients import FORMS_API_CLIENT, BasicAuthenticator from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER from tests.smoke.cms_api_helpers import status_error pytestmark = [allure.suite("Forms-API"), allure.feature("Forms-API")] BASIC_AUTHENTICATOR = BasicAuthenticator(BASICAUTH_USER, BASICAUTH_PASS) @pytest.mark.forms def test_forms_submissions_endpoint_accepts_only_post(): response = FORMS_API_CLIENT.get( URLs.FORMS_API_SUBMISSION.absolute, authenticator=BASIC_AUTHENTICATOR ) assert response.status_code == HTTP_405_METHOD_NOT_ALLOWED, status_error( HTTP_405_METHOD_NOT_ALLOWED, response ) assert response.headers["Allow"] == "POST, OPTIONS"
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("Contact us"), allure.feature("Contact us")] @pytest.mark.dev @pytest.mark.parametrize( "market", [ "1688com", "amazon-canada", "amazon-china", "amazon-france", "amazon-germany", "amazon-italy", "amazon-japan", "amazon-spain", "amazon-usa", "cdiscount", "ebay", "etsy", "flipkart", "jd-worldwide", "kaola", "newegg-inc",
def pytest_runtest_call(item): """Add allure label for doctests""" if isinstance(item, DoctestItem): item.add_marker(allure.suite("Doctests"))
# -*- coding: utf-8 -*- import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("International site"), allure.feature("International site") ] @pytest.mark.dev @pytest.mark.parametrize( "url", [ URLs.INTERNATIONAL_REGIONS_MIDLANDS.absolute, URLs.INTERNATIONAL_REGIONS_NORTH_ENGLAND.absolute, URLs.INTERNATIONAL_REGIONS_NORTHERN_IRELAND.absolute, URLs.INTERNATIONAL_REGIONS_SOUTH_ENGLAND.absolute, URLs.INTERNATIONAL_REGIONS_WALES.absolute, ], ) def test_region_pages(url, basic_auth): get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth, allow_redirects=True)
# -*- coding: utf-8 -*- import pytest from bs4 import BeautifulSoup from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from directory_tests_shared.settings import BASICAUTH_PASS, BASICAUTH_USER from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("sitemap.xml"), allure.feature("sitemap.xml"), allure.description( "A service which handles our Top Level Domain should expose a valid sitemap.xml" " which enables various Search Engines/Web Crawlers (like Google) to discover " "what pages are present and which change frequently. This allows them to crawl " "our site accordingly" ), ] @allure.step("Check if sitemap.xml is present") 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), )
import allure import pytest from tests.api.test_body import generate_body_for_checks from tests.api.testdata.db_filler import DbFiller from tests.api.testdata.generators import ( get_positive_data_for_post_body_check, get_negative_data_for_post_body_check, TestDataWithPreparedBody, ) from tests.api.utils.api_objects import ADCMTestApiWrapper from tests.api.utils.methods import Methods from tests.api.utils.types import get_fields pytestmark = [ allure.suite("POST"), ] @allure.title("Prepare post body data") @pytest.fixture() def prepare_post_body_data(request, adcm_api_fs: ADCMTestApiWrapper): """ Fixture for preparing test data for POST request, depending on generated test datasets """ test_data_list: List[TestDataWithPreparedBody] = request.param valid_request_data = DbFiller( adcm=adcm_api_fs).generate_valid_request_data( endpoint=test_data_list[0].test_data.request.endpoint, method=Methods.POST) final_test_data_list: List[TestDataWithPreparedBody] = []
# -*- coding: utf-8 -*- from random import choice from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from directory_tests_shared.constants import SECTORS from directory_tests_shared.utils import rare_word from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [allure.suite("FAS"), allure.feature("FAS")] def test_landing_page_200(basic_auth): url = URLs.FAS_LANDING.absolute get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth) def test_supplier_list_200(basic_auth): url = URLs.FAS_SUPPLIERS.absolute get_and_assert(url=url, status_code=HTTP_200_OK, auth=basic_auth, allow_redirects=True) def test_search_supplier_200(basic_auth): sector = choice(SECTORS) url = URLs.FAS_SEARCH.absolute_template.format(query=rare_word(), industries=sector)
# -*- coding: utf-8 -*- import pytest from requests import Response from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert, status_error pytestmark = [ allure.suite("HttpOnly Cookie flag"), allure.feature("HttpOnly Cookie flag"), allure.description( "The HttpOnly flag should be set by including this attribute within " "the relevant Set-cookie directive. Alternatively, URL rewriting could be used," " as is detailed in the following example" ), ] USER_AGENT = {"user-agent": "automated smoke tests"} @allure.step("Assert that HttpOnly Cookie flag is set") def assert_httponly_cookie_flag_is_set(response: Response): without_httponly = { c.name: c.__dict__ for c in response.cookies if not c.has_nonstandard_attr("HttpOnly") } error = ( f"Following cookies on {response.url} are set without 'HttpOnly' flag: "
# -*- coding: utf-8 -*- from urllib.parse import urljoin import pytest from rest_framework.status import HTTP_200_OK import allure from directory_tests_shared import URLs from tests.smoke.cms_api_helpers import get_and_assert pytestmark = [ allure.suite("robots.txt"), allure.feature("robots.txt"), allure.description( "The HttpOnly flag should be set by including this attribute within " "the relevant Set-cookie directive. Alternatively, URL rewriting could be used," " as is detailed in the following example"), ] @pytest.mark.parametrize( "url", [ urljoin(URLs.DOMESTIC_LANDING.absolute, "robots.txt"), urljoin(URLs.EXOPPS_LANDING.absolute, "robots.txt"), urljoin(URLs.FAB_LANDING.absolute, "robots.txt"), urljoin(URLs.INTERNATIONAL_LANDING.absolute, "robots.txt"), urljoin(URLs.SOO_LANDING.absolute, "robots.txt"), urljoin(URLs.SSO_LANDING.absolute, "robots.txt"), ], )