Some checks are pending
Build and Push Docker Images / changes (push) Waiting to run
Build and Push Docker Images / build-backend (push) Blocked by required conditions
Build and Push Docker Images / build-frontend (push) Blocked by required conditions
Build and Push Docker Images / build-admin-frontend (push) Blocked by required conditions
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
"""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"]
|