from fastapi.testclient import TestClient from poster_studio.main import app def test_token_catalog_and_project(): with TestClient(app) as client: admin = {"Authorization": "Bearer test-admin"} created = client.post( "/api/v1/admin/tokens", headers=admin, json={ "name": "hub", "app_key": "hub", "allow_tags": ["pk"], "deny_tags": ["private"], }, ) assert created.status_code == 200 token = created.json()["token"] assert ( client.post( "/api/v1/admin/catalog", headers=admin, json={ "kind": "brush", "slug": "flowers", "title": "花花笔刷", "tags": ["pk", "floral"], "definition": {"engine": "stamp"}, "status": "published", }, ).status_code == 201 ) headers = {"X-Editor-Token": token, "X-Editor-App": "hub"} catalog = client.get( "/api/v1/catalog?all_tags=pk&none_tags=private", headers=headers ) assert catalog.status_code == 200 assert catalog.json()[0]["slug"] == "flowers" document = { "schema": "entroia.poster-document", "version": 1, "id": "d", "seed": "s", "canvas": {"width": 1080, "height": 1440}, "layers": [], } project = client.post( "/api/v1/projects", headers=headers, json={"owner_id": "u", "document": document}, ) assert project.status_code == 201 assert project.json()["revision"] == 1 wrong_app = client.get( "/api/v1/catalog", headers={"X-Editor-Token": token, "X-Editor-App": "other"}, ) assert wrong_app.status_code == 403