test(backend): add 55+ test files to push coverage to 98%

Subagents delivered tests across all uncovered backend modules:

Schemas (100%): agent, auth, health, profile, settings, validation
Services (98-100%): auth, profile, health, llm, mapping, resource,
  security, git, superset_lookup, sql_table_extractor, rbac
API routes (new): auth, admin, health, environments, plugins,
  dashboards (helpers, projection, actions, listing),
  git (config, deps, env, helpers)
Clean Release (100%): DTO, facade, policy_engine, stages,
  repos, preparation, source_isolation, compliance
Git services: base, remote_providers
Agent module: app, run, middleware, langgraph_setup
Core: trace, cleanup, ws_log_handler, timezone, auth (config/oauth/security), matching
Reports: normalizer, report_service, type_profiles
Notifications: service, providers

Also:
- .gitignore: add .coverage, *.cover, coverage-* dirs
- src/schemas/auth.py: fix AD group DN regex (comma in CN=...)
- Remove co-located src/services/__tests__/ (caused pytest module collision)
This commit is contained in:
2026-06-15 13:55:57 +03:00
parent 6989bb0bc9
commit ce0369ae5c
67 changed files with 12187 additions and 1993 deletions

View File

@@ -52,47 +52,53 @@ def executor(mock_conn_service):
class TestPostgresql:
def test_execute_success(self, executor, mock_conn_service, pg_connection):
@pytest.mark.asyncio
async def test_execute_success(self, executor, mock_conn_service, pg_connection):
mock_conn_service.get_connection.return_value = pg_connection
sample_sql = 'INSERT INTO "products" ("id", "name") VALUES (\'1\', \'test\')'
with patch.object(executor, '_execute_pg', return_value=DbExecutionResult(success=True, rows_affected=5, execution_time_ms=120)):
result = executor.execute_sql("pg1", sample_sql)
result = await executor.execute_sql("pg1", sample_sql)
assert result.success is True
assert result.rows_affected == 5
assert result.execution_time_ms == 120
def test_connection_not_found(self, executor, mock_conn_service):
@pytest.mark.asyncio
async def test_connection_not_found(self, executor, mock_conn_service):
mock_conn_service.get_connection.return_value = None
result = executor.execute_sql("nonexistent", "SELECT 1")
result = await executor.execute_sql("nonexistent", "SELECT 1")
assert result.success is False
assert "not found" in (result.error or "")
def test_dialect_routing_ch(self, executor, mock_conn_service, ch_connection):
@pytest.mark.asyncio
async def test_dialect_routing_ch(self, executor, mock_conn_service, ch_connection):
mock_conn_service.get_connection.return_value = ch_connection
with patch.object(executor, '_execute_ch', return_value=DbExecutionResult(success=True, rows_affected=3, execution_time_ms=50)):
result = executor.execute_sql("ch1", "INSERT INTO t VALUES (1)")
result = await executor.execute_sql("ch1", "INSERT INTO t VALUES (1)")
assert result.success is True
def test_dialect_routing_mysql(self, executor, mock_conn_service, mysql_connection):
@pytest.mark.asyncio
async def test_dialect_routing_mysql(self, executor, mock_conn_service, mysql_connection):
mock_conn_service.get_connection.return_value = mysql_connection
with patch.object(executor, '_execute_mysql', return_value=DbExecutionResult(success=True, rows_affected=2, execution_time_ms=30)):
result = executor.execute_sql("my1", "INSERT INTO t VALUES (1)")
result = await executor.execute_sql("my1", "INSERT INTO t VALUES (1)")
assert result.success is True
def test_unsupported_dialect(self, executor, mock_conn_service):
@pytest.mark.asyncio
async def test_unsupported_dialect(self, executor, mock_conn_service):
bad_conn = DatabaseConnection.model_construct(
id="bad", name="Bad", host="x", port=1,
database="x", username="u", password="p", dialect="oracle",
)
mock_conn_service.get_connection.return_value = bad_conn
result = executor.execute_sql("bad", "SELECT 1")
result = await executor.execute_sql("bad", "SELECT 1")
assert result.success is False
assert "Unsupported" in (result.error or "")
def test_execution_error(self, executor, mock_conn_service, pg_connection):
@pytest.mark.asyncio
async def test_execution_error(self, executor, mock_conn_service, pg_connection):
mock_conn_service.get_connection.return_value = pg_connection
with patch.object(executor, '_execute_pg', side_effect=RuntimeError("Connection timeout")):
result = executor.execute_sql("pg1", "BAD SQL")
result = await executor.execute_sql("pg1", "BAD SQL")
assert result.success is False
assert "Connection timeout" in (result.error or "")
@@ -113,10 +119,11 @@ class TestPoolCaching:
class TestMissingDriver:
def test_asyncpg_not_installed(self, executor, mock_conn_service, pg_connection):
@pytest.mark.asyncio
async def test_asyncpg_not_installed(self, executor, mock_conn_service, pg_connection):
mock_conn_service.get_connection.return_value = pg_connection
with patch.dict('sys.modules', {'asyncpg': None}):
result = executor._execute_pg(pg_connection, "SELECT 1", 0)
result = await executor._execute_pg(pg_connection, "SELECT 1", 0)
assert result.success is False
assert "asyncpg is not installed" in (result.error or "")