File size: 1,075 Bytes
d29b763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi.testclient import TestClient
from inference.app_production import app


def run():
    client = TestClient(app)

    # Ensure a clean test user
    email = 'test.user@example.com'
    password = 'TestPass123!'

    # Signup
    resp = client.post('/auth/signup', json={'email': email, 'password': password, 'name': 'Test User'})
    if resp.status_code not in (200, 409):
        raise SystemExit(f'Signup failed: {resp.status_code} {resp.text}')

    # Login
    resp = client.post('/auth/login', json={'email': email, 'password': password})
    if resp.status_code != 200:
        raise SystemExit(f'Login failed: {resp.status_code} {resp.text}')

    data = resp.json()
    token = data.get('token')
    if not token:
        raise SystemExit('No token returned on login')

    # Call /auth/me
    resp = client.get('/auth/me', headers={'Authorization': f'Bearer {token}'})
    if resp.status_code != 200:
        raise SystemExit(f'/auth/me failed: {resp.status_code} {resp.text}')

    print('Auth smoke test passed')


if __name__ == '__main__':
    run()