2024-09-27 11:31:25 -05:00
|
|
|
import logging
|
2021-04-29 23:27:03 -07:00
|
|
|
import time
|
2021-12-16 20:06:33 -08:00
|
|
|
import urllib
|
2023-03-20 14:04:42 -07:00
|
|
|
from http import HTTPStatus
|
2022-07-14 22:04:06 +05:30
|
|
|
from typing import Any, Optional
|
2021-06-14 17:15:24 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
import concurrent.futures
|
2021-04-29 23:27:03 -07:00
|
|
|
import pytest
|
2024-09-27 11:31:25 -05:00
|
|
|
import requests
|
2022-07-14 22:04:06 +05:30
|
|
|
import tenacity
|
2021-04-29 23:27:03 -07:00
|
|
|
from datahub.ingestion.run.pipeline import Pipeline
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2023-12-06 15:07:50 +05:30
|
|
|
pytestmark = pytest.mark.no_cypress_suite1
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
from tests.utils import (
|
|
|
|
get_kafka_broker_url,
|
2022-07-14 22:04:06 +05:30
|
|
|
get_kafka_schema_registry,
|
2022-06-30 16:00:50 +05:30
|
|
|
get_sleep_info,
|
|
|
|
ingest_file_via_rest,
|
2022-08-10 17:04:28 +05:30
|
|
|
get_frontend_session,
|
|
|
|
get_admin_credentials,
|
2023-02-27 19:06:16 +05:30
|
|
|
get_root_urn,
|
2024-08-13 15:53:23 -05:00
|
|
|
wait_for_writes_to_sync,
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
bootstrap_sample_data = "../metadata-ingestion/examples/mce_files/bootstrap_mce.json"
|
2024-10-22 06:59:40 -05:00
|
|
|
usage_sample_data = "./test_resources/bigquery_usages_golden.json"
|
2021-04-29 23:27:03 -07:00
|
|
|
bq_sample_data = "./sample_bq_data.json"
|
|
|
|
restli_default_headers = {
|
|
|
|
"X-RestLi-Protocol-Version": "2.0.0",
|
|
|
|
}
|
2022-11-15 20:03:11 -06:00
|
|
|
kafka_post_ingestion_wait_sec = 30
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2022-07-14 22:04:06 +05:30
|
|
|
sleep_sec, sleep_times = get_sleep_info()
|
|
|
|
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2022-07-14 22:04:06 +05:30
|
|
|
@tenacity.retry(
|
|
|
|
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def _ensure_user_present(auth_session, urn: str):
|
|
|
|
response = auth_session.get(
|
|
|
|
f"{auth_session.gms_url()}/entities/{urllib.parse.quote(urn)}",
|
2022-07-14 22:04:06 +05:30
|
|
|
headers={
|
|
|
|
**restli_default_headers,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
2022-06-30 16:00:50 +05:30
|
|
|
|
2022-07-14 22:04:06 +05:30
|
|
|
user_key = "com.linkedin.metadata.snapshot.CorpUserSnapshot"
|
|
|
|
assert data["value"]
|
|
|
|
assert data["value"][user_key]
|
|
|
|
assert data["value"][user_key]["urn"] == urn
|
|
|
|
return data
|
2022-06-30 16:00:50 +05:30
|
|
|
|
|
|
|
|
2022-08-09 23:48:49 +05:30
|
|
|
@tenacity.retry(
|
|
|
|
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def _ensure_user_relationship_present(auth_session, urn, relationships):
|
2022-08-09 23:48:49 +05:30
|
|
|
json = {
|
|
|
|
"query": """query corpUser($urn: String!) {\n
|
|
|
|
corpUser(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
relationships(input: { types: ["IsMemberOfNativeGroup"], direction: OUTGOING, start: 0, count: 1 }) {\n
|
|
|
|
total\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {"urn": urn},
|
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-08-09 23:48:49 +05:30
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpUser"]
|
|
|
|
assert res_data["data"]["corpUser"]["relationships"]
|
2022-11-15 20:03:11 -06:00
|
|
|
assert res_data["data"]["corpUser"]["relationships"]["total"] == relationships
|
2022-08-09 23:48:49 +05:30
|
|
|
|
|
|
|
|
2022-07-14 22:04:06 +05:30
|
|
|
@tenacity.retry(
|
|
|
|
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
|
|
|
|
)
|
2022-06-30 16:00:50 +05:30
|
|
|
def _ensure_dataset_present(
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session: Any,
|
2022-07-14 22:04:06 +05:30
|
|
|
urn: str,
|
|
|
|
aspects: Optional[str] = "datasetProperties",
|
|
|
|
) -> Any:
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.get(
|
|
|
|
f"{auth_session.gms_url()}/entitiesV2?ids=List({urllib.parse.quote(urn)})&aspects=List({aspects})",
|
2022-07-14 22:04:06 +05:30
|
|
|
headers={
|
|
|
|
**restli_default_headers,
|
|
|
|
"X-RestLi-Method": "batch_get",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
assert res_data["results"]
|
|
|
|
assert res_data["results"][urn]
|
|
|
|
assert res_data["results"][urn]["aspects"]["datasetProperties"]
|
|
|
|
return res_data
|
2022-06-30 16:00:50 +05:30
|
|
|
|
|
|
|
|
2022-11-03 22:53:49 +05:30
|
|
|
@tenacity.retry(
|
|
|
|
stop=tenacity.stop_after_attempt(sleep_times), wait=tenacity.wait_fixed(sleep_sec)
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def _ensure_group_not_present(auth_session, urn: str) -> Any:
|
2022-11-03 22:53:49 +05:30
|
|
|
json = {
|
|
|
|
"query": """query corpGroup($urn: String!) {\n
|
|
|
|
corpGroup(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
properties {\n
|
|
|
|
displayName\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {"urn": urn},
|
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-11-03 22:53:49 +05:30
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpGroup"]
|
|
|
|
assert res_data["data"]["corpGroup"]["properties"] is None
|
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def fixture_ingestion_via_rest(auth_session):
|
|
|
|
ingest_file_via_rest(auth_session, bootstrap_sample_data)
|
|
|
|
_ensure_user_present(auth_session, urn=get_root_urn())
|
2021-06-24 19:44:59 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def fixture_ingestion_usage_via_rest(auth_session):
|
|
|
|
ingest_file_via_rest(auth_session, usage_sample_data)
|
2021-06-24 19:44:59 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def fixture_ingestion_via_kafka(auth_session):
|
2021-04-29 23:27:03 -07:00
|
|
|
pipeline = Pipeline.create(
|
|
|
|
{
|
|
|
|
"source": {
|
|
|
|
"type": "file",
|
|
|
|
"config": {"filename": bq_sample_data},
|
|
|
|
},
|
|
|
|
"sink": {
|
|
|
|
"type": "datahub-kafka",
|
|
|
|
"config": {
|
|
|
|
"connection": {
|
2022-06-30 16:00:50 +05:30
|
|
|
"bootstrap": get_kafka_broker_url(),
|
2022-07-14 22:04:06 +05:30
|
|
|
"schema_registry_url": get_kafka_schema_registry(),
|
2021-04-29 23:27:03 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
pipeline.run()
|
|
|
|
pipeline.raise_from_status()
|
2024-09-27 11:31:25 -05:00
|
|
|
_ensure_dataset_present(auth_session,
|
2022-06-30 16:00:50 +05:30
|
|
|
"urn:li:dataset:(urn:li:dataPlatform:bigquery,bigquery-public-data.covid19_geotab_mobility_impact.us_border_wait_times,PROD)"
|
|
|
|
)
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
# Since Kafka emission is asynchronous, we must wait a little bit so that
|
|
|
|
# the changes are actually processed.
|
|
|
|
time.sleep(kafka_post_ingestion_wait_sec)
|
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
|
|
|
def test_run_ingestion(auth_session):
|
2021-04-29 23:27:03 -07:00
|
|
|
# Dummy test so that future ones can just depend on this one.
|
2024-09-27 11:31:25 -05:00
|
|
|
|
|
|
|
# The rest sink fixtures cannot run at the same time, limitation of the Pipeline code
|
|
|
|
fixture_ingestion_usage_via_rest(auth_session)
|
|
|
|
|
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
|
|
|
futures = []
|
|
|
|
for ingestion_fixture in ["fixture_ingestion_via_kafka", "fixture_ingestion_via_rest"]:
|
|
|
|
futures.append(
|
|
|
|
executor.submit(globals()[ingestion_fixture], auth_session)
|
|
|
|
)
|
|
|
|
|
|
|
|
for future in concurrent.futures.as_completed(futures):
|
|
|
|
logger.info(future.result())
|
2024-08-13 15:53:23 -05:00
|
|
|
wait_for_writes_to_sync()
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_get_user(auth_session):
|
2021-04-29 23:27:03 -07:00
|
|
|
username = "jdoe"
|
2021-08-09 09:48:05 -07:00
|
|
|
urn = f"urn:li:corpuser:{username}"
|
2024-09-27 11:31:25 -05:00
|
|
|
_ensure_user_present(auth_session, urn=urn)
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"platform,dataset_name,env",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
# This one tests the bootstrap sample data.
|
|
|
|
"urn:li:dataPlatform:kafka",
|
|
|
|
"SampleKafkaDataset",
|
|
|
|
"PROD",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# This one tests BigQuery ingestion.
|
|
|
|
"urn:li:dataPlatform:bigquery",
|
|
|
|
"bigquery-public-data.covid19_geotab_mobility_impact.us_border_wait_times",
|
|
|
|
"PROD",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_get_dataset(auth_session, platform, dataset_name, env):
|
2021-04-29 23:27:03 -07:00
|
|
|
platform = "urn:li:dataPlatform:bigquery"
|
|
|
|
dataset_name = (
|
|
|
|
"bigquery-public-data.covid19_geotab_mobility_impact.us_border_wait_times"
|
|
|
|
)
|
|
|
|
env = "PROD"
|
|
|
|
urn = f"urn:li:dataset:({platform},{dataset_name},{env})"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.get(
|
|
|
|
f"{auth_session.gms_url()}/entities/{urllib.parse.quote(urn)}",
|
2021-04-29 23:27:03 -07:00
|
|
|
headers={
|
|
|
|
**restli_default_headers,
|
|
|
|
"X-RestLi-Method": "get",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
2021-08-09 09:48:05 -07:00
|
|
|
res_data = response.json()
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2021-08-09 09:48:05 -07:00
|
|
|
assert res_data["value"]
|
|
|
|
assert res_data["value"]["com.linkedin.metadata.snapshot.DatasetSnapshot"]
|
2022-02-02 13:19:15 -08:00
|
|
|
assert (
|
|
|
|
res_data["value"]["com.linkedin.metadata.snapshot.DatasetSnapshot"]["urn"]
|
|
|
|
== urn
|
|
|
|
)
|
|
|
|
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_batch_get_v2(auth_session):
|
2022-01-23 11:24:09 -08:00
|
|
|
platform = "urn:li:dataPlatform:bigquery"
|
|
|
|
env = "PROD"
|
2022-02-02 13:19:15 -08:00
|
|
|
name_1 = "bigquery-public-data.covid19_geotab_mobility_impact.us_border_wait_times"
|
|
|
|
name_2 = "bigquery-public-data.covid19_geotab_mobility_impact.ca_border_wait_times"
|
2022-01-23 11:24:09 -08:00
|
|
|
urn1 = f"urn:li:dataset:({platform},{name_1},{env})"
|
|
|
|
urn2 = f"urn:li:dataset:({platform},{name_2},{env})"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
resp1 = _ensure_dataset_present(auth_session, urn1, aspects="datasetProperties,ownership")
|
2022-07-14 22:04:06 +05:30
|
|
|
assert resp1["results"][urn1]["aspects"]["ownership"]
|
2022-01-23 11:24:09 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
resp2 = _ensure_dataset_present(auth_session, urn2, aspects="datasetProperties,ownership")
|
2022-02-02 13:19:15 -08:00
|
|
|
assert (
|
2022-07-14 22:04:06 +05:30
|
|
|
"ownership" not in resp2["results"][urn2]["aspects"]
|
2022-02-02 13:19:15 -08:00
|
|
|
) # Aspect does not exist.
|
|
|
|
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"query,min_expected_results",
|
|
|
|
[
|
|
|
|
("covid", 1),
|
|
|
|
("sample", 3),
|
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_search_dataset(auth_session, query, min_expected_results):
|
2021-08-09 09:48:05 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
json = {"input": f"{query}", "entity": "dataset", "start": 0, "count": 10}
|
2021-08-09 09:48:05 -07:00
|
|
|
print(json)
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/entities?action=search",
|
2021-08-09 09:48:05 -07:00
|
|
|
headers=restli_default_headers,
|
2022-02-02 13:19:15 -08:00
|
|
|
json=json,
|
2021-04-29 23:27:03 -07:00
|
|
|
)
|
|
|
|
response.raise_for_status()
|
2021-08-09 09:48:05 -07:00
|
|
|
res_data = response.json()
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2021-08-09 09:48:05 -07:00
|
|
|
assert res_data["value"]
|
|
|
|
assert res_data["value"]["numEntities"] >= min_expected_results
|
|
|
|
assert len(res_data["value"]["entities"]) >= min_expected_results
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
2021-10-07 11:41:29 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"query,min_expected_results",
|
|
|
|
[
|
|
|
|
("covid", 1),
|
|
|
|
("sample", 3),
|
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_search_across_entities(auth_session, query, min_expected_results):
|
2021-10-07 11:41:29 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
json = {"input": f"{query}", "entities": [], "start": 0, "count": 10}
|
2021-10-07 11:41:29 -07:00
|
|
|
print(json)
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/entities?action=searchAcrossEntities",
|
2021-10-07 11:41:29 -07:00
|
|
|
headers=restli_default_headers,
|
2022-02-02 13:19:15 -08:00
|
|
|
json=json,
|
2021-10-07 11:41:29 -07:00
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data["value"]
|
|
|
|
assert res_data["value"]["numEntities"] >= min_expected_results
|
|
|
|
assert len(res_data["value"]["entities"]) >= min_expected_results
|
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_gms_usage_fetch(auth_session):
|
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/usageStats?action=queryRange",
|
2021-06-24 19:44:59 -07:00
|
|
|
headers=restli_default_headers,
|
|
|
|
json={
|
|
|
|
"resource": "urn:li:dataset:(urn:li:dataPlatform:bigquery,harshal-playground-306419.test_schema.excess_deaths_derived,PROD)",
|
|
|
|
"duration": "DAY",
|
|
|
|
"rangeFromEnd": "ALL",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
data = response.json()["value"]
|
|
|
|
|
2021-09-14 18:35:10 -07:00
|
|
|
assert len(data["buckets"]) == 6
|
2021-06-24 19:44:59 -07:00
|
|
|
assert data["buckets"][0]["metrics"]["topSqlQueries"]
|
|
|
|
|
|
|
|
fields = data["aggregations"].pop("fields")
|
|
|
|
assert len(fields) == 12
|
|
|
|
assert fields[0]["count"] == 7
|
|
|
|
|
|
|
|
users = data["aggregations"].pop("users")
|
|
|
|
assert len(users) == 1
|
|
|
|
assert users[0]["count"] == 7
|
|
|
|
|
|
|
|
assert data["aggregations"] == {
|
|
|
|
# "fields" and "users" already popped out
|
|
|
|
"totalSqlQueries": 7,
|
|
|
|
"uniqueUserCount": 1,
|
|
|
|
}
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_auth(auth_session):
|
2021-04-29 23:27:03 -07:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_browse_datasets(auth_session):
|
2021-08-09 09:48:05 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query browse($input: BrowseInput!) {\n
|
|
|
|
browse(input: $input) {\n
|
|
|
|
start\n
|
|
|
|
count\n
|
|
|
|
total\n
|
|
|
|
groups {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
entities {\n
|
|
|
|
... on Dataset {\n
|
|
|
|
urn\n
|
|
|
|
name\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"input": {"type": "DATASET", "path": ["prod"]}},
|
2021-08-09 09:48:05 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2021-08-09 09:48:05 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["browse"]
|
|
|
|
assert len(res_data["data"]["browse"]["entities"]) == 0
|
|
|
|
assert len(res_data["data"]["browse"]["groups"]) > 0
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"query,min_expected_results",
|
|
|
|
[
|
|
|
|
("covid", 1),
|
|
|
|
("sample", 3),
|
2021-11-28 16:03:40 -08:00
|
|
|
("", 1),
|
2021-04-29 23:27:03 -07:00
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_search_datasets(auth_session, query, min_expected_results):
|
2021-08-09 09:48:05 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query search($input: SearchInput!) {\n
|
|
|
|
search(input: $input) {\n
|
|
|
|
start\n
|
|
|
|
count\n
|
2022-02-02 13:19:15 -08:00
|
|
|
total\n
|
2021-08-09 09:48:05 -07:00
|
|
|
searchResults {\n
|
|
|
|
entity {\n
|
|
|
|
... on Dataset {\n
|
|
|
|
urn\n
|
|
|
|
name\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"input": {"type": "DATASET", "query": f"{query}", "start": 0, "count": 10}
|
|
|
|
},
|
2021-08-09 09:48:05 -07:00
|
|
|
}
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-04-29 23:27:03 -07:00
|
|
|
response.raise_for_status()
|
2021-08-09 09:48:05 -07:00
|
|
|
res_data = response.json()
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2021-08-09 09:48:05 -07:00
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["search"]
|
|
|
|
assert res_data["data"]["search"]["total"] >= min_expected_results
|
|
|
|
assert len(res_data["data"]["search"]["searchResults"]) >= min_expected_results
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
2021-10-07 11:41:29 -07:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"query,min_expected_results",
|
|
|
|
[
|
|
|
|
("covid", 1),
|
|
|
|
("sample", 3),
|
2021-11-28 16:03:40 -08:00
|
|
|
("", 1),
|
2021-10-07 11:41:29 -07:00
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_search_across_entities(auth_session, query, min_expected_results):
|
2021-10-07 11:41:29 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query searchAcrossEntities($input: SearchAcrossEntitiesInput!) {\n
|
|
|
|
searchAcrossEntities(input: $input) {\n
|
|
|
|
start\n
|
|
|
|
count\n
|
2022-02-02 13:19:15 -08:00
|
|
|
total\n
|
2021-10-07 11:41:29 -07:00
|
|
|
searchResults {\n
|
|
|
|
entity {\n
|
|
|
|
... on Dataset {\n
|
|
|
|
urn\n
|
|
|
|
name\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"input": {"types": [], "query": f"{query}", "start": 0, "count": 10}
|
|
|
|
},
|
2021-10-07 11:41:29 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 11:41:29 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["searchAcrossEntities"]
|
|
|
|
assert res_data["data"]["searchAcrossEntities"]["total"] >= min_expected_results
|
2022-02-02 13:19:15 -08:00
|
|
|
assert (
|
|
|
|
len(res_data["data"]["searchAcrossEntities"]["searchResults"])
|
|
|
|
>= min_expected_results
|
|
|
|
)
|
2021-10-07 11:41:29 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_user_info(auth_session):
|
2021-08-09 09:48:05 -07:00
|
|
|
|
2023-02-27 19:06:16 +05:30
|
|
|
urn = get_root_urn()
|
2021-08-09 09:48:05 -07:00
|
|
|
json = {
|
|
|
|
"query": """query corpUser($urn: String!) {\n
|
|
|
|
corpUser(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
username\n
|
|
|
|
editableInfo {\n
|
|
|
|
pictureLink\n
|
|
|
|
}\n
|
|
|
|
info {\n
|
|
|
|
firstName\n
|
|
|
|
fullName\n
|
|
|
|
title\n
|
|
|
|
email\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": urn},
|
2021-08-09 09:48:05 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-04-29 23:27:03 -07:00
|
|
|
response.raise_for_status()
|
2021-08-09 09:48:05 -07:00
|
|
|
res_data = response.json()
|
2021-04-29 23:27:03 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
assert res_data
|
2021-08-09 09:48:05 -07:00
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpUser"]
|
|
|
|
assert res_data["data"]["corpUser"]["urn"] == urn
|
2021-04-29 23:27:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"platform,dataset_name,env",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
# This one tests the bootstrap sample data.
|
|
|
|
"urn:li:dataPlatform:kafka",
|
|
|
|
"SampleKafkaDataset",
|
|
|
|
"PROD",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
# This one tests BigQuery ingestion.
|
|
|
|
"urn:li:dataPlatform:bigquery",
|
|
|
|
"bigquery-public-data.covid19_geotab_mobility_impact.us_border_wait_times",
|
|
|
|
"PROD",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_datasets(auth_session, platform, dataset_name, env):
|
2021-04-29 23:27:03 -07:00
|
|
|
urn = f"urn:li:dataset:({platform},{dataset_name},{env})"
|
2021-08-09 09:48:05 -07:00
|
|
|
json = {
|
|
|
|
"query": """query getDataset($urn: String!) {\n
|
|
|
|
dataset(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
name\n
|
|
|
|
description\n
|
|
|
|
platform {\n
|
|
|
|
urn\n
|
|
|
|
}\n
|
|
|
|
schemaMetadata {\n
|
|
|
|
name\n
|
|
|
|
version\n
|
|
|
|
createdAt\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": urn},
|
2021-08-09 09:48:05 -07:00
|
|
|
}
|
2021-04-29 23:27:03 -07:00
|
|
|
# Basic dataset info.
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-04-29 23:27:03 -07:00
|
|
|
response.raise_for_status()
|
2021-08-09 09:48:05 -07:00
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["dataset"]
|
|
|
|
assert res_data["data"]["dataset"]["urn"] == urn
|
|
|
|
assert res_data["data"]["dataset"]["name"] == dataset_name
|
|
|
|
assert res_data["data"]["dataset"]["platform"]["urn"] == platform
|
2021-08-04 12:26:29 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_ingest_with_system_metadata(auth_session, test_run_ingestion):
|
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/entities?action=ingest",
|
2021-08-04 12:26:29 -07:00
|
|
|
headers=restli_default_headers,
|
|
|
|
json={
|
2022-02-02 13:19:15 -08:00
|
|
|
"entity": {
|
|
|
|
"value": {
|
|
|
|
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
2023-02-27 19:06:16 +05:30
|
|
|
"urn": get_root_urn(),
|
2022-02-02 13:19:15 -08:00
|
|
|
"aspects": [
|
|
|
|
{
|
|
|
|
"com.linkedin.identity.CorpUserInfo": {
|
|
|
|
"active": True,
|
2022-12-27 00:08:01 +05:30
|
|
|
"displayName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
"email": "datahub@linkedin.com",
|
|
|
|
"title": "CEO",
|
2022-12-27 00:08:01 +05:30
|
|
|
"fullName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"systemMetadata": {
|
|
|
|
"lastObserved": 1628097379571,
|
|
|
|
"runId": "af0fe6e4-f547-11eb-81b2-acde48001122",
|
|
|
|
},
|
2021-08-04 12:26:29 -07:00
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_ingest_with_blank_system_metadata(auth_session):
|
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/entities?action=ingest",
|
2021-08-04 12:26:29 -07:00
|
|
|
headers=restli_default_headers,
|
|
|
|
json={
|
2022-02-02 13:19:15 -08:00
|
|
|
"entity": {
|
|
|
|
"value": {
|
|
|
|
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
2023-02-27 19:06:16 +05:30
|
|
|
"urn": get_root_urn(),
|
2022-02-02 13:19:15 -08:00
|
|
|
"aspects": [
|
|
|
|
{
|
|
|
|
"com.linkedin.identity.CorpUserInfo": {
|
|
|
|
"active": True,
|
2022-12-27 00:08:01 +05:30
|
|
|
"displayName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
"email": "datahub@linkedin.com",
|
|
|
|
"title": "CEO",
|
2022-12-27 00:08:01 +05:30
|
|
|
"fullName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"systemMetadata": {},
|
2021-08-04 12:26:29 -07:00
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_ingest_without_system_metadata(auth_session):
|
|
|
|
response = auth_session.post(
|
|
|
|
f"{auth_session.gms_url()}/entities?action=ingest",
|
2021-08-04 12:26:29 -07:00
|
|
|
headers=restli_default_headers,
|
|
|
|
json={
|
2022-02-02 13:19:15 -08:00
|
|
|
"entity": {
|
|
|
|
"value": {
|
|
|
|
"com.linkedin.metadata.snapshot.CorpUserSnapshot": {
|
2023-02-27 19:06:16 +05:30
|
|
|
"urn": get_root_urn(),
|
2022-02-02 13:19:15 -08:00
|
|
|
"aspects": [
|
|
|
|
{
|
|
|
|
"com.linkedin.identity.CorpUserInfo": {
|
|
|
|
"active": True,
|
2022-12-27 00:08:01 +05:30
|
|
|
"displayName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
"email": "datahub@linkedin.com",
|
|
|
|
"title": "CEO",
|
2022-12-27 00:08:01 +05:30
|
|
|
"fullName": "DataHub",
|
2022-02-02 13:19:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-08-04 12:26:29 -07:00
|
|
|
},
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
2021-09-02 19:05:13 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_app_config(auth_session):
|
2021-09-02 19:05:13 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query appConfig {\n
|
|
|
|
appConfig {\n
|
|
|
|
analyticsConfig {\n
|
|
|
|
enabled\n
|
|
|
|
}\n
|
|
|
|
policiesConfig {\n
|
|
|
|
enabled\n
|
|
|
|
platformPrivileges {\n
|
|
|
|
type\n
|
|
|
|
displayName\n
|
|
|
|
description\n
|
|
|
|
}\n
|
|
|
|
resourcePrivileges {\n
|
|
|
|
resourceType\n
|
|
|
|
resourceTypeDisplayName\n
|
|
|
|
entityType\n
|
|
|
|
privileges {\n
|
|
|
|
type\n
|
|
|
|
displayName\n
|
|
|
|
description\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}"""
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-09-02 19:05:13 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["appConfig"]
|
|
|
|
assert res_data["data"]["appConfig"]["analyticsConfig"]["enabled"] is True
|
|
|
|
assert res_data["data"]["appConfig"]["policiesConfig"]["enabled"] is True
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_frontend_me_query(auth_session):
|
2021-09-02 19:05:13 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query me {\n
|
|
|
|
me {\n
|
|
|
|
corpUser {\n
|
|
|
|
urn\n
|
|
|
|
username\n
|
|
|
|
editableInfo {\n
|
|
|
|
pictureLink\n
|
|
|
|
}\n
|
|
|
|
info {\n
|
|
|
|
firstName\n
|
|
|
|
fullName\n
|
|
|
|
title\n
|
|
|
|
email\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
platformPrivileges {\n
|
|
|
|
viewAnalytics
|
|
|
|
managePolicies
|
2021-11-22 16:33:14 -08:00
|
|
|
manageIdentities
|
2022-06-08 21:13:22 -04:00
|
|
|
manageUserCredentials
|
|
|
|
generatePersonalAccessTokens
|
2021-09-02 19:05:13 -07:00
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}"""
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-09-02 19:05:13 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
2023-02-27 19:06:16 +05:30
|
|
|
assert res_data["data"]["me"]["corpUser"]["urn"] == get_root_urn()
|
2021-09-02 19:05:13 -07:00
|
|
|
assert res_data["data"]["me"]["platformPrivileges"]["viewAnalytics"] is True
|
2021-09-20 11:58:31 -07:00
|
|
|
assert res_data["data"]["me"]["platformPrivileges"]["managePolicies"] is True
|
2022-06-08 21:13:22 -04:00
|
|
|
assert res_data["data"]["me"]["platformPrivileges"]["manageUserCredentials"] is True
|
2021-11-22 16:33:14 -08:00
|
|
|
assert res_data["data"]["me"]["platformPrivileges"]["manageIdentities"] is True
|
2022-02-02 13:19:15 -08:00
|
|
|
assert (
|
|
|
|
res_data["data"]["me"]["platformPrivileges"]["generatePersonalAccessTokens"]
|
|
|
|
is True
|
|
|
|
)
|
2021-09-20 11:58:31 -07:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_list_users(auth_session):
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query listUsers($input: ListUsersInput!) {\n
|
|
|
|
listUsers(input: $input) {\n
|
|
|
|
start\n
|
|
|
|
count\n
|
|
|
|
total\n
|
|
|
|
users {\n
|
|
|
|
urn\n
|
|
|
|
type\n
|
|
|
|
username\n
|
|
|
|
properties {\n
|
|
|
|
firstName
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"start": "0",
|
|
|
|
"count": "2",
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["listUsers"]
|
2022-02-02 13:19:15 -08:00
|
|
|
assert res_data["data"]["listUsers"]["start"] == 0
|
|
|
|
assert res_data["data"]["listUsers"]["count"] == 2
|
|
|
|
assert (
|
|
|
|
len(res_data["data"]["listUsers"]["users"]) >= 2
|
|
|
|
) # Length of default user set.
|
|
|
|
|
2021-10-07 16:14:35 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
@pytest.mark.dependency()
|
|
|
|
def test_list_groups(auth_session):
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query listGroups($input: ListGroupsInput!) {\n
|
|
|
|
listGroups(input: $input) {\n
|
|
|
|
start\n
|
|
|
|
count\n
|
|
|
|
total\n
|
|
|
|
groups {\n
|
|
|
|
urn\n
|
|
|
|
type\n
|
|
|
|
name\n
|
|
|
|
properties {\n
|
|
|
|
displayName
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"start": "0",
|
|
|
|
"count": "2",
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["listGroups"]
|
2022-02-02 13:19:15 -08:00
|
|
|
assert res_data["data"]["listGroups"]["start"] == 0
|
|
|
|
assert res_data["data"]["listGroups"]["count"] == 2
|
|
|
|
assert (
|
|
|
|
len(res_data["data"]["listGroups"]["groups"]) >= 2
|
|
|
|
) # Length of default group set.
|
|
|
|
|
2021-10-07 16:14:35 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
@pytest.mark.dependency(
|
2024-09-27 11:31:25 -05:00
|
|
|
depends=["test_list_groups"]
|
2022-02-02 13:19:15 -08:00
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_add_remove_members_from_group(auth_session):
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
# Assert no group edges for user jdoe
|
|
|
|
json = {
|
|
|
|
"query": """query corpUser($urn: String!) {\n
|
|
|
|
corpUser(urn: $urn) {\n
|
|
|
|
urn\n
|
2022-07-20 16:55:10 -07:00
|
|
|
relationships(input: { types: ["IsMemberOfNativeGroup"], direction: OUTGOING, start: 0, count: 1 }) {\n
|
2021-10-07 16:14:35 -07:00
|
|
|
total\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": "urn:li:corpuser:jdoe"},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpUser"]
|
2022-02-02 13:19:15 -08:00
|
|
|
assert res_data["data"]["corpUser"]["relationships"]["total"] == 0
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
# Add jdoe to group
|
|
|
|
json = {
|
|
|
|
"query": """mutation addGroupMembers($input: AddGroupMembersInput!) {\n
|
|
|
|
addGroupMembers(input: $input) }""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
|
|
|
"groupUrn": "urn:li:corpGroup:bfoo",
|
2022-02-02 13:19:15 -08:00
|
|
|
"userUrns": ["urn:li:corpuser:jdoe"],
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
# Verify the member has been added
|
2024-09-27 11:31:25 -05:00
|
|
|
_ensure_user_relationship_present(auth_session, "urn:li:corpuser:jdoe", 1)
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
# Now remove jdoe from the group
|
|
|
|
json = {
|
|
|
|
"query": """mutation removeGroupMembers($input: RemoveGroupMembersInput!) {\n
|
|
|
|
removeGroupMembers(input: $input) }""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
|
|
|
"groupUrn": "urn:li:corpGroup:bfoo",
|
2022-02-02 13:19:15 -08:00
|
|
|
"userUrns": ["urn:li:corpuser:jdoe"],
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
# Verify the member has been removed
|
2024-09-27 11:31:25 -05:00
|
|
|
_ensure_user_relationship_present(auth_session, "urn:li:corpuser:jdoe", 0)
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2021-10-07 16:14:35 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
@pytest.mark.dependency()
|
|
|
|
def test_update_corp_group_properties(auth_session):
|
2022-02-17 22:47:59 -08:00
|
|
|
|
|
|
|
group_urn = "urn:li:corpGroup:bfoo"
|
|
|
|
|
|
|
|
# Update Corp Group Description
|
|
|
|
json = {
|
|
|
|
"query": """mutation updateCorpGroupProperties($urn: String!, $input: CorpGroupUpdateInput!) {\n
|
|
|
|
updateCorpGroupProperties(urn: $urn, input: $input) { urn } }""",
|
|
|
|
"variables": {
|
2022-06-30 16:00:50 +05:30
|
|
|
"urn": group_urn,
|
|
|
|
"input": {
|
|
|
|
"description": "My test description",
|
|
|
|
"slack": "test_group_slack",
|
|
|
|
"email": "test_group_email@email.com",
|
|
|
|
},
|
2022-02-17 22:47:59 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
print(res_data)
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2022-02-17 22:47:59 -08:00
|
|
|
assert res_data["data"]["updateCorpGroupProperties"] is not None
|
|
|
|
|
|
|
|
# Verify the description has been updated
|
|
|
|
json = {
|
|
|
|
"query": """query corpGroup($urn: String!) {\n
|
|
|
|
corpGroup(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
editableProperties {\n
|
|
|
|
description\n
|
|
|
|
slack\n
|
|
|
|
email\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {"urn": group_urn},
|
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2022-02-17 22:47:59 -08:00
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpGroup"]
|
|
|
|
assert res_data["data"]["corpGroup"]["editableProperties"]
|
|
|
|
assert res_data["data"]["corpGroup"]["editableProperties"] == {
|
2022-06-30 16:00:50 +05:30
|
|
|
"description": "My test description",
|
|
|
|
"slack": "test_group_slack",
|
|
|
|
"email": "test_group_email@email.com",
|
2022-02-17 22:47:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Reset the editable properties
|
|
|
|
json = {
|
2022-07-14 22:04:06 +05:30
|
|
|
"query": """mutation updateCorpGroupProperties($urn: String!, $input: CorpGroupUpdateInput!) {\n
|
|
|
|
updateCorpGroupProperties(urn: $urn, input: $input) { urn } }""",
|
2022-02-17 22:47:59 -08:00
|
|
|
"variables": {
|
2022-06-30 16:00:50 +05:30
|
|
|
"urn": group_urn,
|
|
|
|
"input": {"description": "", "slack": "", "email": ""},
|
2022-02-17 22:47:59 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
|
2022-02-17 22:47:59 -08:00
|
|
|
@pytest.mark.dependency(
|
2022-06-30 16:00:50 +05:30
|
|
|
depends=[
|
|
|
|
"test_update_corp_group_properties",
|
|
|
|
]
|
2022-02-17 22:47:59 -08:00
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_update_corp_group_description(auth_session):
|
2022-02-17 22:47:59 -08:00
|
|
|
|
|
|
|
group_urn = "urn:li:corpGroup:bfoo"
|
|
|
|
|
|
|
|
# Update Corp Group Description
|
|
|
|
json = {
|
|
|
|
"query": """mutation updateDescription($input: DescriptionUpdateInput!) {\n
|
|
|
|
updateDescription(input: $input) }""",
|
|
|
|
"variables": {
|
2022-06-30 16:00:50 +05:30
|
|
|
"input": {"description": "My test description", "resourceUrn": group_urn},
|
2022-02-17 22:47:59 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
print(res_data)
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2022-02-17 22:47:59 -08:00
|
|
|
assert res_data["data"]["updateDescription"] is True
|
|
|
|
|
|
|
|
# Verify the description has been updated
|
|
|
|
json = {
|
|
|
|
"query": """query corpGroup($urn: String!) {\n
|
|
|
|
corpGroup(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
editableProperties {\n
|
|
|
|
description\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {"urn": group_urn},
|
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2022-02-17 22:47:59 -08:00
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpGroup"]
|
|
|
|
assert res_data["data"]["corpGroup"]["editableProperties"]
|
2022-06-30 16:00:50 +05:30
|
|
|
assert (
|
|
|
|
res_data["data"]["corpGroup"]["editableProperties"]["description"]
|
|
|
|
== "My test description"
|
|
|
|
)
|
2022-02-17 22:47:59 -08:00
|
|
|
|
|
|
|
# Reset Corp Group Description
|
|
|
|
json = {
|
|
|
|
"query": """mutation updateDescription($input: DescriptionUpdateInput!) {\n
|
|
|
|
updateDescription(input: $input) }""",
|
|
|
|
"variables": {
|
2022-06-30 16:00:50 +05:30
|
|
|
"input": {"description": "", "resourceUrn": group_urn},
|
2022-02-17 22:47:59 -08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2022-02-17 22:47:59 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
@pytest.mark.dependency(
|
|
|
|
depends=[
|
|
|
|
"test_list_groups",
|
|
|
|
"test_add_remove_members_from_group",
|
|
|
|
]
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_remove_user(auth_session):
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """mutation removeUser($urn: String!) {\n
|
|
|
|
removeUser(urn: $urn) }""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": "urn:li:corpuser:jdoe"},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query corpUser($urn: String!) {\n
|
|
|
|
corpUser(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
properties {\n
|
|
|
|
firstName\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": "urn:li:corpuser:jdoe"},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2021-10-07 16:14:35 -07:00
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpUser"]
|
|
|
|
assert res_data["data"]["corpUser"]["properties"] is None
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
|
|
|
@pytest.mark.dependency(
|
|
|
|
depends=[
|
|
|
|
"test_list_groups",
|
|
|
|
"test_add_remove_members_from_group",
|
|
|
|
]
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_remove_group(auth_session):
|
2022-11-03 22:53:49 +05:30
|
|
|
group_urn = "urn:li:corpGroup:bfoo"
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """mutation removeGroup($urn: String!) {\n
|
|
|
|
removeGroup(urn: $urn) }""",
|
2022-11-03 22:53:49 +05:30
|
|
|
"variables": {"urn": group_urn},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
_ensure_group_not_present(auth_session, group_urn)
|
2021-10-07 16:14:35 -07:00
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
|
|
|
@pytest.mark.dependency(
|
|
|
|
depends=[
|
|
|
|
"test_list_groups",
|
|
|
|
"test_remove_group",
|
|
|
|
]
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_create_group(auth_session):
|
2021-10-07 16:14:35 -07:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """mutation createGroup($input: CreateGroupInput!) {\n
|
|
|
|
createGroup(input: $input) }""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
2022-02-01 10:47:45 -08:00
|
|
|
"id": "test-id",
|
2021-10-07 16:14:35 -07:00
|
|
|
"name": "Test Group",
|
2022-02-02 13:19:15 -08:00
|
|
|
"description": "My test group",
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query corpGroup($urn: String!) {\n
|
|
|
|
corpGroup(urn: $urn) {\n
|
|
|
|
urn\n
|
|
|
|
properties {\n
|
|
|
|
displayName\n
|
|
|
|
}\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-02-02 13:19:15 -08:00
|
|
|
"variables": {"urn": "urn:li:corpGroup:test-id"},
|
2021-10-07 16:14:35 -07:00
|
|
|
}
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-07 16:14:35 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["corpGroup"]
|
2021-10-26 21:23:08 -07:00
|
|
|
assert res_data["data"]["corpGroup"]["properties"]["displayName"] == "Test Group"
|
|
|
|
|
2022-02-02 13:19:15 -08:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_home_page_recommendations(auth_session):
|
2021-10-26 21:23:08 -07:00
|
|
|
|
|
|
|
min_expected_recommendation_modules = 0
|
|
|
|
|
|
|
|
json = {
|
|
|
|
"query": """query listRecommendations($input: ListRecommendationsInput!) {\n
|
|
|
|
listRecommendations(input: $input) { modules { title } } }""",
|
|
|
|
"variables": {
|
|
|
|
"input": {
|
2023-02-27 19:06:16 +05:30
|
|
|
"userUrn": get_root_urn(),
|
2022-02-02 13:19:15 -08:00
|
|
|
"requestContext": {"scenario": "HOME"},
|
|
|
|
"limit": 5,
|
2021-10-26 21:23:08 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-26 21:23:08 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-26 21:23:08 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
print(res_data)
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["listRecommendations"]
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2022-02-02 13:19:15 -08:00
|
|
|
assert (
|
|
|
|
len(res_data["data"]["listRecommendations"]["modules"])
|
|
|
|
> min_expected_recommendation_modules
|
|
|
|
)
|
|
|
|
|
2021-10-26 21:23:08 -07:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_search_results_recommendations(auth_session):
|
2021-10-26 21:23:08 -07:00
|
|
|
|
|
|
|
# This test simply ensures that the recommendations endpoint does not return an error.
|
|
|
|
json = {
|
|
|
|
"query": """query listRecommendations($input: ListRecommendationsInput!) {\n
|
2022-06-30 16:00:50 +05:30
|
|
|
listRecommendations(input: $input) { modules { title } } }""",
|
2021-10-26 21:23:08 -07:00
|
|
|
"variables": {
|
|
|
|
"input": {
|
2023-02-27 19:06:16 +05:30
|
|
|
"userUrn": get_root_urn(),
|
2021-10-26 21:23:08 -07:00
|
|
|
"requestContext": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"scenario": "SEARCH_RESULTS",
|
|
|
|
"searchRequestContext": {"query": "asdsdsdds", "filters": []},
|
2021-10-26 21:23:08 -07:00
|
|
|
},
|
2022-02-02 13:19:15 -08:00
|
|
|
"limit": 5,
|
2021-10-26 21:23:08 -07:00
|
|
|
}
|
2022-02-02 13:19:15 -08:00
|
|
|
},
|
2021-10-26 21:23:08 -07:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-10-26 21:23:08 -07:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2021-11-22 16:33:14 -08:00
|
|
|
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_generate_personal_access_token(auth_session):
|
2021-11-22 16:33:14 -08:00
|
|
|
|
|
|
|
# Test success case
|
|
|
|
json = {
|
|
|
|
"query": """query getAccessToken($input: GetAccessTokenInput!) {\n
|
|
|
|
getAccessToken(input: $input) {\n
|
|
|
|
accessToken\n
|
|
|
|
}\n
|
|
|
|
}""",
|
|
|
|
"variables": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"input": {
|
|
|
|
"type": "PERSONAL",
|
2023-02-27 19:06:16 +05:30
|
|
|
"actorUrn": get_root_urn(),
|
2022-02-02 13:19:15 -08:00
|
|
|
"duration": "ONE_MONTH",
|
|
|
|
}
|
|
|
|
},
|
2021-11-22 16:33:14 -08:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-11-22 16:33:14 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
|
|
|
assert res_data["data"]
|
|
|
|
assert res_data["data"]["getAccessToken"]["accessToken"] is not None
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in res_data
|
2021-11-22 16:33:14 -08:00
|
|
|
|
|
|
|
# Test unauthenticated case
|
|
|
|
json = {
|
|
|
|
"query": """query getAccessToken($input: GetAccessTokenInput!) {\n
|
2022-07-14 22:04:06 +05:30
|
|
|
getAccessToken(input: $input) {\n
|
|
|
|
accessToken\n
|
|
|
|
}\n
|
2021-11-22 16:33:14 -08:00
|
|
|
}""",
|
|
|
|
"variables": {
|
2022-02-02 13:19:15 -08:00
|
|
|
"input": {
|
|
|
|
"type": "PERSONAL",
|
|
|
|
"actorUrn": "urn:li:corpuser:jsmith",
|
|
|
|
"duration": "ONE_DAY",
|
|
|
|
}
|
|
|
|
},
|
2021-11-22 16:33:14 -08:00
|
|
|
}
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
response = auth_session.post(f"{auth_session.frontend_url()}/api/v2/graphql", json=json)
|
2021-11-22 16:33:14 -08:00
|
|
|
response.raise_for_status()
|
|
|
|
res_data = response.json()
|
|
|
|
|
|
|
|
assert res_data
|
2022-02-02 13:19:15 -08:00
|
|
|
assert "errors" in res_data # Assert the request fails
|
2022-06-08 21:13:22 -04:00
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_native_user_endpoints(auth_session):
|
2022-06-08 21:13:22 -04:00
|
|
|
# Sign up tests
|
2024-09-27 11:31:25 -05:00
|
|
|
frontend_session = get_frontend_session()
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Test getting the invite token
|
|
|
|
get_invite_token_json = {
|
2022-09-23 16:48:23 -07:00
|
|
|
"query": """query getInviteToken($input: GetInviteTokenInput!) {\n
|
|
|
|
getInviteToken(input: $input){\n
|
2022-06-08 21:13:22 -04:00
|
|
|
inviteToken\n
|
|
|
|
}\n
|
2022-09-23 16:48:23 -07:00
|
|
|
}""",
|
|
|
|
"variables": {"input": {}},
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
get_invite_token_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/api/v2/graphql", json=get_invite_token_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
get_invite_token_response.raise_for_status()
|
|
|
|
get_invite_token_res_data = get_invite_token_response.json()
|
|
|
|
|
|
|
|
assert get_invite_token_res_data
|
|
|
|
assert get_invite_token_res_data["data"]
|
2022-09-23 16:48:23 -07:00
|
|
|
invite_token = get_invite_token_res_data["data"]["getInviteToken"]["inviteToken"]
|
2022-06-08 21:13:22 -04:00
|
|
|
assert invite_token is not None
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in get_invite_token_res_data
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Pass the invite token when creating the user
|
|
|
|
sign_up_json = {
|
|
|
|
"fullName": "Test User",
|
|
|
|
"email": "test@email.com",
|
|
|
|
"password": "password",
|
|
|
|
"title": "Date Engineer",
|
2022-06-30 16:00:50 +05:30
|
|
|
"inviteToken": invite_token,
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
sign_up_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/signUp", json=sign_up_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert sign_up_response
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in sign_up_response
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Creating the same user again fails
|
2022-06-30 16:00:50 +05:30
|
|
|
same_user_sign_up_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/signUp", json=sign_up_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert not same_user_sign_up_response
|
|
|
|
|
|
|
|
# Test that a bad invite token leads to failed sign up
|
|
|
|
bad_sign_up_json = {
|
|
|
|
"fullName": "Test2 User",
|
|
|
|
"email": "test2@email.com",
|
|
|
|
"password": "password",
|
|
|
|
"title": "Date Engineer",
|
2022-06-30 16:00:50 +05:30
|
|
|
"inviteToken": "invite_token",
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
2022-06-30 16:00:50 +05:30
|
|
|
bad_sign_up_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/signUp", json=bad_sign_up_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert not bad_sign_up_response
|
|
|
|
|
|
|
|
frontend_session.cookies.clear()
|
|
|
|
|
|
|
|
# Reset credentials tests
|
|
|
|
|
|
|
|
# Log in as root again
|
|
|
|
headers = {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
}
|
2022-08-10 17:04:28 +05:30
|
|
|
username, password = get_admin_credentials()
|
|
|
|
root_login_data = '{"username":"' + username + '", "password":"' + password + '"}'
|
2022-06-30 16:00:50 +05:30
|
|
|
frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/logIn", headers=headers, data=root_login_data
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Test creating the password reset token
|
|
|
|
create_reset_token_json = {
|
|
|
|
"query": """mutation createNativeUserResetToken($input: CreateNativeUserResetTokenInput!) {\n
|
|
|
|
createNativeUserResetToken(input: $input) {\n
|
|
|
|
resetToken\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-06-30 16:00:50 +05:30
|
|
|
"variables": {"input": {"userUrn": "urn:li:corpuser:test@email.com"}},
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
create_reset_token_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/api/v2/graphql", json=create_reset_token_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
create_reset_token_response.raise_for_status()
|
|
|
|
create_reset_token_res_data = create_reset_token_response.json()
|
|
|
|
|
|
|
|
assert create_reset_token_res_data
|
|
|
|
assert create_reset_token_res_data["data"]
|
2022-06-30 16:00:50 +05:30
|
|
|
reset_token = create_reset_token_res_data["data"]["createNativeUserResetToken"][
|
|
|
|
"resetToken"
|
|
|
|
]
|
2022-06-08 21:13:22 -04:00
|
|
|
assert reset_token is not None
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in create_reset_token_res_data
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Pass the reset token when resetting credentials
|
|
|
|
reset_credentials_json = {
|
|
|
|
"email": "test@email.com",
|
2023-03-20 14:04:42 -07:00
|
|
|
"password": "newpassword",
|
2022-06-30 16:00:50 +05:30
|
|
|
"resetToken": reset_token,
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
|
|
|
|
2022-06-30 16:00:50 +05:30
|
|
|
reset_credentials_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/resetNativeUserCredentials", json=reset_credentials_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert reset_credentials_response
|
2022-06-30 16:00:50 +05:30
|
|
|
assert "errors" not in reset_credentials_response
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
# Test that a bad reset token leads to failed response
|
|
|
|
bad_user_reset_credentials_json = {
|
|
|
|
"email": "test@email.com",
|
2023-03-20 14:04:42 -07:00
|
|
|
"password": "newerpassword",
|
2022-06-30 16:00:50 +05:30
|
|
|
"resetToken": "reset_token",
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
2022-06-30 16:00:50 +05:30
|
|
|
bad_reset_credentials_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/resetNativeUserCredentials",
|
2022-06-30 16:00:50 +05:30
|
|
|
json=bad_user_reset_credentials_json,
|
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert not bad_reset_credentials_response
|
|
|
|
|
|
|
|
# Test that only a native user can reset their password
|
|
|
|
jaas_user_reset_credentials_json = {
|
|
|
|
"email": "datahub",
|
|
|
|
"password": "password",
|
2022-06-30 16:00:50 +05:30
|
|
|
"resetToken": reset_token,
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
2022-06-30 16:00:50 +05:30
|
|
|
jaas_user_reset_credentials_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/resetNativeUserCredentials",
|
2022-06-30 16:00:50 +05:30
|
|
|
json=jaas_user_reset_credentials_json,
|
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
assert not jaas_user_reset_credentials_response
|
|
|
|
|
|
|
|
# Tests that unauthenticated users can't invite users or send reset password links
|
|
|
|
|
2023-03-20 14:04:42 -07:00
|
|
|
unauthenticated_session = requests.Session()
|
2022-06-08 21:13:22 -04:00
|
|
|
|
2023-03-20 14:04:42 -07:00
|
|
|
unauthenticated_get_invite_token_response = unauthenticated_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/api/v2/graphql", json=get_invite_token_json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
2024-08-13 15:53:23 -05:00
|
|
|
assert (
|
|
|
|
unauthenticated_get_invite_token_response.status_code == HTTPStatus.UNAUTHORIZED
|
|
|
|
)
|
2022-06-08 21:13:22 -04:00
|
|
|
|
|
|
|
unauthenticated_create_reset_token_json = {
|
|
|
|
"query": """mutation createNativeUserResetToken($input: CreateNativeUserResetTokenInput!) {\n
|
|
|
|
createNativeUserResetToken(input: $input) {\n
|
|
|
|
resetToken\n
|
|
|
|
}\n
|
|
|
|
}""",
|
2022-06-30 16:00:50 +05:30
|
|
|
"variables": {"input": {"userUrn": "urn:li:corpuser:test@email.com"}},
|
2022-06-08 21:13:22 -04:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:04:42 -07:00
|
|
|
unauthenticated_create_reset_token_response = unauthenticated_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/api/v2/graphql",
|
2022-06-30 16:00:50 +05:30
|
|
|
json=unauthenticated_create_reset_token_json,
|
|
|
|
)
|
2024-08-13 15:53:23 -05:00
|
|
|
assert (
|
|
|
|
unauthenticated_create_reset_token_response.status_code
|
|
|
|
== HTTPStatus.UNAUTHORIZED
|
|
|
|
)
|
2022-06-30 16:00:50 +05:30
|
|
|
|
|
|
|
# cleanup steps
|
|
|
|
json = {
|
|
|
|
"query": """mutation removeUser($urn: String!) {\n
|
|
|
|
removeUser(urn: $urn) }""",
|
|
|
|
"variables": {"urn": "urn:li:corpuser:test@email.com"},
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:04:42 -07:00
|
|
|
frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/logIn", headers=headers, data=root_login_data
|
2023-03-20 14:04:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
remove_user_response = frontend_session.post(
|
2024-09-27 11:31:25 -05:00
|
|
|
f"{auth_session.frontend_url()}/api/v2/graphql", json=json
|
2022-06-30 16:00:50 +05:30
|
|
|
)
|
|
|
|
remove_user_response.raise_for_status()
|
|
|
|
assert "errors" not in remove_user_response
|