-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
62 lines (47 loc) · 1.97 KB
/
Copy pathconftest.py
File metadata and controls
62 lines (47 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from uipath.llm_client.settings import UiPathBaseSettings
from uipath.llm_client.settings.llmgateway import LLMGatewaySettings
@pytest.fixture(autouse=True, scope="session")
def setup_env():
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())
@pytest.fixture(scope="session")
def vcr_config():
import re
from vcr import VCR
from vcr.request import Request as VCRRequest
def filter_requests(request: VCRRequest) -> VCRRequest | None:
if "identity_/connect/token" in request.uri:
return None
is_uuid = lambda s: bool(
re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", s, re.I)
)
request.uri = "/".join(
["PLACEHOLDER" if is_uuid(item) else item for item in request.uri.split("/") if item]
)
request.headers = None
return request
def filter_responses(response: dict) -> dict | None:
"""Don't record responses with 4xx or 5xx status codes."""
status_code = response.get("status", {}).get("code", 200)
if 200 <= status_code < 300:
return response
return None
return {
"record_mode": "new_episodes",
"record_on_exception": False,
"allow_playback_repeats": False,
"decode_compressed_response": True,
"cassette_library_dir": "tests/cassettes",
"path_transformer": VCR.ensure_suffix(".yaml"),
"before_record_request": filter_requests,
"before_record_response": filter_responses,
}
def pytest_recording_configure(config, vcr):
from tests.sqlite_persister import SQLitePersister
vcr.register_persister(SQLitePersister)
# Only "llmgateway" is parameterized because Platform (agenthub) requires `uipath auth`
# credentials that are not available in CI.
@pytest.fixture(scope="session", params=["llmgateway"])
def client_settings(request: pytest.FixtureRequest) -> UiPathBaseSettings:
return LLMGatewaySettings()