Coverage for app/services/register.py: 78%

21 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-02 23:27 +0000

1from fastapi import HTTPException 

2from supabase import create_client 

3from dotenv import load_dotenv 

4import os 

5 

6from app.core.exceptions import DatabaseQueryError, DatabaseSaveError, UnauthorizedError 

7 

8load_dotenv() 

9 

10def register_user(email: str, password: str): 

11 if len(password) < 6: 

12 raise HTTPException(400, "Password must be at least 6 characters.") 

13 

14 SUPABASE_URL = os.getenv("SUPABASE_URL") 

15 SUPABASE_KEY = os.getenv("SUPABASE_KEY") 

16 

17 if not SUPABASE_URL or not SUPABASE_KEY: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true

18 raise DatabaseQueryError("Supabase credentials missing.") 

19 

20 try: 

21 supabase = create_client(SUPABASE_URL, SUPABASE_KEY) 

22 response = supabase.auth.sign_up({ 

23 "email": email, 

24 "password": password 

25 }) 

26 

27 if response.user is None: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true

28 raise UnauthorizedError("Invalid email or password.") 

29 

30 return response 

31 

32 except Exception as e: 

33 raise DatabaseSaveError(f"Failed to register {e}") 

34