Skip to content

Commit

Permalink
fix(ci): use graphql instead of restli (#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Aug 16, 2022
1 parent d854798 commit 01e5bdf
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions smoke-test/tests/read_only/test_search.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
import pytest
import requests

from tests.test_result_msg import add_datahub_stats
from tests.utils import get_frontend_url, get_gms_url
from tests.utils import get_frontend_session, get_frontend_url

restli_default_headers = {
"X-RestLi-Protocol-Version": "2.0.0",
}

ENTITY_TO_MAP = {
"chart": "CHART",
"dataset": "DATASET",
"dashboard": "DASHBOARD",
"dataJob": "DATA_JOB",
"dataFlow": "DATA_FLOW",
"container": "CONTAINER",
"tag": "TAG",
"corpUser": "CORP_USER",
"mlFeature": "MLFEATURE",
"glossaryTerm": "GLOSSARY_TERM",
"domain": "DOMAIN",
"mlPrimaryKey": "MLPRIMARY_KEY",
"corpGroup": "CORP_GROUP",
"mlFeatureTable": "MLFEATURE_TABLE",
"glossaryNode": "GLOSSARY_NODE",
"mlModel": "MLMODEL",
}


def _get_search_result(entity: str):
json = {"input": "*", "entity": entity, "start": 0, "count": 1}
response = requests.post(
f"{get_gms_url()}/entities?action=search",
headers=restli_default_headers,
json=json,
)
def _get_search_result(frontend_session, entity: str):
json = {
"query": """
query search($input: SearchInput!) {
search(input: $input) {
total
searchResults {
entity {
urn
}
}
}
}
""",
"variables": {"input": {"type": ENTITY_TO_MAP.get(entity), "query": "*"}},
}
response = frontend_session.post(f"{get_frontend_url()}/api/v2/graphql", json=json)
print(f"Response text was {response.text}")
res_data = response.json()
assert res_data, f"response data was {res_data}"
assert res_data["value"], f"response data was {res_data}"
return res_data["value"]
assert res_data["data"], f"response data was {res_data}"
assert res_data["data"]["search"], f"response data was {res_data}"
return res_data["data"]["search"]


@pytest.mark.read_only
Expand Down Expand Up @@ -56,16 +86,17 @@ def _get_search_result(entity: str):
("mlModel", "mlModel"),
],
)
def test_search_works(frontend_session, entity_type, api_name):
search_result = _get_search_result(entity_type)
num_entities = search_result["numEntities"]
def test_search_works(entity_type, api_name):
frontend_session = get_frontend_session()
search_result = _get_search_result(frontend_session, entity_type)
num_entities = search_result["total"]
add_datahub_stats(f"num-{entity_type}", num_entities)
if num_entities == 0:
print(f"[WARN] No results for {entity_type}")
return
entities = search_result["entities"]
entities = search_result["searchResults"]

first_urn = entities[0]["entity"]
first_urn = entities[0]["entity"]["urn"]

json = {
"query": """
Expand Down

0 comments on commit 01e5bdf

Please sign in to comment.