41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
def test_login_success(client, regular_user):
|
|
response = client.post('/api/v1/auth/login', json={
|
|
'email': 'user@test.com',
|
|
'password': 'UserPass123!'
|
|
})
|
|
assert response.status_code == 200
|
|
data = response.get_json()
|
|
assert 'access_token' in data
|
|
assert data['user']['email'] == 'user@test.com'
|
|
assert data['user']['role'] == 'user'
|
|
|
|
def test_login_invalid_password(client, regular_user):
|
|
response = client.post('/api/v1/auth/login', json={
|
|
'email': 'user@test.com',
|
|
'password': 'WrongPassword'
|
|
})
|
|
assert response.status_code == 401
|
|
data = response.get_json()
|
|
assert 'error' in data
|
|
|
|
def test_get_me_profile(client, user_headers):
|
|
response = client.get('/api/v1/auth/me', headers=user_headers)
|
|
assert response.status_code == 200
|
|
data = response.get_json()
|
|
assert data['email'] == 'user@test.com'
|
|
|
|
def test_change_password_success(client, user_headers):
|
|
response = client.post('/api/v1/auth/change-password', headers=user_headers, json={
|
|
'old_password': 'UserPass123!',
|
|
'new_password': 'NewSuperPass123!'
|
|
})
|
|
assert response.status_code == 200
|
|
assert 'message' in response.get_json()
|
|
|
|
# Tentar login com a nova senha
|
|
login_res = client.post('/api/v1/auth/login', json={
|
|
'email': 'user@test.com',
|
|
'password': 'NewSuperPass123!'
|
|
})
|
|
assert login_res.status_code == 200
|