Spaces:
Running

File size: 2,664 Bytes
dd35b54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

import asyncio
import httpx
import random
import string
from urllib.parse import urlparse

BASE_URL = "http://localhost:8000/api/v1"

def generate_random_email():
    return f"test_{''.join(random.choices(string.ascii_lowercase, k=8))}@example.com"

async def test_auth_flow():
    email = generate_random_email()
    password = "Start@123_Secure"
    company_name = "Test Company"
    
    print(f"📧 Testing with email: {email}")
    
    async with httpx.AsyncClient(timeout=30.0) as client:
        # 1. Register
        print("\n1️⃣  Testing Registration...")
        response = await client.post(f"{BASE_URL}/auth/register", json={
            "email": email,
            "password": password,
            "company_name": company_name
        })
        
        if response.status_code != 200:
            print(f"❌ Registration failed: {response.text}")
            return
            
        data = response.json()
        if data.get("access_token") == "verification_pending":
            print("✅ Registration successful (Verification Pending)")
        else:
            print(f"⚠️  Unexpected response: {data}")
            
        # At this point, we need the verification code.
        # Since we can't easily read the email in this test script without mocking,
        # we might need to peek into the DB or just rely on the user to check email.
        # But for automated testing, we could query the DB if we had direct access.
        
        # For now, I will verify that the login fails without verification
        print("\n2️⃣  Testing Login (Unverified)...")
        response = await client.post(f"{BASE_URL}/auth/login", json={
            "email": email,
            "password": password
        })
        
        if response.status_code == 403 and "verified" in response.text.lower():
            print("✅ Login failed as expected (Unverified)")
        else:
            print(f"❌ Login verification check failed: {response.status_code} {response.text}")

        # Test Forgot Password Request
        print("\n3️⃣  Testing Forgot Password Request...")
        response = await client.post(f"{BASE_URL}/auth/forgot-password", json={
            "email": email
        })
        if response.status_code == 200:
             print("✅ Forgot Password request successful")
        else:
             print(f"❌ Forgot Password request failed: {response.text}")

        print("\n⚠️  Manual verification required for obtaining the OTP and completing the flow.")
        print("Please check the backend logs or email inbox for the code.")

if __name__ == "__main__":
    asyncio.run(test_auth_flow())