From 8aec311d9f9f402003782a0667e30f03c6a96c7d Mon Sep 17 00:00:00 2001 From: Eduard0803 Date: Wed, 29 Nov 2023 15:03:03 -0300 Subject: [PATCH] update tests user-routes --- gestao/tests/test_gestao.py | 87 ++----------------------------------- gestao/tests/utils.py | 69 +++++++++++++++-------------- 2 files changed, 38 insertions(+), 118 deletions(-) diff --git a/gestao/tests/test_gestao.py b/gestao/tests/test_gestao.py index c466b2d..6ed1d99 100644 --- a/gestao/tests/test_gestao.py +++ b/gestao/tests/test_gestao.py @@ -21,22 +21,6 @@ async def test_get_users(client: AsyncClient, fastapi_app: FastAPI) -> None: assert response.status_code == 200 -@pytest.mark.anyio -async def test_get_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None: - url = fastapi_app.url_path_for("create_user") - user = generate_fake_user() - await client.post(url, json=user) - - url = fastapi_app.url_path_for("get_users") - response = await client.get(url) - user_data = response.json()[0] - user_id = user_data['id'] - - url = fastapi_app.url_path_for("get_user", user_id=user_id) - response = await client.get(url) - assert response.status_code == 200 - - @pytest.mark.anyio async def test_get_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None: url = fastapi_app.url_path_for("get_user", user_id=str(uuid4())) @@ -56,28 +40,11 @@ async def test_create_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> async def test_create_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None: url = fastapi_app.url_path_for("create_user") user = generate_fake_user() - user.pop('name') + user.pop("name") response = await client.post(url, json=user) assert response.status_code == 422 -@pytest.mark.anyio -async def test_update_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None: - url = fastapi_app.url_path_for("create_user") - user = generate_fake_user() - await client.post(url, json=user) - - url = fastapi_app.url_path_for("get_users") - response = await client.get(url) - user_data = response.json()[0] - user_id = user_data['id'] - user_data['name'] = 'joao' - - url = fastapi_app.url_path_for("update_user", user_id=user_id) - response = await client.put(url, json=user_data) - assert response.status_code == 200 - - @pytest.mark.anyio async def test_update_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None: url = fastapi_app.url_path_for("update_user", user_id=str(uuid4())) @@ -86,60 +53,14 @@ async def test_update_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) @pytest.mark.anyio -async def test_delete_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None: - url = fastapi_app.url_path_for("create_user") - user = generate_fake_user() - await client.post(url, json=user) - - url = fastapi_app.url_path_for("get_users") - response = await client.get(url) - user_data = response.json()[0] - user_id = user_data['id'] - - url = fastapi_app.url_path_for("delete_user", user_id=user_id) - response = await client.delete(url) - assert response.status_code == 200 - - -@pytest.mark.anyio -async def test_disable_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None: - url = fastapi_app.url_path_for("create_user") - user = generate_fake_user() - await client.post(url, json=user) - - url = fastapi_app.url_path_for("get_users") - response = await client.get(url) - user_data = response.json()[0] - user_id = user_data['id'] - - url = fastapi_app.url_path_for("disable_user", user_id=user_id) - response = await client.patch(url) - assert response.status_code == 200 - - -@pytest.mark.anyio -async def test_disable_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None: +async def test_disable_user_incorrect( + client: AsyncClient, fastapi_app: FastAPI +) -> None: url = fastapi_app.url_path_for("disable_user", user_id=str(uuid4())) response = await client.patch(url) assert response.status_code == 404 -@pytest.mark.anyio -async def test_enable_user_correct(client: AsyncClient, fastapi_app: FastAPI) -> None: - url = fastapi_app.url_path_for("create_user") - user = generate_fake_user() - await client.post(url, json=user) - - url = fastapi_app.url_path_for("get_users") - response = await client.get(url) - user_data = response.json()[0] - user_id = user_data['id'] - - url = fastapi_app.url_path_for("enable_user", user_id=user_id) - response = await client.patch(url) - assert response.status_code == 200 - - @pytest.mark.anyio async def test_enable_user_incorrect(client: AsyncClient, fastapi_app: FastAPI) -> None: url = fastapi_app.url_path_for("enable_user", user_id=str(uuid4())) diff --git a/gestao/tests/utils.py b/gestao/tests/utils.py index ac93233..b4d3a02 100644 --- a/gestao/tests/utils.py +++ b/gestao/tests/utils.py @@ -1,42 +1,41 @@ def generate_fake_user(): from faker import Faker - f = Faker('pt-br') + f = Faker("pt-br") user = { - 'name': f'{f.name()}', - 'address': f'{f.address()}', - 'neighborhood': 'Gama', - 'city': f'{f.city()}', - 'state': f'{f.state()}', - 'zipcode': f'{f.postcode()}', - 'cpf': f'{f.random_number(digits=11)}', - 'rg': f'{f.random_number(digits=7)}', - 'birth_date': f'{f.date_of_birth()}', - 'place_of_birth': f'{f.city()}', - 'blood_type': 'A+', - 'gender': 'M', - 'father_name': f'{f.name()}', - 'mother_date': f'{f.name()}', - 'position': 'null', - 'occupancy': 'null', - 'admission_date': f'{f.date_of_birth()}', - 'situation': 'active', - 'phone': f'{f.phone_number()}', - 'email': f'{f.email(domain="sindpol.org.br")}', - 'marital_status': 'alone', - 'education': 'Bachelor Degree', - 'registration': f'{f.random_number(digits=10)}', - 'role': 'cop', - 'category': 'null', - 'pattern': 'null', - 'dispatcher': 'null', - 'dispatched_date': f'{f.date_of_birth()}', - 'war_name': f'{f.name()}', - 'password': 'admin', - 'rg_consignor': 'SSP', - 'rg_date': f'{f.date_of_birth()}', - 'situation_obs': 'null' + "name": f"{f.name()}", + "address": f"{f.address()}", + "neighborhood": "Gama", + "city": f"{f.city()}", + "state": f"{f.state()}", + "zipcode": f"{f.postcode()}", + "cpf": f"{f.random_number(digits=11)}", + "rg": f"{f.random_number(digits=7)}", + "birth_date": f"{f.date_of_birth()}", + "place_of_birth": f"{f.city()}", + "blood_type": "A+", + "gender": "M", + "father_name": f"{f.name()}", + "mother_date": f"{f.name()}", + "position": "null", + "occupancy": "null", + "admission_date": f"{f.date_of_birth()}", + "situation": "active", + "phone": f"{f.phone_number()}", + "email": f'{f.email(domain="sindpol.org.br")}', + "marital_status": "alone", + "education": "Bachelor Degree", + "registration": f"{f.random_number(digits=10)}", + "role": "cop", + "category": "null", + "pattern": "null", + "dispatcher": "null", + "dispatched_date": f"{f.date_of_birth()}", + "war_name": f"{f.name()}", + "password": "admin", + "rg_consignor": "SSP", + "rg_date": f"{f.date_of_birth()}", + "situation_obs": "null", } return user -