mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-17 13:45:54 +00:00
refactor(tests): extract common code (#7441)
This commit is contained in:
parent
1b53c03794
commit
c12f3491a2
@ -15,7 +15,6 @@ python -c 'from tests.cypress.integration_test import ingest_data; ingest_data()
|
||||
cd tests/cypress
|
||||
npm install
|
||||
|
||||
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub}
|
||||
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}
|
||||
source ./set-cypress-creds.sh
|
||||
|
||||
npx cypress open
|
4
smoke-test/set-cypress-creds.sh
Normal file
4
smoke-test/set-cypress-creds.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub}
|
||||
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}
|
@ -22,8 +22,7 @@ source venv/bin/activate
|
||||
|
||||
(cd ..; ./gradlew :smoke-test:yarnInstall)
|
||||
|
||||
export CYPRESS_ADMIN_USERNAME=${ADMIN_USERNAME:-datahub}
|
||||
export CYPRESS_ADMIN_PASSWORD=${ADMIN_PASSWORD:-datahub}
|
||||
source ./set-cypress-creds.sh
|
||||
|
||||
if [[ -z "${TEST_STRATEGY}" ]]; then
|
||||
pytest -rP --durations=20 -vv --continue-on-collection-errors --junit-xml=junit.smoke.xml
|
||||
|
@ -17,6 +17,7 @@ from tests.utils import (
|
||||
wait_for_healthcheck_util,
|
||||
get_frontend_session,
|
||||
get_admin_credentials,
|
||||
get_root_urn,
|
||||
)
|
||||
|
||||
bootstrap_sample_data = "../metadata-ingestion/examples/mce_files/bootstrap_mce.json"
|
||||
@ -120,10 +121,7 @@ def _ensure_dataset_present(
|
||||
@tenacity.retry(
|
||||
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
|
||||
)
|
||||
def _ensure_group_not_present(
|
||||
urn: str,
|
||||
frontend_session
|
||||
) -> Any:
|
||||
def _ensure_group_not_present(urn: str, frontend_session) -> Any:
|
||||
json = {
|
||||
"query": """query corpGroup($urn: String!) {\n
|
||||
corpGroup(urn: $urn) {\n
|
||||
@ -148,7 +146,7 @@ def _ensure_group_not_present(
|
||||
@pytest.mark.dependency(depends=["test_healthchecks"])
|
||||
def test_ingestion_via_rest(wait_for_healthchecks):
|
||||
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"])
|
||||
@ -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"])
|
||||
def test_frontend_user_info(frontend_session):
|
||||
|
||||
urn = "urn:li:corpuser:datahub"
|
||||
urn = get_root_urn()
|
||||
json = {
|
||||
"query": """query corpUser($urn: String!) {\n
|
||||
corpUser(urn: $urn) {\n
|
||||
@ -570,7 +568,7 @@ def test_ingest_with_system_metadata():
|
||||
"entity": {
|
||||
"value": {
|
||||
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
||||
"urn": "urn:li:corpuser:datahub",
|
||||
"urn": get_root_urn(),
|
||||
"aspects": [
|
||||
{
|
||||
"com.linkedin.identity.CorpUserInfo": {
|
||||
@ -603,7 +601,7 @@ def test_ingest_with_blank_system_metadata():
|
||||
"entity": {
|
||||
"value": {
|
||||
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
||||
"urn": "urn:li:corpuser:datahub",
|
||||
"urn": get_root_urn(),
|
||||
"aspects": [
|
||||
{
|
||||
"com.linkedin.identity.CorpUserInfo": {
|
||||
@ -633,7 +631,7 @@ def test_ingest_without_system_metadata():
|
||||
"entity": {
|
||||
"value": {
|
||||
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
||||
"urn": "urn:li:corpuser:datahub",
|
||||
"urn": get_root_urn(),
|
||||
"aspects": [
|
||||
{
|
||||
"com.linkedin.identity.CorpUserInfo": {
|
||||
@ -731,7 +729,7 @@ def test_frontend_me_query(frontend_session):
|
||||
|
||||
assert res_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"]["managePolicies"] 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 } } }""",
|
||||
"variables": {
|
||||
"input": {
|
||||
"userUrn": "urn:li:corpuser:datahub",
|
||||
"userUrn": get_root_urn(),
|
||||
"requestContext": {"scenario": "HOME"},
|
||||
"limit": 5,
|
||||
}
|
||||
@ -1171,7 +1169,7 @@ def test_search_results_recommendations(frontend_session):
|
||||
listRecommendations(input: $input) { modules { title } } }""",
|
||||
"variables": {
|
||||
"input": {
|
||||
"userUrn": "urn:li:corpuser:datahub",
|
||||
"userUrn": get_root_urn(),
|
||||
"requestContext": {
|
||||
"scenario": "SEARCH_RESULTS",
|
||||
"searchRequestContext": {"query": "asdsdsdds", "filters": []},
|
||||
@ -1202,7 +1200,7 @@ def test_generate_personal_access_token(frontend_session):
|
||||
"variables": {
|
||||
"input": {
|
||||
"type": "PERSONAL",
|
||||
"actorUrn": "urn:li:corpuser:datahub",
|
||||
"actorUrn": get_root_urn(),
|
||||
"duration": "ONE_MONTH",
|
||||
}
|
||||
},
|
||||
|
@ -1,5 +1,10 @@
|
||||
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)
|
||||
@ -87,7 +92,7 @@ def test_update_deprecation_all_fields(frontend_session):
|
||||
"deprecated": True,
|
||||
"decommissionTime": 0,
|
||||
"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"] == {
|
||||
"deprecated": False,
|
||||
"note": "",
|
||||
"actor": "urn:li:corpuser:datahub",
|
||||
"actor": get_root_urn(),
|
||||
"decommissionTime": None,
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
import pytest
|
||||
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"
|
||||
|
||||
@ -25,7 +31,7 @@ def frontend_session(wait_for_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):
|
||||
"""Fixture to execute setup before and tear down after all tests are run"""
|
||||
res_data = listPolicies(frontend_session)
|
||||
@ -73,9 +79,11 @@ def _ensure_policy_present(frontend_session, new_urn):
|
||||
assert res_data["data"]["listPolicies"]
|
||||
|
||||
# Verify that the updated policy appears in the list and has the appropriate changes
|
||||
result = list(filter(
|
||||
lambda x: x["urn"] == new_urn, res_data["data"]["listPolicies"]["policies"]
|
||||
))
|
||||
result = list(
|
||||
filter(
|
||||
lambda x: x["urn"] == new_urn, res_data["data"]["listPolicies"]["policies"]
|
||||
)
|
||||
)
|
||||
print(result)
|
||||
|
||||
assert len(result) == 1
|
||||
@ -99,7 +107,7 @@ def test_frontend_policy_operations(frontend_session):
|
||||
"resources": {"type": "dataset", "allResources": True},
|
||||
"privileges": ["EDIT_ENTITY_TAGS"],
|
||||
"actors": {
|
||||
"users": ["urn:li:corpuser:datahub"],
|
||||
"users": [get_root_urn()],
|
||||
"resourceOwners": False,
|
||||
"allUsers": 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()
|
||||
res_data = response.json()
|
||||
|
||||
|
@ -38,6 +38,10 @@ def get_admin_credentials():
|
||||
)
|
||||
|
||||
|
||||
def get_root_urn():
|
||||
return "urn:li:corpuser:datahub"
|
||||
|
||||
|
||||
def get_gms_url():
|
||||
return os.getenv("DATAHUB_GMS_URL") or "http://localhost:8080"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user