Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
/ "migrations"
/ "0102_project_bound_summary_event.sql"
)
_TENANT_SETTINGS_MIGRATION = (
Path(__file__).resolve().parents[2] / "migrations" / "0103_tenant_settings.sql"
)
_CHANNEL_WEIGHT_MIGRATION = (
Path(__file__).resolve().parents[2]
/ "migrations"
Expand Down Expand Up @@ -242,6 +245,7 @@ def seeded_db(demo_analyst_token):
cur.execute(_MAJOR_EVENT_ACTION_MIGRATION.read_text())
cur.execute(_PROJECT_BOUND_ACTION_MIGRATION.read_text())
cur.execute(_PROJECT_BOUND_EVENT_MIGRATION.read_text())
cur.execute(_TENANT_SETTINGS_MIGRATION.read_text())
cur.execute(_CHANNEL_WEIGHT_MIGRATION.read_text())
cur.execute(_LEFTOVER_OBSERVED_EXPECTED_MIGRATION.read_text())
cur.execute(_LEFTOVER_MAP_RANK_MIGRATION.read_text())
Expand Down Expand Up @@ -2091,6 +2095,51 @@ def test_nonexistent_post_is_not_found(client, demo_analyst_token) -> None:
assert response.status_code == 404


def test_settings_get_returns_the_seeded_brand_name(
client, demo_analyst_token, seeded_db
) -> None:
"""An authenticated reader receives the persisted synthetic brand."""

response = client.get(
"/api/settings",
headers={"Authorization": f"Bearer {demo_analyst_token}"},
)
assert response.status_code == 200
assert response.json() == {"brandName": "LineageWeave"}


def test_update_settings_requires_post_admin(client, demo_analyst_token, seeded_db) -> None:
"""A non-admin reader cannot mutate tenant presentation settings."""

response = client.patch(
"/api/settings",
json={"brandName": "Someone Else's Brand"},
headers={"Authorization": f"Bearer {demo_analyst_token}"},
)
assert response.status_code == 403


def test_update_settings_as_admin_changes_the_brand_name(
client, demo_analyst_token, seeded_db
) -> None:
"""A post admin can persist and subsequently read a synthetic brand."""

_grant_post_admin(seeded_db["dsn"])
patch_response = client.patch(
"/api/settings",
json={"brandName": "Renamed Corp"},
headers={"Authorization": f"Bearer {demo_analyst_token}"},
)
assert patch_response.status_code == 200
assert patch_response.json() == {"brandName": "Renamed Corp"}

get_response = client.get(
"/api/settings",
headers={"Authorization": f"Bearer {demo_analyst_token}"},
)
assert get_response.json() == {"brandName": "Renamed Corp"}


def test_missing_token_is_unauthorized(client) -> None:
response = client.get("/api/posts")
assert response.status_code in (401, 403)
Expand Down