|
2 | 2 |
|
3 | 3 | import psycopg |
4 | 4 | import pytest |
5 | | -from conftest import BRANCH_TIMEOUT_SEC, wait_for_status |
| 5 | +from conftest import BRANCH_TIMEOUT_SEC, wait_for_deletion, wait_for_status |
6 | 6 |
|
7 | 7 | pytestmark = pytest.mark.branch |
8 | 8 |
|
@@ -182,3 +182,32 @@ def test_branch_apikey_list(client, org, project, branch_id): |
182 | 182 | assert r.status_code == 200 |
183 | 183 | ids = [k["id"] for k in r.json()] |
184 | 184 | assert _state["api_key_id"] in ids |
| 185 | + |
| 186 | + |
| 187 | +def test_branch_delete_lifecycle(client, org, project, branch_id): |
| 188 | + base = f"organizations/{org}/projects/{project}/branches/{branch_id}" |
| 189 | + |
| 190 | + # DELETE returns 202 with a Location pointing at the task |
| 191 | + r = client.delete(f"{base}/") |
| 192 | + assert r.status_code == 202 |
| 193 | + assert "Location" in r.headers |
| 194 | + |
| 195 | + # Branch detail reflects the DELETING status immediately |
| 196 | + r = client.get(f"{base}/") |
| 197 | + if r.status_code == 200: |
| 198 | + assert r.json()["status"] == "DELETING" |
| 199 | + |
| 200 | + # Task is listed on the branch while deletion is in progress |
| 201 | + r = client.get(f"{base}/tasks/") |
| 202 | + if r.status_code == 200: |
| 203 | + assert any(t["task_type"] == "delete" for t in r.json()) |
| 204 | + |
| 205 | + # A second DELETE while delete_task_id is set must be rejected |
| 206 | + r = client.delete(f"{base}/") |
| 207 | + assert r.status_code == 400 |
| 208 | + |
| 209 | + # Wait for the background job to finish — branch must disappear |
| 210 | + wait_for_deletion(client, f"{base}/", BRANCH_TIMEOUT_SEC) |
| 211 | + |
| 212 | + r = client.get(f"{base}/") |
| 213 | + assert r.status_code == 404 |
0 commit comments