fix: tests — add setup_db fixture for init_db in test env
This commit is contained in:
1
.venv/bin/python
Symbolic link
1
.venv/bin/python
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
1
.venv/bin/python3
Symbolic link
1
.venv/bin/python3
Symbolic link
@@ -0,0 +1 @@
|
||||
/usr/bin/python3
|
||||
1
.venv/bin/python3.10
Symbolic link
1
.venv/bin/python3.10
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
1
.venv/lib64
Symbolic link
1
.venv/lib64
Symbolic link
@@ -0,0 +1 @@
|
||||
lib
|
||||
3
.venv/pyvenv.cfg
Normal file
3
.venv/pyvenv.cfg
Normal file
@@ -0,0 +1,3 @@
|
||||
home = /usr/bin
|
||||
include-system-site-packages = false
|
||||
version = 3.10.12
|
||||
BIN
data/orchestrator.db
Normal file
BIN
data/orchestrator.db
Normal file
Binary file not shown.
BIN
src/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
src/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/config.cpython-312.pyc
Normal file
BIN
src/__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/db.cpython-312.pyc
Normal file
BIN
src/__pycache__/db.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/main.cpython-312.pyc
Normal file
BIN
src/__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/webhooks/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
src/webhooks/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/webhooks/__pycache__/gitea.cpython-312.pyc
Normal file
BIN
src/webhooks/__pycache__/gitea.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/webhooks/__pycache__/plane.cpython-312.pyc
Normal file
BIN
src/webhooks/__pycache__/plane.cpython-312.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
tests/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_webhooks.cpython-312-pytest-9.0.3.pyc
Normal file
BIN
tests/__pycache__/test_webhooks.cpython-312-pytest-9.0.3.pyc
Normal file
Binary file not shown.
@@ -1,12 +1,27 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# Override DB path before importing app
|
||||
os.environ["ORCH_DB_PATH"] = os.path.join(tempfile.gettempdir(), "test_orchestrator.db")
|
||||
_test_db = os.path.join(tempfile.gettempdir(), "test_orchestrator.db")
|
||||
os.environ["ORCH_DB_PATH"] = _test_db
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from src.main import app
|
||||
from src.db import init_db
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_db():
|
||||
"""Ensure DB tables exist before each test."""
|
||||
# Remove old test db if exists
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
init_db()
|
||||
yield
|
||||
if os.path.exists(_test_db):
|
||||
os.unlink(_test_db)
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
@@ -63,3 +78,14 @@ def test_status_endpoint():
|
||||
resp = client.get("/status")
|
||||
assert resp.status_code == 200
|
||||
assert "active_tasks" in resp.json()
|
||||
|
||||
|
||||
def test_plane_webhook_creates_task():
|
||||
"""Verify that work_item.created actually inserts a task."""
|
||||
client.post("/webhook/plane", json={
|
||||
"event": "work_item.created",
|
||||
"data": {"id": "task-456", "name": "New feature", "project": "proj-2"}
|
||||
})
|
||||
resp = client.get("/status")
|
||||
tasks = resp.json()["active_tasks"]
|
||||
assert any(t["plane_id"] == "task-456" for t in tasks)
|
||||
|
||||
Reference in New Issue
Block a user