Skip to content

Commit

Permalink
refactor: refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andiserg committed Jul 28, 2023
1 parent eb83247 commit 3e2b1e1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/integrations/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_auth_token(client_db: AsyncClient): # noqa: F811;
Якщо ні, то повернути помилку 401.
"""
user_json = {"email": "test", "password": "test"} # nosec B106
await client_db.post("/users/create/", json=user_json)
await client_db.post("/users/", json=user_json)

auth_json = {"username": user_json["email"], "password": user_json["password"]}
auth_result = await client_db.post("/token/", data=auth_json)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/bank_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def test_update_costs_with_endpoint(client_db: AsyncClient, database: Data
# Створення менеджера
uow = SqlAlchemyUnitOfWork(session)
await create_monobank_manager(uow, user_id)
response = await client_db.put("/bankapi/update_costs/", headers=headers)
response = await client_db.put("/bankapi/costs/", headers=headers)
assert response.status_code == 200


Expand All @@ -61,7 +61,7 @@ async def test_add_bank_info_with_endpoint(client_db: AsyncClient):
headers = {"Authorization": token}

response = await client_db.post(
"/bankapi/add/",
"/bankapi/",
json={
"bank_name": "monobank",
"X-Token": "uZFOvRJNeXoVHYTUA_8NgHneWUz8IsG8dRPUbx60mbM4",
Expand Down
6 changes: 2 additions & 4 deletions tests/integrations/categories_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ async def test_create_category_endpoint(client_db: AsyncClient):
headers = {"Authorization": token}

category_data = {"name": "category name"}
response = await client_db.post(
"/categories/create/", json=category_data, headers=headers
)
response = await client_db.post("/categories/", json=category_data, headers=headers)
assert response.status_code == 201

created_category = response.json()
Expand All @@ -37,6 +35,6 @@ async def test_read_categories_endpoint(database: Database, client_db: AsyncClie
schema = CategoryCreateSchema(name=f"test category #{i}")
await create_category(uow, user_id, schema)

response = await client_db.get("/categories/list/", headers=headers)
response = await client_db.get("/categories/", headers=headers)
assert response.status_code == 200
assert len(response.json()) == 10
12 changes: 4 additions & 8 deletions tests/integrations/operations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def test_create_operation_endpoint(client_db: AsyncClient): # noqa: F811;
"source_type": "manual",
}
response = await client_db.post(
"/operations/create/", json=operation_data, headers=headers
"/operations/", json=operation_data, headers=headers
)
assert response.status_code == 201

Expand All @@ -37,9 +37,7 @@ async def test_create_operation_with_incorrect_data(client_db: AsyncClient):
token = auth_data["token"]
headers = {"Authorization": token}

incorrect_response = await client_db.post(
"/operations/create/", json={}, headers=headers
)
incorrect_response = await client_db.post("/operations/", json={}, headers=headers)
assert incorrect_response.status_code == 422


Expand All @@ -55,11 +53,9 @@ async def test_read_operations_endpoint(client_db: AsyncClient): # noqa: F811;
"description": "description",
"source_type": "manual",
}
await client_db.post(
"/operations/create/", json=operation_data, headers=headers
)
await client_db.post("/operations/", json=operation_data, headers=headers)

operations_response = await client_db.get("/operations/list/", headers=headers)
operations_response = await client_db.get("/operations/", headers=headers)
assert operations_response.status_code == 200

operations = operations_response.json()
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def test_create_user_endpoint(client_db: AsyncClient): # noqa: F811;
Testing src.views.users.create_user_view
"""
data = {"email": "test@mail.test", "password": "123456"} # nosec B106
result = await client_db.post("/users/create/", json=data)
result = await client_db.post("/users/", json=data)
assert result.status_code == 201
assert all(key in result.json() for key in ["id", "email"])

Expand All @@ -28,7 +28,7 @@ async def test_read_user(client_db: AsyncClient): # noqa: F811;
auth_result = await create_and_auth_func_user(client_db)
created_user, token = auth_result["user"], auth_result["token"]

read_result = await client_db.get("/users/me/", headers={"Authorization": token})
read_result = await client_db.get("/users/", headers={"Authorization": token})
assert read_result.status_code == 200

user_data = read_result.json()
Expand Down
4 changes: 2 additions & 2 deletions tests/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def create_func_user(client: AsyncClient) -> dict:
:return: dict з інформацією про користувача
"""
user_data = {"email": "test@mail.test", "password": "123456"} # nosec B106
return (await client.post("/users/create/", json=user_data)).json()
return (await client.post("/users/", json=user_data)).json()


async def create_and_auth_func_user(client: AsyncClient) -> dict:
Expand Down Expand Up @@ -64,4 +64,4 @@ async def create_operations(headers: dict, client: AsyncClient):
"mcc": random.randint(1000, 9999),
"source_type": "manual",
}
await client.post("/operations/create/", json=operation_data, headers=headers)
await client.post("/operations/", json=operation_data, headers=headers)

0 comments on commit 3e2b1e1

Please sign in to comment.