-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from nuclia.data import get_auth | ||
from nuclia.data import get_config | ||
from nuclia.sdk.kbs import NucliaKBS | ||
from nuclia_e2e.tests.data import TEST_ACCOUNT_SLUG | ||
|
||
import aiohttp | ||
import asyncio | ||
|
@@ -19,12 +20,10 @@ | |
import string | ||
import tempfile | ||
|
||
from .data import TEST_ACCOUNT_SLUG | ||
|
||
TEST_ENV = os.environ.get("TEST_ENV") | ||
|
||
# All tests that needs some existing account will use the one configured in the global "permanent_account_slug" | ||
# with some predefined user credentials without expiration: | ||
# All tests that needs some existing account will use the one configured in | ||
# the global "permanent_account_slug" with some predefined user credentials without expiration: | ||
# "permanent_account_owner_pat": PAT token for `[email protected]` on the suitable account | ||
|
||
CLUSTERS_CONFIG = { | ||
|
@@ -136,7 +135,8 @@ async def send_onboard_inquiry(self, data): | |
|
||
async def create_account(self, slug): | ||
if not self.access_token: | ||
raise ValueError("Access token is not set. Please provide an access token.") | ||
msg = "Access token is not set. Please provide an access token." | ||
raise ValueError(msg) | ||
url = f"{self.base_url}/api/v1/accounts" | ||
async with self.session.post( | ||
url, json={"slug": slug, "title": slug}, headers=self.auth_headers | ||
|
@@ -168,7 +168,7 @@ def global_api(aiohttp_session): | |
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
@pytest.fixture() | ||
def global_api_config(): | ||
global_config = CLUSTERS_CONFIG[TEST_ENV]["global"] | ||
nuclia.BASE = global_config["base_url"] | ||
|
@@ -182,7 +182,6 @@ def global_api_config(): | |
|
||
|
||
@pytest.fixture( | ||
scope="function", | ||
params=[pytest.param(zone, id=zone["name"]) for zone in CLUSTERS_CONFIG[TEST_ENV]["zones"]], | ||
) | ||
def regional_api_config(request, global_api_config): | ||
|
@@ -194,7 +193,7 @@ def regional_api_config(request, global_api_config): | |
config.set_default_account(global_api_config["permanent_account_slug"]) | ||
config.set_default_zone(zone_config["zone_slug"]) | ||
zone_config["test_kb_slug"] = "{test_kb_slug}-{name}".format(**zone_config) | ||
yield zone_config | ||
return zone_config | ||
|
||
|
||
class EmailUtil: | ||
|
@@ -261,7 +260,7 @@ async def get_last_email_body(self, test_address): | |
async def wait_for_email_signup_link(self, email_address, max_wait_time=20): | ||
print(f"waiting 10 seconds for signup email at {email_address}") | ||
signup_url = None | ||
for i in range(max_wait_time): | ||
for _ in range(max_wait_time): | ||
print("still waiting...") | ||
await asyncio.sleep(1) | ||
body = await self.get_last_email_body(email_address) | ||
|
@@ -276,11 +275,10 @@ async def wait_for_email_signup_link(self, email_address, max_wait_time=20): | |
|
||
@pytest.fixture(scope="session") | ||
def email_util(): | ||
util = EmailUtil("[email protected]", "oynpctapnzwqjxol") | ||
return util | ||
return EmailUtil("[email protected]", "oynpctapnzwqjxol") | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
@pytest.fixture() | ||
async def cleanup_test_account(global_api: GlobalAPI): | ||
await global_api.manager.delete_account(TEST_ACCOUNT_SLUG) | ||
|
||
|
@@ -289,13 +287,11 @@ async def cleanup_test_account(global_api: GlobalAPI): | |
await global_api.manager.delete_account(TEST_ACCOUNT_SLUG) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
@pytest.fixture() | ||
async def clean_kb_test(request, regional_api_config): | ||
kbs = NucliaKBS() | ||
try: | ||
await asyncio.to_thread(partial(kbs.delete, slug=regional_api_config["test_kb_slug"])) | ||
except ValueError: | ||
# Raised by sdk when kb not found | ||
pass | ||
|
||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from collections.abc import Coroutine | ||
from datetime import datetime | ||
from datetime import timedelta | ||
from datetime import timezone | ||
|
@@ -23,7 +24,6 @@ | |
from pathlib import Path | ||
from time import monotonic | ||
from typing import Any | ||
from typing import Coroutine | ||
|
||
import asyncio | ||
import backoff | ||
|
@@ -189,7 +189,8 @@ async def condition() -> tuple[bool, Any]: | |
continue | ||
for fc in res.computedmetadata.field_classifications: | ||
if fc.field.field_type.name == "GENERIC": | ||
# in case only generic fields are found, result won't be ever trur and condition will fail. | ||
# in case only generic fields are found, | ||
# result won't be ever true and condition will fail. | ||
continue | ||
|
||
# heuristic, but [email protected] enough for now, | ||
|
@@ -310,13 +311,13 @@ async def condition() -> tuple[bool, Any]: | |
partial( | ||
kb.logs.query, | ||
type=EventType.CHAT, | ||
query=ActivityLogsChatQuery(year_month="{dt.year}-{dt.month}".format(dt=now), filters={}), | ||
query=ActivityLogsChatQuery(year_month=f"{now.year}-{now.month}", filters={}), | ||
) | ||
) | ||
if len(logs.data) >= 2: | ||
# as the asks may be retried more than once (because some times rephrase doesn't always work) | ||
# we need to check the last logs. The way the tests are setup if we reach here is because we validated | ||
# that we got the expected results on ask, so the log should match this reasoning. | ||
# we need to check the last logs. The way the tests are setup if we reach here is because we | ||
# validated that we got the expected results on ask, so the log should match this reasoning. | ||
if logs.data[-2].question == "why cocoa prices high?" and logs.data[-1].question == "when?": | ||
return (True, logs) | ||
return (False, None) | ||
|
@@ -331,7 +332,7 @@ async def condition() -> tuple[bool, Any]: | |
partial( | ||
kb.logs.query, | ||
type=EventType.SEARCH, | ||
query=ActivityLogsSearchQuery(year_month="{dt.year}-{dt.month}".format(dt=now), filters={}), | ||
query=ActivityLogsSearchQuery(year_month=f"{now.year}-{now.month}", filters={}), | ||
) | ||
) | ||
assert logs.data[-1].question == "why cocoa prices high?" | ||
|
@@ -346,7 +347,7 @@ async def run_test_kb_deletion(regional_api_config): | |
assert kbid is None | ||
|
||
|
||
@pytest.mark.asyncio_cooperative | ||
@pytest.mark.asyncio_cooperative() | ||
async def test_kb(regional_api_config, clean_kb_test): | ||
""" | ||
Test a chain of operations that simulates a normal use of a knowledgebox, just concentrated | ||
|
@@ -375,9 +376,9 @@ async def test_kb(regional_api_config, clean_kb_test): | |
# Upload a new resource and validate that is correctly processed and stored in nuclia | ||
(await run_test_upload_and_process(regional_api_config),) | ||
|
||
# Wait for both labeller task results to be consolidated in nucliadb while we also run semantic search | ||
# and a generative question. This /find and /ask requests are crafted so they trigger all the existing calls | ||
# to predict features | ||
# Wait for both labeller task results to be consolidated in nucliadb while we also run semantic search | ||
# and a generative question. This /find and /ask requests are crafted so they trigger | ||
# all the existing calls to predict features | ||
await asyncio.gather( | ||
run_test_check_da_labeller_output(regional_api_config), | ||
run_test_find(regional_api_config), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters