fix: fetch dataset scope options from WorldQuant platform
This commit is contained in:
@@ -26,6 +26,8 @@ async def catalog(logged_in, app):
|
||||
401, headers={"WWW-Authenticate": "persona", "Location": "/authentication/persona/test"}
|
||||
)
|
||||
return httpx.Response(201, json={"token": {"expiry": 14400}})
|
||||
if request.method == "OPTIONS":
|
||||
return catalog_response(request)
|
||||
assert request.method == "GET"
|
||||
if request.url.path == "/users/self":
|
||||
return httpx.Response(200, json={"id": "TEST_USER"})
|
||||
@@ -209,7 +211,7 @@ async def test_scope_ownership_empty_and_unknown_fields_are_rejected(catalog):
|
||||
).status_code == 422
|
||||
assert (await prepare(client, version, dataset_id="TEST_NEWS")).status_code == 409
|
||||
assert (await prepare(client, version, scope={**SCOPE, "delay": 0})).status_code == 404
|
||||
assert (await prepare(client, version, scope={**SCOPE, "region": "CHN"})).status_code == 422
|
||||
assert (await prepare(client, version, scope={**SCOPE, "region": "CHN"})).status_code == 404
|
||||
subset = await prepare(client, version, selection="explicit", excluded_ids=["TEST_FIN_110"])
|
||||
assert subset.status_code == 201 and len(subset.json()["field_ids"]) == 122
|
||||
assert "TEST_FIN_110" not in subset.json()["field_ids"]
|
||||
@@ -241,9 +243,11 @@ async def test_retry_after_auth_wait_disconnect_and_collection_manifest(catalog)
|
||||
assert job["status"] == "completed" and delays == [2]
|
||||
manifest = await search(client, "/datasets/TEST_FIN/collection")
|
||||
assert manifest["collection_version"] == job["id"] and len(manifest["field_ids"]) == 123
|
||||
queued = await client.post(BASE + "/sync-jobs", json={"scope": SCOPE, "dataset_id": "TEST_FIN"})
|
||||
state["persona"] = True
|
||||
runner.client.authenticated = False
|
||||
waiting = await sync(catalog, "TEST_FIN")
|
||||
await runner.execute(queued.json()["id"])
|
||||
waiting = (await client.get("/api/v1/sync-jobs/" + queued.json()["id"])).json()
|
||||
assert waiting["status"] == "waiting_auth"
|
||||
assert (await search(client, "/datasets/TEST_FIN/collection")) == manifest
|
||||
await runner.disconnect()
|
||||
@@ -255,3 +259,19 @@ async def test_retry_after_auth_wait_disconnect_and_collection_manifest(catalog)
|
||||
await runner.execute(connect["id"])
|
||||
await runner.execute(waiting["id"])
|
||||
assert (await client.get("/api/v1/sync-jobs/" + waiting["id"])).json()["status"] == "completed"
|
||||
|
||||
|
||||
async def test_dynamic_platform_scopes_and_validation(catalog):
|
||||
client, runner, _ = catalog
|
||||
options = (await client.get(BASE + "/scopes")).json()
|
||||
assert "IND" in options["regions_by_type"]["EQUITY"]
|
||||
assert (await sync(catalog, scope={**SCOPE, "region": "IND", "universe": "TOP500"}))["status"] == "completed"
|
||||
invalid = await client.post(BASE + "/sync-jobs", json={"scope": {**SCOPE, "region": "IND"}})
|
||||
assert invalid.status_code == 422
|
||||
from app.ai.tools import EmptyArgs, read_tool
|
||||
ai = await read_tool(None, "get_catalog_scopes", EmptyArgs(), runner.client)
|
||||
assert ai["instrument_options"] == options["instrument_options"]
|
||||
assert ai["_meta"]["source"] == "worldquant_platform"
|
||||
runner.client.disconnect()
|
||||
assert (await client.get(BASE + "/scopes")).status_code == 409
|
||||
assert (await search(client))["total"] == 0
|
||||
|
||||
Reference in New Issue
Block a user