test: retarget v2 coverage monkeypatch targets to definition modules after handler split (assertions unchanged)
This commit is contained in:
1 parent
6e0660e97b
commit
741eb387ed
7 files changed
+45
-48
No files matched your search
@@ -32,11 +32,9 @@ REPO_ROOT = Path(__file__).resolve().parents[2]
|
|||||||
sys.path.insert(0, str(REPO_ROOT))
|
sys.path.insert(0, str(REPO_ROOT))
|
||||||
|
|
||||||
import cloud.server as server_mod
|
import cloud.server as server_mod
|
||||||
|
from cloud.handler_fullauto import FullAutoError, _full_auto_branch_protection_ok, _full_auto_github_request
|
||||||
from cloud.server import (
|
from cloud.server import (
|
||||||
CloudControlPlaneHandler,
|
CloudControlPlaneHandler,
|
||||||
FullAutoError,
|
|
||||||
_full_auto_branch_protection_ok,
|
|
||||||
_full_auto_github_request,
|
|
||||||
init_db,
|
init_db,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ class AutomationTestCase(_Base):
|
|||||||
def test_automation_create_generic_error_502(self):
|
def test_automation_create_generic_error_502(self):
|
||||||
self._project()
|
self._project()
|
||||||
h = self._h(body={"name": "a1", "prompt": "p"})
|
h = self._h(body={"name": "a1", "prompt": "p"})
|
||||||
with mock.patch("cloud.server._auto_create",
|
with mock.patch("cloud.handler_automation._auto_create",
|
||||||
side_effect=RuntimeError("db boom")):
|
side_effect=RuntimeError("db boom")):
|
||||||
h._automation_create("u1", "p1")
|
h._automation_create("u1", "p1")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ class TodosAutomationLoopTestCase(_Base):
|
|||||||
def test_todos_update_generic_error_502(self):
|
def test_todos_update_generic_error_502(self):
|
||||||
todo = self._todo()
|
todo = self._todo()
|
||||||
h = self._h(body={"title": "new"})
|
h = self._h(body={"title": "new"})
|
||||||
with mock.patch("cloud.server._todo_update",
|
with mock.patch("cloud.handler_automation._todo_update",
|
||||||
side_effect=RuntimeError("db down")):
|
side_effect=RuntimeError("db down")):
|
||||||
h._todos_update("u1", "p1", todo["id"])
|
h._todos_update("u1", "p1", todo["id"])
|
||||||
self.assertEqual(self._last(h)[0], 502)
|
self.assertEqual(self._last(h)[0], 502)
|
||||||
@@ -509,7 +509,7 @@ class TodosAutomationLoopTestCase(_Base):
|
|||||||
|
|
||||||
def test_auto_memory_run_extracted_audits(self):
|
def test_auto_memory_run_extracted_audits(self):
|
||||||
h = self._h(body={})
|
h = self._h(body={})
|
||||||
with mock.patch("cloud.server._auto_process_due",
|
with mock.patch("cloud.handler_identity._auto_process_due",
|
||||||
return_value=[{"status": "extracted",
|
return_value=[{"status": "extracted",
|
||||||
"task_id": "t1"},
|
"task_id": "t1"},
|
||||||
{"status": "skipped",
|
{"status": "skipped",
|
||||||
@@ -756,7 +756,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
h.path = ("/oauth/github/login?client_id=c"
|
h.path = ("/oauth/github/login?client_id=c"
|
||||||
"&redirect_uri=https://example.com/cb")
|
"&redirect_uri=https://example.com/cb")
|
||||||
err = OAuthError("denied", reason="bad_client")
|
err = OAuthError("denied", reason="bad_client")
|
||||||
with mock.patch("cloud.server.start_oauth_login",
|
with mock.patch("cloud.handler_oauth.start_oauth_login",
|
||||||
side_effect=err):
|
side_effect=err):
|
||||||
h._oauth_login("/oauth/github/login")
|
h._oauth_login("/oauth/github/login")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
@@ -767,7 +767,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
h = self._h()
|
h = self._h()
|
||||||
h.path = ("/oauth/github/login?client_id=c"
|
h.path = ("/oauth/github/login?client_id=c"
|
||||||
"&redirect_uri=https://example.com/cb")
|
"&redirect_uri=https://example.com/cb")
|
||||||
with mock.patch("cloud.server.start_oauth_login",
|
with mock.patch("cloud.handler_oauth.start_oauth_login",
|
||||||
side_effect=ValueError("bad scope")):
|
side_effect=ValueError("bad scope")):
|
||||||
h._oauth_login("/oauth/github/login")
|
h._oauth_login("/oauth/github/login")
|
||||||
self.assertEqual(self._last(h)[0], 400)
|
self.assertEqual(self._last(h)[0], 400)
|
||||||
@@ -784,7 +784,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
"redirect_uri": "https://example.com/cb"})
|
"redirect_uri": "https://example.com/cb"})
|
||||||
h._authenticate = lambda: "u1"
|
h._authenticate = lambda: "u1"
|
||||||
err = OAuthError("denied", reason="bad_client")
|
err = OAuthError("denied", reason="bad_client")
|
||||||
with mock.patch("cloud.server.build_authorization_url",
|
with mock.patch("cloud.handler_oauth.build_authorization_url",
|
||||||
side_effect=err):
|
side_effect=err):
|
||||||
h._oauth_bind_initiate("github")
|
h._oauth_bind_initiate("github")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
@@ -795,7 +795,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
h = self._h(body={"client_id": "c",
|
h = self._h(body={"client_id": "c",
|
||||||
"redirect_uri": "https://example.com/cb"})
|
"redirect_uri": "https://example.com/cb"})
|
||||||
h._authenticate = lambda: "u1"
|
h._authenticate = lambda: "u1"
|
||||||
with mock.patch("cloud.server.build_authorization_url",
|
with mock.patch("cloud.handler_oauth.build_authorization_url",
|
||||||
side_effect=ValueError("bad scope")):
|
side_effect=ValueError("bad scope")):
|
||||||
h._oauth_bind_initiate("github")
|
h._oauth_bind_initiate("github")
|
||||||
self.assertEqual(self._last(h)[0], 400)
|
self.assertEqual(self._last(h)[0], 400)
|
||||||
@@ -813,8 +813,8 @@ class OauthGatewayTestCase(_Base):
|
|||||||
def create_state(self, provider, redirect_uri, client_id=None,
|
def create_state(self, provider, redirect_uri, client_id=None,
|
||||||
bind_user_id=None):
|
bind_user_id=None):
|
||||||
return "st1"
|
return "st1"
|
||||||
with mock.patch("cloud.server.OAuthStateStore", _Store), \
|
with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store), \
|
||||||
mock.patch("cloud.server.build_authorization_url",
|
mock.patch("cloud.handler_oauth.build_authorization_url",
|
||||||
return_value="https://example.com/auth"):
|
return_value="https://example.com/auth"):
|
||||||
h._oauth_bind_initiate("github")
|
h._oauth_bind_initiate("github")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
@@ -824,7 +824,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
def _finish_h(self, identity):
|
def _finish_h(self, identity):
|
||||||
h = self._h()
|
h = self._h()
|
||||||
h._oauth_clients = lambda provider: (None, None)
|
h._oauth_clients = lambda provider: (None, None)
|
||||||
patcher = mock.patch("cloud.server.handle_oauth_callback",
|
patcher = mock.patch("cloud.handler_oauth.handle_oauth_callback",
|
||||||
return_value=dict(identity))
|
return_value=dict(identity))
|
||||||
patcher.start()
|
patcher.start()
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
@@ -864,7 +864,7 @@ class OauthGatewayTestCase(_Base):
|
|||||||
h = self._finish_h({"external_id": "ext-new"})
|
h = self._finish_h({"external_id": "ext-new"})
|
||||||
with mock.patch.dict(os.environ,
|
with mock.patch.dict(os.environ,
|
||||||
{"SUB2API_BASE_URL": "https://gw.example"}), \
|
{"SUB2API_BASE_URL": "https://gw.example"}), \
|
||||||
mock.patch("cloud.server._ensure_sub2api_key",
|
mock.patch("cloud.handler_oauth._ensure_sub2api_key",
|
||||||
side_effect=RuntimeError("gw down")):
|
side_effect=RuntimeError("gw down")):
|
||||||
result = h._oauth_finish("github", "code", "st", "c", "r")
|
result = h._oauth_finish("github", "code", "st", "c", "r")
|
||||||
self.assertTrue(result[1])
|
self.assertTrue(result[1])
|
||||||
@@ -888,8 +888,8 @@ class OauthGatewayTestCase(_Base):
|
|||||||
def __init__(self, db_path):
|
def __init__(self, db_path):
|
||||||
self.conn = mock.Mock()
|
self.conn = mock.Mock()
|
||||||
self.conn.close.side_effect = RuntimeError("close down")
|
self.conn.close.side_effect = RuntimeError("close down")
|
||||||
with mock.patch("cloud.server.OAuthStateStore", _Store), \
|
with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store), \
|
||||||
mock.patch("cloud.server.handle_oauth_callback",
|
mock.patch("cloud.handler_oauth.handle_oauth_callback",
|
||||||
return_value={"bind_user_id": uid,
|
return_value={"bind_user_id": uid,
|
||||||
"external_id": "ext1"}):
|
"external_id": "ext1"}):
|
||||||
result = h._oauth_finish("github", "code", "st", "c", "r")
|
result = h._oauth_finish("github", "code", "st", "c", "r")
|
||||||
@@ -1174,7 +1174,7 @@ class WebhookBrowserFullAutoTestCase(_Base):
|
|||||||
h = self._full_auto_h({"repo": "o/r"})
|
h = self._full_auto_h({"repo": "o/r"})
|
||||||
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
||||||
"FULL_AUTO_ENABLED": "1"}), \
|
"FULL_AUTO_ENABLED": "1"}), \
|
||||||
mock.patch("cloud.server._resolve_app_token",
|
mock.patch("cloud.handler_fullauto._resolve_app_token",
|
||||||
return_value=None):
|
return_value=None):
|
||||||
h._full_auto_execute("u1")
|
h._full_auto_execute("u1")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
@@ -1189,7 +1189,7 @@ class WebhookBrowserFullAutoTestCase(_Base):
|
|||||||
from cloud.full_auto import FullAutoError
|
from cloud.full_auto import FullAutoError
|
||||||
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
||||||
"FULL_AUTO_ENABLED": "1"}), \
|
"FULL_AUTO_ENABLED": "1"}), \
|
||||||
mock.patch("cloud.server.auto_config_plan",
|
mock.patch("cloud.handler_fullauto.auto_config_plan",
|
||||||
side_effect=FullAutoError(
|
side_effect=FullAutoError(
|
||||||
"bad plan", reason="bad")):
|
"bad plan", reason="bad")):
|
||||||
h._full_auto_execute("u1")
|
h._full_auto_execute("u1")
|
||||||
@@ -1205,9 +1205,9 @@ class WebhookBrowserFullAutoTestCase(_Base):
|
|||||||
from cloud.full_auto import FullAutoDenied
|
from cloud.full_auto import FullAutoDenied
|
||||||
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
||||||
"FULL_AUTO_ENABLED": "1"}), \
|
"FULL_AUTO_ENABLED": "1"}), \
|
||||||
mock.patch("cloud.server.auto_config_plan",
|
mock.patch("cloud.handler_fullauto.auto_config_plan",
|
||||||
return_value=[{"step": "s1"}]), \
|
return_value=[{"step": "s1"}]), \
|
||||||
mock.patch("cloud.server.run_plan",
|
mock.patch("cloud.handler_fullauto.run_plan",
|
||||||
side_effect=FullAutoDenied(
|
side_effect=FullAutoDenied(
|
||||||
"nope", reason="step_denied")):
|
"nope", reason="step_denied")):
|
||||||
h._full_auto_execute("u1")
|
h._full_auto_execute("u1")
|
||||||
@@ -1223,9 +1223,9 @@ class WebhookBrowserFullAutoTestCase(_Base):
|
|||||||
from cloud.full_auto import FullAutoError
|
from cloud.full_auto import FullAutoError
|
||||||
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1",
|
||||||
"FULL_AUTO_ENABLED": "1"}), \
|
"FULL_AUTO_ENABLED": "1"}), \
|
||||||
mock.patch("cloud.server.auto_config_plan",
|
mock.patch("cloud.handler_fullauto.auto_config_plan",
|
||||||
return_value=[{"step": "s1"}]), \
|
return_value=[{"step": "s1"}]), \
|
||||||
mock.patch("cloud.server.run_plan",
|
mock.patch("cloud.handler_fullauto.run_plan",
|
||||||
side_effect=FullAutoError(
|
side_effect=FullAutoError(
|
||||||
"boom", reason="plan")):
|
"boom", reason="plan")):
|
||||||
h._full_auto_execute("u1")
|
h._full_auto_execute("u1")
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def add_summary(self, *a, **k):
|
def add_summary(self, *a, **k):
|
||||||
return 99
|
return 99
|
||||||
h = self._h(body={"goal": "g", "conclusion": "c"})
|
h = self._h(body={"goal": "g", "conclusion": "c"})
|
||||||
with mock.patch("cloud.server.MemoryStore", _Store):
|
with mock.patch("cloud.handler_identity.MemoryStore", _Store):
|
||||||
h._memory_create("u1", "p1")
|
h._memory_create("u1", "p1")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
self.assertEqual(code, 201)
|
self.assertEqual(code, 201)
|
||||||
@@ -272,12 +272,12 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def build_prompt_context(self, project_id, top_k=5):
|
def build_prompt_context(self, project_id, top_k=5):
|
||||||
return ""
|
return ""
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.MemoryStore", _Store):
|
with mock.patch("cloud.handler_identity.MemoryStore", _Store):
|
||||||
h._memory_list("p1", {})
|
h._memory_list("p1", {})
|
||||||
self.assertEqual(self._last(h)[0], 200)
|
self.assertEqual(self._last(h)[0], 200)
|
||||||
|
|
||||||
def test_memory_supersede_close_failure_swallowed(self):
|
def test_memory_supersede_close_failure_swallowed(self):
|
||||||
from cloud.server import MemoryStore
|
from cloud.handler_identity import MemoryStore
|
||||||
store = MemoryStore(self.db_path)
|
store = MemoryStore(self.db_path)
|
||||||
try:
|
try:
|
||||||
mid = store.add_summary("p1", "", "g", "c")
|
mid = store.add_summary("p1", "", "g", "c")
|
||||||
@@ -291,7 +291,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def deprecate(self, mid):
|
def deprecate(self, mid):
|
||||||
pass
|
pass
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.MemoryStore", _Store):
|
with mock.patch("cloud.handler_identity.MemoryStore", _Store):
|
||||||
h._memory_supersede("u1", "p1", str(mid))
|
h._memory_supersede("u1", "p1", str(mid))
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
self.assertEqual(code, 200)
|
self.assertEqual(code, 200)
|
||||||
@@ -344,7 +344,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def supersede_memory(self, *a, **k):
|
def supersede_memory(self, *a, **k):
|
||||||
raise KeyError("gone")
|
raise KeyError("gone")
|
||||||
h = self._h(body={})
|
h = self._h(body={})
|
||||||
with mock.patch("cloud.server.IdentityStore", _Store):
|
with mock.patch("cloud.handler_identity.IdentityStore", _Store):
|
||||||
h._identity_user_memory_supersede("u1", "m1")
|
h._identity_user_memory_supersede("u1", "m1")
|
||||||
self.assertEqual(self._last(h)[0], 404)
|
self.assertEqual(self._last(h)[0], 404)
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def delete_memory(self, mem_id, user_id):
|
def delete_memory(self, mem_id, user_id):
|
||||||
raise KeyError("gone")
|
raise KeyError("gone")
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.IdentityStore", _Store):
|
with mock.patch("cloud.handler_identity.IdentityStore", _Store):
|
||||||
h._identity_user_memory_delete("u1", "m1")
|
h._identity_user_memory_delete("u1", "m1")
|
||||||
self.assertEqual(self._last(h)[0], 404)
|
self.assertEqual(self._last(h)[0], 404)
|
||||||
|
|
||||||
@@ -405,7 +405,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def build_prompt_context(self, project_id):
|
def build_prompt_context(self, project_id):
|
||||||
return ""
|
return ""
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.MemoryStore", _Store):
|
with mock.patch("cloud.handler_identity.MemoryStore", _Store):
|
||||||
h._identity_context("u1", {"project_id": ["p1"]})
|
h._identity_context("u1", {"project_id": ["p1"]})
|
||||||
self.assertEqual(self._last(h)[0], 200)
|
self.assertEqual(self._last(h)[0], 200)
|
||||||
|
|
||||||
@@ -479,7 +479,7 @@ class MemoryIdentityTestCase(_Base):
|
|||||||
def supersede_memory(self, *a, **k):
|
def supersede_memory(self, *a, **k):
|
||||||
raise PermissionError("not yours")
|
raise PermissionError("not yours")
|
||||||
h = self._h(body={})
|
h = self._h(body={})
|
||||||
with mock.patch("cloud.server.IdentityStore", _Store):
|
with mock.patch("cloud.handler_identity.IdentityStore", _Store):
|
||||||
h._project_identity_memory_supersede("u1", "p1", "m1")
|
h._project_identity_memory_supersede("u1", "p1", "m1")
|
||||||
self.assertEqual(self._last(h)[0], 404)
|
self.assertEqual(self._last(h)[0], 404)
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class CostRelayTestCase(_Base):
|
|||||||
def search(self, project_id, q, top_k=5):
|
def search(self, project_id, q, top_k=5):
|
||||||
return []
|
return []
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.KBStore", _Store):
|
with mock.patch("cloud.handler_identity.KBStore", _Store):
|
||||||
h._kb_search("p1", {"q": ["x"]})
|
h._kb_search("p1", {"q": ["x"]})
|
||||||
self.assertEqual(self._last(h)[0], 200)
|
self.assertEqual(self._last(h)[0], 200)
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ class CostRelayTestCase(_Base):
|
|||||||
with mock.patch.dict(os.environ, {"CLOUD_GATEWAY": "sub2api"}), \
|
with mock.patch.dict(os.environ, {"CLOUD_GATEWAY": "sub2api"}), \
|
||||||
mock.patch("cloud.server._validate_sub2api_key",
|
mock.patch("cloud.server._validate_sub2api_key",
|
||||||
return_value=("ok", "key", "sub", "kid")), \
|
return_value=("ok", "key", "sub", "kid")), \
|
||||||
mock.patch("cloud.server._list_sub2api_models",
|
mock.patch("cloud.handler_identity._list_sub2api_models",
|
||||||
side_effect=RuntimeError("gw down")):
|
side_effect=RuntimeError("gw down")):
|
||||||
h._relay_models("u1")
|
h._relay_models("u1")
|
||||||
self.assertEqual(self._last(h)[0], 502)
|
self.assertEqual(self._last(h)[0], 502)
|
||||||
|
|||||||
@@ -937,7 +937,7 @@ class MetricsOauthAppTestCase(_Base):
|
|||||||
with mock.patch.dict(os.environ, {
|
with mock.patch.dict(os.environ, {
|
||||||
"CODEX_GLOBAL_ADMINS": "u1",
|
"CODEX_GLOBAL_ADMINS": "u1",
|
||||||
"GITHUB_APP_PUBLIC_BASE": "https://api.example.test"}), \
|
"GITHUB_APP_PUBLIC_BASE": "https://api.example.test"}), \
|
||||||
mock.patch("cloud.server.SetupStateStore", _Store):
|
mock.patch("cloud.handler_oauth.SetupStateStore", _Store):
|
||||||
h._github_app_setup_state()
|
h._github_app_setup_state()
|
||||||
self.assertEqual(self._last(h)[0], 200)
|
self.assertEqual(self._last(h)[0], 200)
|
||||||
|
|
||||||
@@ -981,8 +981,8 @@ class MetricsOauthAppTestCase(_Base):
|
|||||||
def consume_state(self, state, allowed_issuers=None):
|
def consume_state(self, state, allowed_issuers=None):
|
||||||
return True
|
return True
|
||||||
from cloud.github_app import AppError
|
from cloud.github_app import AppError
|
||||||
with mock.patch("cloud.server.SetupStateStore", _Store), \
|
with mock.patch("cloud.handler_oauth.SetupStateStore", _Store), \
|
||||||
mock.patch("cloud.server.exchange_manifest_code",
|
mock.patch("cloud.handler_oauth.exchange_manifest_code",
|
||||||
side_effect=AppError("bad code",
|
side_effect=AppError("bad code",
|
||||||
reason="exchange_failed")):
|
reason="exchange_failed")):
|
||||||
h._github_app_callback()
|
h._github_app_callback()
|
||||||
@@ -998,7 +998,7 @@ class MetricsOauthAppTestCase(_Base):
|
|||||||
class FullAutoKeysPushTestCase(_Base):
|
class FullAutoKeysPushTestCase(_Base):
|
||||||
def test_full_auto_config_plan_error(self):
|
def test_full_auto_config_plan_error(self):
|
||||||
h = self._h()
|
h = self._h()
|
||||||
with mock.patch("cloud.server.auto_config_plan",
|
with mock.patch("cloud.handler_fullauto.auto_config_plan",
|
||||||
side_effect=FullAutoError("boom", reason="x")):
|
side_effect=FullAutoError("boom", reason="x")):
|
||||||
h._full_auto_config_plan("u1", {"repo": ["o/r"]})
|
h._full_auto_config_plan("u1", {"repo": ["o/r"]})
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ from unittest import mock
|
|||||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||||
sys.path.insert(0, str(REPO_ROOT))
|
sys.path.insert(0, str(REPO_ROOT))
|
||||||
|
|
||||||
|
from cloud.handler_fullauto import _full_auto_installation_verified, _full_auto_parse_plan_params
|
||||||
from cloud.server import (
|
from cloud.server import (
|
||||||
CloudControlPlaneHandler,
|
CloudControlPlaneHandler,
|
||||||
RateLimiter,
|
RateLimiter,
|
||||||
@@ -31,8 +32,6 @@ from cloud.server import (
|
|||||||
_classify_goal_followup,
|
_classify_goal_followup,
|
||||||
_deployed_commit,
|
_deployed_commit,
|
||||||
_default_executor,
|
_default_executor,
|
||||||
_full_auto_installation_verified,
|
|
||||||
_full_auto_parse_plan_params,
|
|
||||||
_make_rate_limiter,
|
_make_rate_limiter,
|
||||||
_read_agent_entries,
|
_read_agent_entries,
|
||||||
_read_agent_entries_multi,
|
_read_agent_entries_multi,
|
||||||
@@ -311,23 +310,23 @@ class HelpersTestCase(_Base):
|
|||||||
|
|
||||||
def test_installation_verified_config_none(self):
|
def test_installation_verified_config_none(self):
|
||||||
c = _conn(self.db_path)
|
c = _conn(self.db_path)
|
||||||
with mock.patch("cloud.server.get_app_config",
|
with mock.patch("cloud.handler_fullauto.get_app_config",
|
||||||
return_value=None):
|
return_value=None):
|
||||||
self.assertFalse(_full_auto_installation_verified(c))
|
self.assertFalse(_full_auto_installation_verified(c))
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
def test_installation_verified_config_error(self):
|
def test_installation_verified_config_error(self):
|
||||||
c = _conn(self.db_path)
|
c = _conn(self.db_path)
|
||||||
with mock.patch("cloud.server.get_app_config",
|
with mock.patch("cloud.handler_fullauto.get_app_config",
|
||||||
side_effect=RuntimeError("config down")):
|
side_effect=RuntimeError("config down")):
|
||||||
self.assertFalse(_full_auto_installation_verified(c))
|
self.assertFalse(_full_auto_installation_verified(c))
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
def test_installation_verified_repo(self):
|
def test_installation_verified_repo(self):
|
||||||
c = _conn(self.db_path)
|
c = _conn(self.db_path)
|
||||||
with mock.patch("cloud.server.get_app_config",
|
with mock.patch("cloud.handler_fullauto.get_app_config",
|
||||||
return_value={"id": 1}), \
|
return_value={"id": 1}), \
|
||||||
mock.patch("cloud.server.find_installation_for_repo",
|
mock.patch("cloud.handler_fullauto.find_installation_for_repo",
|
||||||
return_value={"id": 9}):
|
return_value={"id": 9}):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
_full_auto_installation_verified(c, "o/r"))
|
_full_auto_installation_verified(c, "o/r"))
|
||||||
@@ -335,9 +334,9 @@ class HelpersTestCase(_Base):
|
|||||||
|
|
||||||
def test_installation_verified_any(self):
|
def test_installation_verified_any(self):
|
||||||
c = _conn(self.db_path)
|
c = _conn(self.db_path)
|
||||||
with mock.patch("cloud.server.get_app_config",
|
with mock.patch("cloud.handler_fullauto.get_app_config",
|
||||||
return_value={"id": 1}), \
|
return_value={"id": 1}), \
|
||||||
mock.patch("cloud.server.list_installations",
|
mock.patch("cloud.handler_fullauto.list_installations",
|
||||||
return_value=[{"id": 9}]):
|
return_value=[{"id": 9}]):
|
||||||
self.assertTrue(_full_auto_installation_verified(c))
|
self.assertTrue(_full_auto_installation_verified(c))
|
||||||
c.close()
|
c.close()
|
||||||
@@ -391,7 +390,7 @@ class HelpersTestCase(_Base):
|
|||||||
def __init__(self, db_path):
|
def __init__(self, db_path):
|
||||||
self.conn = mock.Mock()
|
self.conn = mock.Mock()
|
||||||
self.conn.close.side_effect = RuntimeError("down")
|
self.conn.close.side_effect = RuntimeError("down")
|
||||||
with mock.patch("cloud.server.AuthStore", _FakeStore):
|
with mock.patch("cloud.handler_support.AuthStore", _FakeStore):
|
||||||
with _auth_store_cm(self.db_path) as store:
|
with _auth_store_cm(self.db_path) as store:
|
||||||
self.assertIsNotNone(store)
|
self.assertIsNotNone(store)
|
||||||
|
|
||||||
@@ -475,7 +474,7 @@ class HandlerLeftoversTestCase(_Base):
|
|||||||
|
|
||||||
def index_file(self, project_id, path, content, kind="file"):
|
def index_file(self, project_id, path, content, kind="file"):
|
||||||
return "d1"
|
return "d1"
|
||||||
with mock.patch("cloud.server.KBStore", _Store):
|
with mock.patch("cloud.handler_identity.KBStore", _Store):
|
||||||
h._kb_index("u1", "p1")
|
h._kb_index("u1", "p1")
|
||||||
code, payload = self._last(h)
|
code, payload = self._last(h)
|
||||||
self.assertEqual(code, 201)
|
self.assertEqual(code, 201)
|
||||||
@@ -539,7 +538,7 @@ class HandlerLeftoversTestCase(_Base):
|
|||||||
self.assertTrue(h._check_coordinator_reserve("u1", 1))
|
self.assertTrue(h._check_coordinator_reserve("u1", 1))
|
||||||
|
|
||||||
def test_oauth_login_close_failure_swallowed(self):
|
def test_oauth_login_close_failure_swallowed(self):
|
||||||
from cloud.server import OAuthStateStore as _RealStore
|
from cloud.handler_oauth import OAuthStateStore as _RealStore
|
||||||
|
|
||||||
class _ClosingProxy:
|
class _ClosingProxy:
|
||||||
def __init__(self, real):
|
def __init__(self, real):
|
||||||
@@ -558,7 +557,7 @@ class HandlerLeftoversTestCase(_Base):
|
|||||||
h = self._h()
|
h = self._h()
|
||||||
h.path = ("/oauth/github/login?client_id=c"
|
h.path = ("/oauth/github/login?client_id=c"
|
||||||
"&redirect_uri=https://x.test/cb")
|
"&redirect_uri=https://x.test/cb")
|
||||||
with mock.patch("cloud.server.OAuthStateStore", _Store):
|
with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store):
|
||||||
h._oauth_login("/oauth/github/login")
|
h._oauth_login("/oauth/github/login")
|
||||||
# Either 200 (login started) or 400 (no client config): both
|
# Either 200 (login started) or 400 (no client config): both
|
||||||
# pass through the close-failure swallow in the finally.
|
# pass through the close-failure swallow in the finally.
|
||||||
|
|||||||
Reference in new issue
Block a user