feat: configure cloud API endpoints by stand

This commit is contained in:
Repinoid
2026-10-25 17:43:42 +03:00
parent 5b19094a4d
commit 1f8e00e4f9
7 changed files with 53 additions and 79 deletions
+14 -14
View File
@@ -2,6 +2,12 @@
Тесты: auth.py — режимы, стенды, URL, cookie.
"""
import api.auth as auth
from api.http_client import API_ENDPOINTS, STANDS
def test_api_endpoint_map_has_all_three_stands():
assert list(API_ENDPOINTS) == ["dev", "test", "prod"]
assert len(STANDS) == 3
def test_polygon_url_construction(monkeypatch):
@@ -125,18 +131,15 @@ def test_whitelist_stand_invalid(monkeypatch):
assert auth.get_polygon_stand() == "test" # fallback
def test_cloud_detection_includes_configured_prod_endpoint(monkeypatch):
def test_cloud_detection_includes_prod_endpoint_from_source_map(monkeypatch):
from flask import Flask
prod_endpoint = "https://prod.example/api/v1/svc"
prod_endpoint = API_ENDPOINTS["prod"]
app = Flask(__name__)
app.config["NUBES_API_ENDPOINT"] = auth.STANDS[1]
app.config["NUBES_API_PROD_ENDPOINT"] = prod_endpoint
captured = {}
def fake_detect(token, endpoints):
def fake_detect(token):
captured["token"] = token
captured["endpoints"] = endpoints
return prod_endpoint
monkeypatch.setattr(auth, "detect_endpoint", fake_detect)
@@ -145,14 +148,13 @@ def test_cloud_detection_includes_configured_prod_endpoint(monkeypatch):
assert auth._cached_detect("prod-token") == prod_endpoint
assert captured["token"] == "prod-token"
assert captured["endpoints"] == [*auth.STANDS, prod_endpoint]
def test_detect_endpoint_tries_configured_prod_endpoint(monkeypatch):
def test_detect_endpoint_tries_prod_endpoint(monkeypatch):
from api import http_client
prod_endpoint = "https://prod.example/api/v1/svc"
endpoints = [*auth.STANDS, prod_endpoint]
prod_endpoint = API_ENDPOINTS["prod"]
endpoints = STANDS
attempted = []
class FakeHttpClient:
@@ -171,13 +173,11 @@ def test_detect_endpoint_tries_configured_prod_endpoint(monkeypatch):
assert attempted == endpoints
def test_get_stand_labels_configured_prod_endpoint(monkeypatch):
def test_get_stand_labels_prod_endpoint(monkeypatch):
from flask import Flask
prod_endpoint = "https://prod.example/api/v1/svc"
prod_endpoint = API_ENDPOINTS["prod"]
app = Flask(__name__)
app.config["NUBES_API_ENDPOINT"] = auth.STANDS[1]
app.config["NUBES_API_PROD_ENDPOINT"] = prod_endpoint
monkeypatch.setattr(auth, "get_mode", lambda: "cloud")
monkeypatch.setattr(auth, "get_token", lambda: "prod-token")
monkeypatch.setattr(auth, "_cached_detect", lambda token: prod_endpoint)