Fix signup bug
This commit is contained in:
parent
7fa4f08c00
commit
fd8ac67cf1
|
@ -43,8 +43,12 @@ class UsersList(Resource):
|
|||
|
||||
user = add_user(username, email, password)
|
||||
|
||||
response_object["message"] = f"{email} was added!"
|
||||
response_object["id"] = user.id
|
||||
response_object = {
|
||||
"message": f"{user.email} was added!",
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
"email": user.email,
|
||||
}
|
||||
return response_object, 201
|
||||
|
||||
|
||||
|
@ -78,8 +82,14 @@ class Users(Resource):
|
|||
|
||||
user = update_user(user, username, email) # new
|
||||
|
||||
response_object["message"] = f"{user.id} was updated!"
|
||||
response_object["id"] = user.id
|
||||
response_object = {
|
||||
"message": f"{user.id} was updated!",
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
"email": user.email,
|
||||
"created_date": user.created_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"airline": user.airline,
|
||||
}
|
||||
return response_object, 200
|
||||
|
||||
@users_namespace.response(200, "<user_id> was removed!")
|
||||
|
|
|
@ -21,9 +21,9 @@ def test_add_user(test_app, monkeypatch):
|
|||
d.update(
|
||||
{
|
||||
"id": 10,
|
||||
"username": "me",
|
||||
"email": "me@itba.edu",
|
||||
"password": "123456789",
|
||||
"username": username,
|
||||
"email": email,
|
||||
"password": passwd,
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
@ -144,7 +144,11 @@ def test_remove_user(test_app, monkeypatch):
|
|||
def mock_get_user_by_id(user_id):
|
||||
d = AttrDict()
|
||||
d.update(
|
||||
{"id": 1, "username": "user-to-be-removed", "email": "remove-me@itba.edu"}
|
||||
{
|
||||
"id": user_id,
|
||||
"username": "user-to-be-removed",
|
||||
"email": "remove-me@itba.edu",
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
||||
|
@ -175,12 +179,20 @@ def test_remove_user_incorrect_id(test_app, monkeypatch):
|
|||
def test_update_user(test_app, monkeypatch):
|
||||
def mock_get_user_by_id(user_id):
|
||||
d = AttrDict()
|
||||
d.update({"id": 1, "username": "me", "email": "me@itba.edu"})
|
||||
d.update({"id": user_id, "username": "-", "email": "-"})
|
||||
return d
|
||||
|
||||
def mock_update_user(user, username, email):
|
||||
d = AttrDict()
|
||||
d.update({"id": 1, "username": "me", "email": "me@itba.edu"})
|
||||
d.update(
|
||||
{
|
||||
"id": 1,
|
||||
"username": username,
|
||||
"email": email,
|
||||
"created_date": datetime.now(),
|
||||
"airline": False,
|
||||
}
|
||||
)
|
||||
return d
|
||||
|
||||
def mock_get_user_by_email(email):
|
||||
|
@ -191,17 +203,14 @@ def test_update_user(test_app, monkeypatch):
|
|||
monkeypatch.setattr(src.api.users, "update_user", mock_update_user)
|
||||
|
||||
client = test_app.test_client()
|
||||
resp_one = client.put(
|
||||
resp = client.put(
|
||||
"/users/1",
|
||||
data=json.dumps({"username": "me", "email": "me@itba.edu"}),
|
||||
content_type="application/json",
|
||||
)
|
||||
data = json.loads(resp_one.data.decode())
|
||||
assert resp_one.status_code == 200
|
||||
data = json.loads(resp.data.decode())
|
||||
assert resp.status_code == 200
|
||||
assert "1 was updated!" in data["message"]
|
||||
resp_two = client.get("/users/1")
|
||||
data = json.loads(resp_two.data.decode())
|
||||
assert resp_two.status_code == 200
|
||||
assert "me" in data["username"]
|
||||
assert "me@itba.edu" in data["email"]
|
||||
|
||||
|
@ -246,7 +255,7 @@ def test_update_user_duplicate_email(test_app, monkeypatch):
|
|||
|
||||
def mock_get_user_by_id(user_id):
|
||||
d = AttrDict()
|
||||
d.update({"id": 1, "username": "me", "email": "me@itba.edu"})
|
||||
d.update({"id": user_id, "username": "me", "email": "me@itba.edu"})
|
||||
return d
|
||||
|
||||
def mock_update_user(user, username, email):
|
||||
|
|
|
@ -5,12 +5,12 @@ from fastapi import APIRouter, Header, HTTPException, Request
|
|||
|
||||
from src.api.config import API_USERS
|
||||
from src.api.routes.auth import checkAuth
|
||||
from src.api.schemas.user import User, UserRegister
|
||||
from src.api.schemas.user import User, UserMin, UserRegister
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("", response_model=User)
|
||||
@router.post("", response_model=UserMin)
|
||||
async def create_users(user: UserRegister, req: Request):
|
||||
request_id = req.state.request_id
|
||||
header = {"x-api-request-id": request_id}
|
||||
|
|
Loading…
Reference in New Issue