forked from mtusi2026/mtusi2026lab3
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client as PublicClient
|
||||
from scripts import lab
|
||||
|
||||
|
||||
def project_name():
|
||||
name = os.environ.get("LAB3_PROJECT", lab.settings().get("COMPOSE_PROJECT_NAME", "kuznetsov-lab3"))
|
||||
if name != "kuznetsov-lab3" and not name.startswith("kuznetsov-lab3-"):
|
||||
raise RuntimeError("Tests only operate on Kuznetsov lab3 projects")
|
||||
return name
|
||||
|
||||
|
||||
class Client(PublicClient):
|
||||
def __init__(self, base_url=None, ca_file=None, timeout=10):
|
||||
project_name()
|
||||
port = int(os.environ.get("LAB3_PORT", lab.settings().get("HTTP_PORT", "18103")))
|
||||
target = base_url or os.environ.get("BASE_URL") or f"http://127.0.0.1:{port}"
|
||||
parsed = urlsplit(target)
|
||||
if parsed.scheme != "http" or parsed.hostname not in ("127.0.0.1", "localhost") or parsed.port != port:
|
||||
raise RuntimeError("BASE_URL must match this lab's local port")
|
||||
for name in ("NO_PROXY", "no_proxy"):
|
||||
os.environ[name] = ",".join(filter(None, [os.environ.get(name), "localhost", "127.0.0.1"]))
|
||||
super().__init__(target, ca_file=ca_file, timeout=timeout)
|
||||
Reference in New Issue
Block a user