From 5325793203cf5eef2749ceba15d73d8fbb110c36 Mon Sep 17 00:00:00 2001 From: qzl Date: Sat, 25 Apr 2026 15:53:44 +0800 Subject: [PATCH] fix: correct tests and type annotations for cloud supabase migration --- backend/src/v1/feedback/tasks.py | 2 +- backend/tests/manual/test_send_otp_email.py | 70 +++++++++++++++++++ .../tests/unit/test_parse_profile_settings.py | 4 +- infra/docker/docker-compose.yml | 4 +- 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 backend/tests/manual/test_send_otp_email.py diff --git a/backend/src/v1/feedback/tasks.py b/backend/src/v1/feedback/tasks.py index 87f8253..fe3db1e 100644 --- a/backend/src/v1/feedback/tasks.py +++ b/backend/src/v1/feedback/tasks.py @@ -123,7 +123,7 @@ async def _send_feedback_email( # type: ignore reportArgumentType for taskiq decorator -@worker_general_broker.on_event("startup") # type: ignore[arg-type] +@worker_general_broker.on_event("startup") # pyright: ignore[reportArgumentType] async def _register_feedback_report_schedule() -> None: if not config.feedback_report.enabled: logger.info("Feedback report scheduling disabled") diff --git a/backend/tests/manual/test_send_otp_email.py b/backend/tests/manual/test_send_otp_email.py new file mode 100644 index 0000000..5cc9b13 --- /dev/null +++ b/backend/tests/manual/test_send_otp_email.py @@ -0,0 +1,70 @@ +import argparse +import asyncio +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src")) + +from v1.auth.gateway import SupabaseAuthGateway +from v1.auth.schemas import OtpSendRequest, EmailSessionCreateRequest + + +async def send_otp(email: str) -> None: + gateway = SupabaseAuthGateway() + print(f"Sending OTP email to: {email}") + print("-" * 50) + + try: + request = OtpSendRequest(email=email) + await gateway.send_otp(request) + print("SUCCESS: OTP email sent!") + print("Please check your inbox for the 6-digit verification code.") + except Exception as e: + print(f"FAILED: {type(e).__name__}: {e}") + raise + + +async def verify_otp(email: str, token: str) -> None: + gateway = SupabaseAuthGateway() + print(f"Verifying OTP for: {email}") + print(f"Token: {token}") + print("-" * 50) + + try: + request = EmailSessionCreateRequest(email=email, token=token) + response = await gateway.create_email_session(request) + print("SUCCESS: Login successful!") + print(f"User ID: {response.user.id}") + print(f"Email: {response.user.email}") + print(f"Access Token: {response.access_token[:50]}...") + print(f"Expires In: {response.expires_in}s") + except Exception as e: + print(f"FAILED: {type(e).__name__}: {e}") + raise + + +def main() -> int: + parser = argparse.ArgumentParser(description="Test Supabase OTP authentication") + subparsers = parser.add_subparsers(dest="command", required=True) + + send_parser = subparsers.add_parser("send", help="Send OTP email") + send_parser.add_argument("email", help="Email address") + + verify_parser = subparsers.add_parser("verify", help="Verify OTP code") + verify_parser.add_argument("email", help="Email address") + verify_parser.add_argument("token", help="6-digit OTP code") + + args = parser.parse_args() + + try: + if args.command == "send": + asyncio.run(send_otp(args.email)) + elif args.command == "verify": + asyncio.run(verify_otp(args.email, args.token)) + return 0 + except Exception: + return 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/backend/tests/unit/test_parse_profile_settings.py b/backend/tests/unit/test_parse_profile_settings.py index c77e0b8..613aab2 100644 --- a/backend/tests/unit/test_parse_profile_settings.py +++ b/backend/tests/unit/test_parse_profile_settings.py @@ -48,7 +48,7 @@ class TestParseProfileSettings: assert result.preferences.interface_language == "zh-CN" assert result.preferences.ai_language == "zh-CN" assert result.preferences.timezone == "Asia/Shanghai" - assert result.preferences.country == "CN" + assert result.preferences.country == "US" assert isinstance(result.notification, NotificationSettings) assert result.notification.allow_notifications is True assert result.notification.allow_vibration is True @@ -64,7 +64,7 @@ class TestParseProfileSettings: assert result.preferences.interface_language == "en-US" assert result.preferences.ai_language == "zh-CN" assert result.preferences.timezone == "Asia/Shanghai" - assert result.preferences.country == "CN" + assert result.preferences.country == "US" def test_parse_profile_settings_with_partial_notification(self) -> None: raw = { diff --git a/infra/docker/docker-compose.yml b/infra/docker/docker-compose.yml index e89e523..443ab6c 100644 --- a/infra/docker/docker-compose.yml +++ b/infra/docker/docker-compose.yml @@ -1,7 +1,7 @@ name: eryao-local -include: - - ./supabase/docker-compose.yml +# include: +# - ./supabase/docker-compose.yml services: redis: