refactor(tests): extract common code (#7441)

This commit is contained in:
Aseem Bansal 2023-02-27 19:06:16 +05:30 committed by GitHub
parent 1b53c03794
commit c12f3491a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 27 deletions

View File

@ -15,7 +15,6 @@ python -c 'from tests.cypress.integration_test import ingest_data; ingest_data()
cd tests/cypress cd tests/cypress
npm install npm install
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub} source ./set-cypress-creds.sh
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}
npx cypress open npx cypress open

View File

@ -0,0 +1,4 @@
#!/bin/bash
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub}
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}

View File

@ -22,8 +22,7 @@ source venv/bin/activate
(cd ..; ./gradlew :smoke-test:yarnInstall) (cd ..; ./gradlew :smoke-test:yarnInstall)
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub} source ./set-cypress-creds.sh
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}
if [[ -z "${TEST_STRATEGY}" ]]; then if [[ -z "${TEST_STRATEGY}" ]]; then
pytest -rP --durations=20 -vv --continue-on-collection-errors --junit-xml=junit.smoke.xml pytest -rP --durations=20 -vv --continue-on-collection-errors --junit-xml=junit.smoke.xml

View File

@ -17,6 +17,7 @@ from tests.utils import (
wait_for_healthcheck_util, wait_for_healthcheck_util,
get_frontend_session, get_frontend_session,
get_admin_credentials, get_admin_credentials,
get_root_urn,
) )
bootstrap_sample_data = "../metadata-ingestion/examples/mce_files/bootstrap_mce.json" bootstrap_sample_data = "../metadata-ingestion/examples/mce_files/bootstrap_mce.json"
@ -120,10 +121,7 @@ def _ensure_dataset_present(
@tenacity.retry( @tenacity.retry(
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec) stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
) )
def _ensure_group_not_present( def _ensure_group_not_present(urn: str, frontend_session) -> Any:
urn: str,
frontend_session
) -> Any:
json = { json = {
"query": """query corpGroup($urn: String!) {\n "query": """query corpGroup($urn: String!) {\n
corpGroup(urn: $urn) {\n corpGroup(urn: $urn) {\n
@ -148,7 +146,7 @@ def _ensure_group_not_present(
@pytest.mark.dependency(depends=["test_healthchecks"]) @pytest.mark.dependency(depends=["test_healthchecks"])
def test_ingestion_via_rest(wait_for_healthchecks): def test_ingestion_via_rest(wait_for_healthchecks):
ingest_file_via_rest(bootstrap_sample_data) ingest_file_via_rest(bootstrap_sample_data)
_ensure_user_present(urn="urn:li:corpuser:datahub") _ensure_user_present(urn=get_root_urn())
@pytest.mark.dependency(depends=["test_healthchecks"]) @pytest.mark.dependency(depends=["test_healthchecks"])
@ -481,7 +479,7 @@ def test_frontend_search_across_entities(frontend_session, query, min_expected_r
@pytest.mark.dependency(depends=["test_healthchecks", "test_run_ingestion"]) @pytest.mark.dependency(depends=["test_healthchecks", "test_run_ingestion"])
def test_frontend_user_info(frontend_session): def test_frontend_user_info(frontend_session):
urn = "urn:li:corpuser:datahub" urn = get_root_urn()
json = { json = {
"query": """query corpUser($urn: String!) {\n "query": """query corpUser($urn: String!) {\n
corpUser(urn: $urn) {\n corpUser(urn: $urn) {\n
@ -570,7 +568,7 @@ def test_ingest_with_system_metadata():
"entity": { "entity": {
"value": { "value": {
"com.linkedin.metadata.snapshot.CorpUserSnapshot": { "com.linkedin.metadata.snapshot.CorpUserSnapshot": {
"urn": "urn:li:corpuser:datahub", "urn": get_root_urn(),
"aspects": [ "aspects": [
{ {
"com.linkedin.identity.CorpUserInfo": { "com.linkedin.identity.CorpUserInfo": {
@ -603,7 +601,7 @@ def test_ingest_with_blank_system_metadata():
"entity": { "entity": {
"value": { "value": {
"com.linkedin.metadata.snapshot.CorpUserSnapshot": { "com.linkedin.metadata.snapshot.CorpUserSnapshot": {
"urn": "urn:li:corpuser:datahub", "urn": get_root_urn(),
"aspects": [ "aspects": [
{ {
"com.linkedin.identity.CorpUserInfo": { "com.linkedin.identity.CorpUserInfo": {
@ -633,7 +631,7 @@ def test_ingest_without_system_metadata():
"entity": { "entity": {
"value": { "value": {
"com.linkedin.metadata.snapshot.CorpUserSnapshot": { "com.linkedin.metadata.snapshot.CorpUserSnapshot": {
"urn": "urn:li:corpuser:datahub", "urn": get_root_urn(),
"aspects": [ "aspects": [
{ {
"com.linkedin.identity.CorpUserInfo": { "com.linkedin.identity.CorpUserInfo": {
@ -731,7 +729,7 @@ def test_frontend_me_query(frontend_session):
assert res_data assert res_data
assert res_data["data"] assert res_data["data"]
assert res_data["data"]["me"]["corpUser"]["urn"] == "urn:li:corpuser:datahub" assert res_data["data"]["me"]["corpUser"]["urn"] == get_root_urn()
assert res_data["data"]["me"]["platformPrivileges"]["viewAnalytics"] is True assert res_data["data"]["me"]["platformPrivileges"]["viewAnalytics"] is True
assert res_data["data"]["me"]["platformPrivileges"]["managePolicies"] is True assert res_data["data"]["me"]["platformPrivileges"]["managePolicies"] is True
assert res_data["data"]["me"]["platformPrivileges"]["manageUserCredentials"] is True assert res_data["data"]["me"]["platformPrivileges"]["manageUserCredentials"] is True
@ -1140,7 +1138,7 @@ def test_home_page_recommendations(frontend_session):
listRecommendations(input: $input) { modules { title } } }""", listRecommendations(input: $input) { modules { title } } }""",
"variables": { "variables": {
"input": { "input": {
"userUrn": "urn:li:corpuser:datahub", "userUrn": get_root_urn(),
"requestContext": {"scenario": "HOME"}, "requestContext": {"scenario": "HOME"},
"limit": 5, "limit": 5,
} }
@ -1171,7 +1169,7 @@ def test_search_results_recommendations(frontend_session):
listRecommendations(input: $input) { modules { title } } }""", listRecommendations(input: $input) { modules { title } } }""",
"variables": { "variables": {
"input": { "input": {
"userUrn": "urn:li:corpuser:datahub", "userUrn": get_root_urn(),
"requestContext": { "requestContext": {
"scenario": "SEARCH_RESULTS", "scenario": "SEARCH_RESULTS",
"searchRequestContext": {"query": "asdsdsdds", "filters": []}, "searchRequestContext": {"query": "asdsdsdds", "filters": []},
@ -1202,7 +1200,7 @@ def test_generate_personal_access_token(frontend_session):
"variables": { "variables": {
"input": { "input": {
"type": "PERSONAL", "type": "PERSONAL",
"actorUrn": "urn:li:corpuser:datahub", "actorUrn": get_root_urn(),
"duration": "ONE_MONTH", "duration": "ONE_MONTH",
} }
}, },

View File

@ -1,5 +1,10 @@
import pytest import pytest
from tests.utils import delete_urns_from_file, get_frontend_url, ingest_file_via_rest from tests.utils import (
delete_urns_from_file,
get_frontend_url,
ingest_file_via_rest,
get_root_urn,
)
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
@ -87,7 +92,7 @@ def test_update_deprecation_all_fields(frontend_session):
"deprecated": True, "deprecated": True,
"decommissionTime": 0, "decommissionTime": 0,
"note": "My test note", "note": "My test note",
"actor": "urn:li:corpuser:datahub", "actor": get_root_urn(),
} }
@ -143,6 +148,6 @@ def test_update_deprecation_partial_fields(frontend_session, ingest_cleanup_data
assert res_data["data"]["dataset"]["deprecation"] == { assert res_data["data"]["dataset"]["deprecation"] == {
"deprecated": False, "deprecated": False,
"note": "", "note": "",
"actor": "urn:li:corpuser:datahub", "actor": get_root_urn(),
"decommissionTime": None, "decommissionTime": None,
} }

View File

@ -1,6 +1,12 @@
import pytest import pytest
import tenacity import tenacity
from tests.utils import get_frontend_url, wait_for_healthcheck_util, get_frontend_session, get_sleep_info from tests.utils import (
get_frontend_url,
wait_for_healthcheck_util,
get_frontend_session,
get_sleep_info,
get_root_urn,
)
TEST_POLICY_NAME = "Updated Platform Policy" TEST_POLICY_NAME = "Updated Platform Policy"
@ -25,7 +31,7 @@ def frontend_session(wait_for_healthchecks):
@pytest.mark.dependency(depends=["test_healthchecks"]) @pytest.mark.dependency(depends=["test_healthchecks"])
@pytest.fixture(scope='class', autouse=True) @pytest.fixture(scope="class", autouse=True)
def test_frontend_list_policies(frontend_session): def test_frontend_list_policies(frontend_session):
"""Fixture to execute setup before and tear down after all tests are run""" """Fixture to execute setup before and tear down after all tests are run"""
res_data = listPolicies(frontend_session) res_data = listPolicies(frontend_session)
@ -73,9 +79,11 @@ def _ensure_policy_present(frontend_session, new_urn):
assert res_data["data"]["listPolicies"] assert res_data["data"]["listPolicies"]
# Verify that the updated policy appears in the list and has the appropriate changes # Verify that the updated policy appears in the list and has the appropriate changes
result = list(filter( result = list(
lambda x: x["urn"] == new_urn, res_data["data"]["listPolicies"]["policies"] filter(
)) lambda x: x["urn"] == new_urn, res_data["data"]["listPolicies"]["policies"]
)
)
print(result) print(result)
assert len(result) == 1 assert len(result) == 1
@ -99,7 +107,7 @@ def test_frontend_policy_operations(frontend_session):
"resources": {"type": "dataset", "allResources": True}, "resources": {"type": "dataset", "allResources": True},
"privileges": ["EDIT_ENTITY_TAGS"], "privileges": ["EDIT_ENTITY_TAGS"],
"actors": { "actors": {
"users": ["urn:li:corpuser:datahub"], "users": [get_root_urn()],
"resourceOwners": False, "resourceOwners": False,
"allUsers": False, "allUsers": False,
"allGroups": False, "allGroups": False,
@ -138,7 +146,9 @@ def test_frontend_policy_operations(frontend_session):
}, },
} }
response = frontend_session.post(f"{get_frontend_url()}/api/v2/graphql", json=update_json) response = frontend_session.post(
f"{get_frontend_url()}/api/v2/graphql", json=update_json
)
response.raise_for_status() response.raise_for_status()
res_data = response.json() res_data = response.json()

View File

@ -38,6 +38,10 @@ def get_admin_credentials():
) )
def get_root_urn():
return "urn:li:corpuser:datahub"
def get_gms_url(): def get_gms_url():
return os.getenv("DATAHUB_GMS_URL") or "http://localhost:8080" return os.getenv("DATAHUB_GMS_URL") or "http://localhost:8080"