o2o-negosium-original/negodata/backend/tests/test_auth.py
Mina Choi 82076e138e [test] negodata: 백엔드 테스트 스위트 구축 + 공통 픽스처(conftest) 정비
- test DB 세션마다 자동 create/drop (팀원은 Postgres만 있으면 pytest 한 방)
- auth_headers 시드 픽스처(무인증 /auth/create 제거 대응) + other_company_id
- 커버: 회사 스코프(견적·상품·협력사·대시보드·세팅), 견적 마감 재견적 O/X + 알림,
  견적 생성·목표가, 알림함 읽기, 회사유저 OWNER 게이팅, 기존 파일 검증/기대결과 주석 정비

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 15:06:55 +09:00

44 lines
1.9 KiB
Python

"""auth 도메인 e2e — 로그인 / 내정보 / 인증거부 흐름.
계정 생성·중복·최고관리자 스코프는 test_company_user.py. 유저 시드/로그인은 auth_headers 픽스처.
"""
async def test_login_and_me_flow(auth_headers, client, company_id):
"""검증: 시드된 유저가 로그인해 받은 토큰으로 /me 호출.
기대결과: 200, 본인 id·name·소속사(company_id)가 그대로 반환."""
h = await auth_headers("user1", name="홍길동")
r = await client.get("/v1/auth/me", headers=h)
assert r.status_code == 200
me = r.json()
assert me["id"] == "user1"
assert me["name"] == "홍길동"
assert me["company"]["company_id"] == company_id
async def test_login_with_wrong_password(auth_headers, client):
"""검증: 존재하는 계정에 '틀린 비밀번호'로 로그인.
기대결과: 로그인 실패 — success=False, code=1200(ACCOUNT_INVALID_INFO), 토큰 빈 문자열."""
await auth_headers("user2") # pw1234 로 시드
r = await client.post("/v1/auth/login", json={"id": "user2", "password": "wrong"})
body = r.json()
assert body["result"]["success"] is False
assert body["result"]["code"] == 1200
assert body.get("access_token", "") == ""
async def test_login_nonexistent_account(client):
"""검증: 존재하지 않는 계정으로 로그인.
기대결과: 실패 — success=False (계정 유무를 '틀린 비번'과 구분해 흘리지 않음)."""
r = await client.post("/v1/auth/login", json={"id": "ghost", "password": "whatever"})
assert r.json()["result"]["success"] is False
async def test_me_without_token_is_rejected(client):
"""검증: 토큰 없이 보호 엔드포인트 /me 호출.
기대결과: 인증 단계에서 거부 — HTTP 401 또는 403."""
r = await client.get("/v1/auth/me")
assert r.status_code in (401, 403)