#!/usr/bin/env python3
"""E2E: 项目 CRUD"""
from helper import *

header("Projects")

# ── Create ──
project_name = unique_name("E2E-项目测试")
pid = create_project(project_name)
ok("create project")

# List 包含新建项目
projects = assert_ok(get("/api/v1/projects"))
assert any(p["name"] == project_name for p in projects)
ok("list projects includes new")

# Get
p = assert_ok(get(f"/api/v1/projects/{pid}"))
assert p["name"] == project_name
ok("get project")

# Create with empty name → 400
assert_err(post("/api/v1/projects", {"name": ""}), 400)
ok("reject empty name")

# Get nonexistent
assert_err(get(f"/api/v1/projects/00000000-0000-0000-0000-000000000000"), 404)
ok("404 on nonexistent project")

# Delete
assert_ok(delete(f"/api/v1/projects/{pid}"))
ok("delete project")

# Delete again → 404
assert_err(delete(f"/api/v1/projects/{pid}"), 404)
ok("404 on already deleted project")

summary()
