"""Story universe API tests.""" def _create_profile(auth_client): response = auth_client.post( "/api/profiles", json={ "name": "小明", "gender": "male", "interests": ["太空"], "growth_themes": ["勇气"], }, ) assert response.status_code == 201 return response.json()["id"] def test_create_list_update_universe(auth_client): profile_id = _create_profile(auth_client) payload = { "name": "星际冒险", "protagonist": {"name": "小明", "role": "船长"}, "recurring_characters": [{"name": "小七", "role": "机器人"}], "world_settings": {"world_name": "星际学院"}, } response = auth_client.post(f"/api/profiles/{profile_id}/universes", json=payload) assert response.status_code == 201 data = response.json() assert data["name"] == payload["name"] universe_id = data["id"] response = auth_client.get(f"/api/profiles/{profile_id}/universes") assert response.status_code == 200 list_data = response.json() assert list_data["total"] == 1 response = auth_client.put( f"/api/universes/{universe_id}", json={"name": "星际冒险·第二季"}, ) assert response.status_code == 200 data = response.json() assert data["name"] == "星际冒险·第二季" def test_add_achievement(auth_client): profile_id = _create_profile(auth_client) response = auth_client.post( f"/api/profiles/{profile_id}/universes", json={ "name": "梦幻森林", "protagonist": {"name": "小红"}, }, ) assert response.status_code == 201 universe_id = response.json()["id"] response = auth_client.post( f"/api/universes/{universe_id}/achievements", json={"type": "勇气", "description": "克服黑暗"}, ) assert response.status_code == 200 data = response.json() assert {"type": "勇气", "description": "克服黑暗"} in data["achievements"]