Delete unused code

This commit is contained in:
bsquillari 2023-12-04 14:04:08 +00:00
parent 5e548162ee
commit 1dee061e97
2 changed files with 3 additions and 79 deletions

View File

@ -1,75 +1,11 @@
import json import json
import time import time
import pytest
TEST_USERNAME = "fede_auth" TEST_USERNAME = "fede_auth"
TEST_EMAIL = "fede_auth@gmail.com" TEST_EMAIL = "fede_auth@gmail.com"
TEST_PASSWD = "password1234" TEST_PASSWD = "password1234"
def test_user_registration(test_app, test_database):
client = test_app.test_client()
resp = client.post(
"/auth/register",
data=json.dumps(
{
"username": TEST_USERNAME,
"email": TEST_EMAIL,
"password": TEST_PASSWD,
}
),
content_type="application/json",
)
data = json.loads(resp.data.decode())
assert resp.status_code == 201
assert resp.content_type == "application/json"
assert TEST_USERNAME in data["username"]
assert TEST_EMAIL in data["email"]
assert "password" not in data
def test_user_registration_duplicate_email(test_app, test_database, add_user):
add_user(TEST_USERNAME, TEST_EMAIL, TEST_PASSWD)
client = test_app.test_client()
resp = client.post(
"/auth/register",
data=json.dumps(
{"username": "martin", "email": TEST_EMAIL, "password": "test"}
),
content_type="application/json",
)
data = json.loads(resp.data.decode())
assert resp.status_code == 400
assert resp.content_type == "application/json"
assert "Sorry. That email already exists." == data["message"]
@pytest.mark.parametrize(
"payload",
[
{},
{"email": TEST_EMAIL, "password": TEST_PASSWD},
{"username": TEST_USERNAME, "password": TEST_PASSWD},
{"email": TEST_EMAIL, "username": TEST_USERNAME},
{"mail": TEST_EMAIL, "username": TEST_USERNAME, "password": TEST_PASSWD},
{"email": TEST_EMAIL, "user": TEST_USERNAME, "password": TEST_PASSWD},
{"email": TEST_EMAIL, "username": TEST_USERNAME, "passwd": TEST_PASSWD},
],
)
def test_user_registration_invalid_json(test_app, test_database, payload):
client = test_app.test_client()
resp = client.post(
"/auth/register",
data=json.dumps(payload),
content_type="application/json",
)
data = json.loads(resp.data.decode())
assert resp.status_code == 400
assert resp.content_type == "application/json"
assert "Input payload validation failed" in data["message"]
def test_registered_user_login(test_app, test_database, add_user): def test_registered_user_login(test_app, test_database, add_user):
add_user(TEST_USERNAME, TEST_EMAIL, TEST_PASSWD) add_user(TEST_USERNAME, TEST_EMAIL, TEST_PASSWD)
client = test_app.test_client() client = test_app.test_client()
@ -174,7 +110,7 @@ def test_user_status(test_app, test_database, add_user):
data = json.loads(resp.data.decode()) data = json.loads(resp.data.decode())
assert resp.status_code == 200 assert resp.status_code == 200
assert resp.content_type == "application/json" assert resp.content_type == "application/json"
assert not data["airline"] assert data["role"] == 0
assert "password" not in data assert "password" not in data

View File

@ -5,23 +5,11 @@ from fastapi import APIRouter, Header, HTTPException, Request
from src.api.config import API_AUTH from src.api.config import API_AUTH
from src.api.schemas.auth import RefreshToken, Token from src.api.schemas.auth import RefreshToken, Token
from src.api.schemas.user import UserLogin, UserMin, UserRegister, UserStatus from src.api.schemas.user import UserLogin, UserStatus
router = APIRouter() router = APIRouter()
@router.post("/register", response_model=UserMin)
async def register(user: UserRegister, req: Request):
request_id = req.state.request_id
header = {"x-api-request-id": request_id}
(response, status, _) = await request(
f"{API_AUTH}/register", "POST", json=user.model_dump(), headers=header
)
if status < 200 or status > 204:
raise HTTPException(status_code=status, detail=response)
return response
@router.post("/login", response_model=Token) @router.post("/login", response_model=Token)
async def login(user: UserLogin, req: Request): async def login(user: UserLogin, req: Request):
request_id = req.state.request_id request_id = req.state.request_id
@ -67,7 +55,7 @@ async def checkAuth(
): ):
response = await status(req, authorization) response = await status(req, authorization)
if isAirline: if isAirline:
if response["airline"]: if response["role"] == 1:
return response["id"] return response["id"]
else: else:
raise HTTPException( raise HTTPException(