import pytest from rest_framework.test import APIClient @pytest.fixture def api(): return APIClient() @pytest.fixture def user(db): from apps.accounts.models import User return User.objects.create_user( username="u@x.com", email="u@x.com", password="pw1234", user_name="유저" ) @pytest.fixture def auth_api(api, user): """로그인된 클라이언트 + 토큰 응답.""" res = api.post("/api/v1/auth/login", {"email": "u@x.com", "password": "pw1234"}, format="json") tokens = res.json()["data"] api.credentials(HTTP_AUTHORIZATION=f"Bearer {tokens['token']}") api.tokens = tokens return api