2022-12-27 00:08:01 +05:30
|
|
|
from typing import Set, List
|
2022-12-07 16:21:55 -08:00
|
|
|
|
2022-12-27 00:08:01 +05:30
|
|
|
import datetime
|
2021-12-13 23:08:30 -08:00
|
|
|
import pytest
|
|
|
|
import subprocess
|
2022-05-09 19:49:57 -07:00
|
|
|
import os
|
2021-12-13 23:08:30 -08:00
|
|
|
|
2022-12-07 16:21:55 -08:00
|
|
|
from tests.utils import (
|
|
|
|
create_datahub_step_state_aspects,
|
|
|
|
get_admin_username,
|
|
|
|
ingest_file_via_rest,
|
|
|
|
delete_urns_from_file,
|
|
|
|
)
|
|
|
|
|
|
|
|
CYPRESS_TEST_DATA_DIR = "tests/cypress"
|
|
|
|
|
|
|
|
TEST_DATA_FILENAME = "data.json"
|
|
|
|
TEST_DBT_DATA_FILENAME = "cypress_dbt_data.json"
|
|
|
|
TEST_SCHEMA_BLAME_DATA_FILENAME = "schema-blame-data.json"
|
|
|
|
TEST_ONBOARDING_DATA_FILENAME: str = "onboarding.json"
|
|
|
|
|
|
|
|
HOME_PAGE_ONBOARDING_IDS: List[str] = [
|
|
|
|
"global-welcome-to-datahub",
|
|
|
|
"home-page-ingestion",
|
|
|
|
"home-page-domains",
|
|
|
|
"home-page-platforms",
|
|
|
|
"home-page-most-popular",
|
|
|
|
"home-page-search-bar",
|
|
|
|
]
|
|
|
|
|
|
|
|
SEARCH_ONBOARDING_IDS: List[str] = [
|
|
|
|
"search-results-filters",
|
|
|
|
"search-results-advanced-search",
|
|
|
|
]
|
|
|
|
|
|
|
|
ENTITY_PROFILE_ONBOARDING_IDS: List[str] = [
|
|
|
|
"entity-profile-entities",
|
|
|
|
"entity-profile-properties",
|
|
|
|
"entity-profile-documentation",
|
|
|
|
"entity-profile-lineage",
|
|
|
|
"entity-profile-schema",
|
|
|
|
"entity-profile-owners",
|
|
|
|
"entity-profile-tags",
|
|
|
|
"entity-profile-glossary-terms",
|
|
|
|
"entity-profile-domains",
|
|
|
|
]
|
|
|
|
|
|
|
|
INGESTION_ONBOARDING_IDS: List[str] = [
|
|
|
|
"ingestion-create-source",
|
|
|
|
"ingestion-refresh-sources",
|
|
|
|
]
|
|
|
|
|
|
|
|
BUSINESS_GLOSSARY_ONBOARDING_IDS: List[str] = [
|
|
|
|
"business-glossary-intro",
|
|
|
|
"business-glossary-create-term",
|
|
|
|
"business-glossary-create-term-group",
|
|
|
|
]
|
|
|
|
|
|
|
|
DOMAINS_ONBOARDING_IDS: List[str] = [
|
|
|
|
"domains-intro",
|
|
|
|
"domains-create-domain",
|
|
|
|
]
|
|
|
|
|
|
|
|
USERS_ONBOARDING_IDS: List[str] = [
|
|
|
|
"users-intro",
|
|
|
|
"users-sso",
|
|
|
|
"users-invite-link",
|
|
|
|
"users-assign-role",
|
|
|
|
]
|
|
|
|
|
|
|
|
GROUPS_ONBOARDING_IDS: List[str] = [
|
|
|
|
"groups-intro",
|
|
|
|
"groups-create-group",
|
|
|
|
]
|
|
|
|
|
|
|
|
ROLES_ONBOARDING_IDS: List[str] = [
|
|
|
|
"roles-intro",
|
|
|
|
]
|
|
|
|
|
|
|
|
POLICIES_ONBOARDING_IDS: List[str] = [
|
|
|
|
"policies-intro",
|
|
|
|
"policies-create-policy",
|
|
|
|
]
|
|
|
|
|
|
|
|
ONBOARDING_ID_LISTS: List[List[str]] = [
|
|
|
|
HOME_PAGE_ONBOARDING_IDS,
|
|
|
|
SEARCH_ONBOARDING_IDS,
|
|
|
|
ENTITY_PROFILE_ONBOARDING_IDS,
|
|
|
|
INGESTION_ONBOARDING_IDS,
|
|
|
|
BUSINESS_GLOSSARY_ONBOARDING_IDS,
|
|
|
|
DOMAINS_ONBOARDING_IDS,
|
|
|
|
USERS_ONBOARDING_IDS,
|
|
|
|
GROUPS_ONBOARDING_IDS,
|
|
|
|
ROLES_ONBOARDING_IDS,
|
|
|
|
POLICIES_ONBOARDING_IDS,
|
|
|
|
]
|
|
|
|
|
|
|
|
ONBOARDING_IDS: List[str] = []
|
|
|
|
for id_list in ONBOARDING_ID_LISTS:
|
|
|
|
ONBOARDING_IDS.extend(id_list)
|
2021-12-13 23:08:30 -08:00
|
|
|
|
|
|
|
|
2022-12-27 00:08:01 +05:30
|
|
|
def print_now():
|
|
|
|
print(f"current time is {datetime.datetime.now(datetime.timezone.utc)}")
|
|
|
|
|
|
|
|
|
2022-12-08 20:27:51 -06:00
|
|
|
def ingest_data():
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
2022-12-07 16:21:55 -08:00
|
|
|
print("creating onboarding data file")
|
|
|
|
create_datahub_step_state_aspects(
|
|
|
|
get_admin_username(),
|
|
|
|
ONBOARDING_IDS,
|
|
|
|
f"{CYPRESS_TEST_DATA_DIR}/{TEST_ONBOARDING_DATA_FILENAME}",
|
|
|
|
)
|
|
|
|
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
2021-12-13 23:08:30 -08:00
|
|
|
print("ingesting test data")
|
2022-12-07 16:21:55 -08:00
|
|
|
ingest_file_via_rest(f"{CYPRESS_TEST_DATA_DIR}/{TEST_DATA_FILENAME}")
|
|
|
|
ingest_file_via_rest(f"{CYPRESS_TEST_DATA_DIR}/{TEST_DBT_DATA_FILENAME}")
|
|
|
|
ingest_file_via_rest(f"{CYPRESS_TEST_DATA_DIR}/{TEST_SCHEMA_BLAME_DATA_FILENAME}")
|
|
|
|
ingest_file_via_rest(f"{CYPRESS_TEST_DATA_DIR}/{TEST_ONBOARDING_DATA_FILENAME}")
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
|
|
|
print("completed ingesting test data")
|
2022-12-08 20:27:51 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def ingest_cleanup_data():
|
|
|
|
ingest_data()
|
2021-12-13 23:08:30 -08:00
|
|
|
yield
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
2021-12-13 23:08:30 -08:00
|
|
|
print("removing test data")
|
2022-12-07 16:21:55 -08:00
|
|
|
delete_urns_from_file(f"{CYPRESS_TEST_DATA_DIR}/{TEST_DATA_FILENAME}")
|
|
|
|
delete_urns_from_file(f"{CYPRESS_TEST_DATA_DIR}/{TEST_DBT_DATA_FILENAME}")
|
|
|
|
delete_urns_from_file(f"{CYPRESS_TEST_DATA_DIR}/{TEST_SCHEMA_BLAME_DATA_FILENAME}")
|
|
|
|
delete_urns_from_file(f"{CYPRESS_TEST_DATA_DIR}/{TEST_ONBOARDING_DATA_FILENAME}")
|
|
|
|
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
2022-12-07 16:21:55 -08:00
|
|
|
print("deleting onboarding data file")
|
|
|
|
if os.path.exists(f"{CYPRESS_TEST_DATA_DIR}/{TEST_ONBOARDING_DATA_FILENAME}"):
|
|
|
|
os.remove(f"{CYPRESS_TEST_DATA_DIR}/{TEST_ONBOARDING_DATA_FILENAME}")
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
|
|
|
print("deleted onboarding data")
|
|
|
|
|
|
|
|
|
|
|
|
def _get_spec_map(items: Set[str]) -> str:
|
|
|
|
if len(items) == 0:
|
|
|
|
return ""
|
|
|
|
return ",".join([f"**/{item}/*.js" for item in items])
|
2021-12-13 23:08:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_run_cypress(frontend_session, wait_for_healthchecks):
|
2022-05-09 19:49:57 -07:00
|
|
|
# Run with --record option only if CYPRESS_RECORD_KEY is non-empty
|
|
|
|
record_key = os.getenv("CYPRESS_RECORD_KEY")
|
2022-12-27 00:08:01 +05:30
|
|
|
tag_arg = ""
|
|
|
|
test_strategy = os.getenv("TEST_STRATEGY", None)
|
2022-12-29 21:47:25 +05:30
|
|
|
if record_key:
|
2022-12-27 00:08:01 +05:30
|
|
|
record_arg = " --record "
|
|
|
|
tag_arg = f" --tag {test_strategy} "
|
2022-05-09 19:49:57 -07:00
|
|
|
else:
|
2022-12-27 00:08:01 +05:30
|
|
|
record_arg = " "
|
|
|
|
|
|
|
|
rest_specs = set(os.listdir("tests/cypress/cypress/integration"))
|
|
|
|
cypress_suite1_specs = {"mutations", "search", "views"}
|
|
|
|
rest_specs.difference_update(set(cypress_suite1_specs))
|
|
|
|
strategy_spec_map = {
|
|
|
|
"cypress_suite1": cypress_suite1_specs,
|
|
|
|
"cypress_rest": rest_specs,
|
|
|
|
}
|
|
|
|
print(f"test strategy is {test_strategy}")
|
|
|
|
test_spec_arg = ""
|
|
|
|
if test_strategy is not None:
|
|
|
|
specs = _get_spec_map(strategy_spec_map.get(test_strategy))
|
|
|
|
test_spec_arg = f" --spec '{specs}' "
|
|
|
|
|
|
|
|
print("Running Cypress tests with command")
|
|
|
|
command = f"NO_COLOR=1 npx cypress run {record_arg} {test_spec_arg} {tag_arg}"
|
|
|
|
print(command)
|
|
|
|
# Add --headed --spec '**/mutations/mutations.js' (change spec name)
|
|
|
|
# in case you want to see the browser for debugging
|
|
|
|
print_now()
|
2022-12-07 16:21:55 -08:00
|
|
|
proc = subprocess.Popen(
|
|
|
|
command,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
cwd=f"{CYPRESS_TEST_DATA_DIR}",
|
|
|
|
)
|
2021-12-13 23:08:30 -08:00
|
|
|
stdout = proc.stdout.read()
|
|
|
|
stderr = proc.stderr.read()
|
|
|
|
return_code = proc.wait()
|
|
|
|
print(stdout.decode("utf-8"))
|
2022-12-07 16:21:55 -08:00
|
|
|
print("stderr output:")
|
2021-12-13 23:08:30 -08:00
|
|
|
print(stderr.decode("utf-8"))
|
2022-12-07 16:21:55 -08:00
|
|
|
print("return code", return_code)
|
2022-12-27 00:08:01 +05:30
|
|
|
print_now()
|
2022-12-07 16:21:55 -08:00
|
|
|
assert return_code == 0
|