34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from apa_browser_adapter import REPO_ROOT, resolve_chrome_profile_base
|
|
|
|
|
|
def test_default_chrome_profile_is_outside_repo():
|
|
profile = resolve_chrome_profile_base(requested="")
|
|
assert profile == (REPO_ROOT.parent / "rpa-chrome-profile").resolve()
|
|
assert REPO_ROOT.resolve() not in profile.parents
|
|
assert profile != REPO_ROOT.resolve()
|
|
|
|
|
|
def test_env_path_inside_repo_is_rejected(tmp_path, monkeypatch):
|
|
inside = REPO_ROOT / "rpa_contract" / "screenshots" / "chrome-profile"
|
|
monkeypatch.delenv("RPA_CHROME_PROFILE", raising=False)
|
|
profile = resolve_chrome_profile_base(requested=str(inside))
|
|
assert profile == (REPO_ROOT.parent / "rpa-chrome-profile").resolve()
|
|
assert not _is_relative_to(profile, REPO_ROOT)
|
|
|
|
|
|
def test_env_path_outside_repo_is_kept(tmp_path):
|
|
outside = tmp_path / "custom-chrome"
|
|
outside.mkdir()
|
|
profile = resolve_chrome_profile_base(requested=str(outside))
|
|
assert profile == outside.resolve()
|
|
|
|
|
|
def _is_relative_to(path: Path, root: Path) -> bool:
|
|
try:
|
|
path.resolve().relative_to(root.resolve())
|
|
except ValueError:
|
|
return False
|
|
return True
|