ba8b493a31
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
"""SLICE-3 storefront creation — service + endpoint scenario tests (SD-0001 §6.5 PUC-4/7)."""
|
|
import re
|
|
|
|
import psycopg
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import create_app
|
|
from app.domains import storefronts
|
|
from app.platform import db
|
|
|
|
|
|
@pytest.fixture()
|
|
def migrated_conn(fresh_db_url):
|
|
with psycopg.connect(fresh_db_url) as conn:
|
|
db.migrate(conn)
|
|
yield conn
|
|
|
|
|
|
def _account_id(conn, email="merchant@example.com"):
|
|
return conn.execute(
|
|
"INSERT INTO account (email) VALUES (%s) RETURNING id", (email,)
|
|
).fetchone()[0]
|
|
|
|
|
|
def test_create_storefront_with_name(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
sf = storefronts.create_storefront(migrated_conn, acct, "merchant@example.com", "Ben's Bets")
|
|
assert sf.name == "Ben's Bets"
|
|
assert storefronts.storefront_for(migrated_conn, acct) == sf
|
|
|
|
|
|
def test_14_01_0026_blank_name_gets_generated_default(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
sf = storefronts.create_storefront(migrated_conn, acct, "merchant@example.com", None)
|
|
assert sf.name == "merchant's storefront"
|
|
|
|
|
|
def test_whitespace_name_treated_as_blank(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
sf = storefronts.create_storefront(migrated_conn, acct, "ben@bensbets.com", " ")
|
|
assert sf.name == "ben's storefront"
|
|
|
|
|
|
def test_second_create_refused_inv_4(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
storefronts.create_storefront(migrated_conn, acct, "merchant@example.com", "First")
|
|
with pytest.raises(storefronts.AlreadyOwnsStorefront):
|
|
storefronts.create_storefront(migrated_conn, acct, "merchant@example.com", "Second")
|
|
|
|
|
|
def test_membership_row_is_owner(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
sf = storefronts.create_storefront(migrated_conn, acct, "merchant@example.com", None)
|
|
role = migrated_conn.execute(
|
|
"SELECT role FROM storefront_membership WHERE account_id = %s AND storefront_id = %s",
|
|
(acct, sf.id),
|
|
).fetchone()[0]
|
|
assert role == "owner"
|
|
|
|
|
|
def test_storefront_for_none_when_absent(migrated_conn):
|
|
acct = _account_id(migrated_conn)
|
|
assert storefronts.storefront_for(migrated_conn, acct) is None
|