From fd8ac67cf1061a33f6380e1df12a1bf70ab9f83a Mon Sep 17 00:00:00 2001 From: bsquillari Date: Wed, 29 Nov 2023 04:17:21 +0000 Subject: [PATCH] Fix signup bug --- auth-domain/user-manager/src/api/users.py | 18 +++++++--- .../user-manager/src/tests/unit/test_users.py | 35 ++++++++++++------- gateway/src/api/routes/users.py | 4 +-- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/auth-domain/user-manager/src/api/users.py b/auth-domain/user-manager/src/api/users.py index 9d3c45f..81e5566 100644 --- a/auth-domain/user-manager/src/api/users.py +++ b/auth-domain/user-manager/src/api/users.py @@ -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, " was removed!") diff --git a/auth-domain/user-manager/src/tests/unit/test_users.py b/auth-domain/user-manager/src/tests/unit/test_users.py index 9438472..5baffc9 100644 --- a/auth-domain/user-manager/src/tests/unit/test_users.py +++ b/auth-domain/user-manager/src/tests/unit/test_users.py @@ -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): diff --git a/gateway/src/api/routes/users.py b/gateway/src/api/routes/users.py index b53370e..6390339 100644 --- a/gateway/src/api/routes/users.py +++ b/gateway/src/api/routes/users.py @@ -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}