From b7527e94768384c6b0fcf7249ac24d17a5a68531 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Fri, 5 Dec 2025 21:05:29 +0300 Subject: [PATCH 1/7] modified: tests/test_routes/test_item_type.py --- tests/test_routes/test_item_type.py | 33 ++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 8dd0806..1f4ada5 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -79,25 +79,38 @@ def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, re @pytest.mark.parametrize( - 'item_n,response_status', + 'item_n,count,response_status,expected_changed,expected_available', [ - # Есть один item available - (0, status.HTTP_200_OK), - # type_id без items - (1, status.HTTP_404_NOT_FOUND), + # Есть ItemType с 2 items (1 available, 1 unavailable), count=1 -> совпадает + (0, 1, status.HTTP_200_OK, 0, 1), + # Есть ItemType с 2 items, count=0 -> нужно сделать всех недоступными + (0, 0, status.HTTP_200_OK, 1, 0), + # Есть ItemType с 2 items, count=2 -> нужно сделать всех доступными + (0, 2, status.HTTP_200_OK, 1, 2), + # Есть ItemType с 2 items, count=100 -> максимум доступных = 2 + (0, 100, status.HTTP_200_OK, 1, 2), + # ItemType без items, count=5 -> ничего не меняется + (1, 5, status.HTTP_200_OK, 0, 0), # Несуществующий type_id - (2, status.HTTP_404_NOT_FOUND), + (2, 1, status.HTTP_404_NOT_FOUND, None, None), ], ) -def test_update_item_type_available(client, item_n, items_with_same_type_id, response_status): +def test_update_item_type_available( + client, item_n, count, items_with_same_type_id, response_status, expected_changed, expected_available +): type_id = -100000 if item_n < len(items_with_same_type_id): type_id = items_with_same_type_id[item_n].id - response = client.patch(f"{url}/available/{type_id}") + + response = client.patch(f"{url}/available/{type_id}?count={count}") assert response.status_code == response_status + if response.status_code == status.HTTP_200_OK: - response = client.patch(f"{url}/available/{type_id}") - assert response.status_code == status.HTTP_404_NOT_FOUND + data = response.json() + assert data["items_changed"] == expected_changed + assert data["total_available"] == expected_available + assert isinstance(data["item_ids"], list) + assert len(data["item_ids"]) == expected_changed def test_delete_item_type(client, item_type_fixture): From d440aed9914868fe8ec0924df535f3685db7e393 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Mon, 8 Dec 2025 21:45:29 +0300 Subject: [PATCH 2/7] modified: tests/test_routes/test_item_type.py --- tests/test_routes/test_item_type.py | 35 ++++++++++++----------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 1f4ada5..09f2515 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -79,38 +79,31 @@ def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, re @pytest.mark.parametrize( - 'item_n,count,response_status,expected_changed,expected_available', + 'item_n,count,response_status', [ - # Есть ItemType с 2 items (1 available, 1 unavailable), count=1 -> совпадает - (0, 1, status.HTTP_200_OK, 0, 1), - # Есть ItemType с 2 items, count=0 -> нужно сделать всех недоступными - (0, 0, status.HTTP_200_OK, 1, 0), - # Есть ItemType с 2 items, count=2 -> нужно сделать всех доступными - (0, 2, status.HTTP_200_OK, 1, 2), - # Есть ItemType с 2 items, count=100 -> максимум доступных = 2 - (0, 100, status.HTTP_200_OK, 1, 2), - # ItemType без items, count=5 -> ничего не меняется - (1, 5, status.HTTP_200_OK, 0, 0), - # Несуществующий type_id - (2, 1, status.HTTP_404_NOT_FOUND, None, None), + # 200_OK as item types are changed + (0, 1, status.HTTP_200_OK), + (0, 0, status.HTTP_200_OK), + (0, 2, status.HTTP_200_OK), + (0, 100, status.HTTP_200_OK), + (1, 5, status.HTTP_200_OK), + # Non-existent id + (2, 1, status.HTTP_404_NOT_FOUND), + # Not correct count + (0, -1, status.HTTP_422_UNPROCESSABLE_ENTITY), ], ) def test_update_item_type_available( - client, item_n, count, items_with_same_type_id, response_status, expected_changed, expected_available + client, item_n, count, items_with_same_type_id, response_status ): type_id = -100000 if item_n < len(items_with_same_type_id): type_id = items_with_same_type_id[item_n].id - - response = client.patch(f"{url}/available/{type_id}?count={count}") + response = client.patch(f"{url}/available/{type_id}", params={"count": count}) assert response.status_code == response_status - if response.status_code == status.HTTP_200_OK: data = response.json() - assert data["items_changed"] == expected_changed - assert data["total_available"] == expected_available - assert isinstance(data["item_ids"], list) - assert len(data["item_ids"]) == expected_changed + assert data["total_available"] == min(count, len(items_with_same_type_id[item_n].items)) def test_delete_item_type(client, item_type_fixture): From 5c2331559984a8a92c5915669cb18f6fde73558e Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Mon, 8 Dec 2025 21:48:21 +0300 Subject: [PATCH 3/7] fixed codestyle --- tests/test_routes/test_item_type.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 09f2515..4914e0a 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -93,9 +93,7 @@ def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, re (0, -1, status.HTTP_422_UNPROCESSABLE_ENTITY), ], ) -def test_update_item_type_available( - client, item_n, count, items_with_same_type_id, response_status -): +def test_update_item_type_available(client, item_n, count, items_with_same_type_id, response_status): type_id = -100000 if item_n < len(items_with_same_type_id): type_id = items_with_same_type_id[item_n].id From 6a2e679480cac269b81c50374d49afa238ba87cc Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Tue, 9 Dec 2025 00:52:12 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item_type.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 4914e0a..9655d15 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -62,8 +62,10 @@ def test_get_item_type_id(client, item_n, item_type_fixture, response_status): [ (0, {"name": True}, status.HTTP_422_UNPROCESSABLE_ENTITY), (1, {"name": "TestOK"}, status.HTTP_200_OK), - # Non-existent id + # Несуществующий id (2, {"name": "TestBAD"}, status.HTTP_404_NOT_FOUND), + # Некорректный ввод + (0, {}, status.HTTP_422_UNPROCESSABLE_ENTITY), ], ) def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, response_status): @@ -81,15 +83,14 @@ def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, re @pytest.mark.parametrize( 'item_n,count,response_status', [ - # 200_OK as item types are changed (0, 1, status.HTTP_200_OK), (0, 0, status.HTTP_200_OK), (0, 2, status.HTTP_200_OK), (0, 100, status.HTTP_200_OK), (1, 5, status.HTTP_200_OK), - # Non-existent id + # Несуществующий id (2, 1, status.HTTP_404_NOT_FOUND), - # Not correct count + # Некорректное число (0, -1, status.HTTP_422_UNPROCESSABLE_ENTITY), ], ) From 53bb0fd5fe71f55d90dd0d36f72505fa92f7c1c9 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Wed, 10 Dec 2025 23:28:39 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item_type.py | 43 +++++++++++++++++++---------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 9655d15..dcdd1db 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -28,15 +28,16 @@ def test_create_item_type(client, item_type_fixture, item_n, response_status): assert post_response.status_code == response_status -def test_get_item_type(client, item_type_fixture): - # 200_OK as any item types are found +def test_get_item_type_successfully(client, item_type_fixture): get_response = client.get(url) assert get_response.status_code == status.HTTP_200_OK + +def test_get_item_type_unsuccessfully(client, item_type_fixture): response = client.delete(f"{url}/{item_type_fixture[0].id}") assert response.status_code == status.HTTP_200_OK response = client.delete(f"{url}/{item_type_fixture[1].id}") assert response.status_code == status.HTTP_200_OK - # 404_NOT_FOUND as no item types are found + response = client.delete(f"{url}/{item_type_fixture[0].id}") get_response = client.get(url) assert get_response.status_code == status.HTTP_404_NOT_FOUND @@ -105,14 +106,28 @@ def test_update_item_type_available(client, item_n, count, items_with_same_type_ assert data["total_available"] == min(count, len(items_with_same_type_id[item_n].items)) -def test_delete_item_type(client, item_type_fixture): - response = client.delete(f"{url}/{item_type_fixture[0].id}") - assert response.status_code == status.HTTP_200_OK - # checking if items are not deleted - assert item_type_fixture[0].items == [] - # trying to delete deleted - response = client.delete(f"{url}/{item_type_fixture[0].id}") - assert response.status_code == status.HTTP_404_NOT_FOUND - # trying to get deleted - response = client.get(f'{url}/{item_type_fixture[0].id}') - assert response.status_code == status.HTTP_404_NOT_FOUND +@pytest.mark.parametrize( + 'item_n,response_status', + [ + (0, status.HTTP_200_OK), + (1, status.HTTP_200_OK), + ], +) +def test_delete_item_type(client, item_type_fixture, item_n, response_status): + type_id = item_type_fixture[item_n].id + response = client.delete(f"{url}/{type_id}") + assert response.status_code == response_status + if response.status_code == status.HTTP_200_OK: + assert client.get(f"{url}/{type_id}").status_code == status.HTTP_404_NOT_FOUND + + +def test_delete_item_type_with_items(client, items_with_same_type_id): + type_id = items_with_same_type_id[0].id + response = client.delete(f"{url}/{type_id}") + assert response.status_code == status.HTTP_403_FORBIDDEN + assert client.get(f"{url}/{type_id}").status_code == status.HTTP_200_OK + + +def test_delete_nonexistent_item_type(client, item_type_fixture): + response = client.delete(f"{url}/999999") + assert response.status_code == status.HTTP_404_NOT_FOUND \ No newline at end of file From 44fd2ef535563a531b76099fa99d956af521d350 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Thu, 11 Dec 2025 19:51:33 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item_type.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index dcdd1db..6008f24 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -32,6 +32,7 @@ def test_get_item_type_successfully(client, item_type_fixture): get_response = client.get(url) assert get_response.status_code == status.HTTP_200_OK + def test_get_item_type_unsuccessfully(client, item_type_fixture): response = client.delete(f"{url}/{item_type_fixture[0].id}") assert response.status_code == status.HTTP_200_OK @@ -58,6 +59,11 @@ def test_get_item_type_id(client, item_n, item_type_fixture, response_status): assert response.status_code == response_status +def test_get_item_type_id_invalid(client, item_type_fixture): + response = client.get(f'{url}/invalid') + assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY + + @pytest.mark.parametrize( 'item_n,body,response_status', [ @@ -130,4 +136,18 @@ def test_delete_item_type_with_items(client, items_with_same_type_id): def test_delete_nonexistent_item_type(client, item_type_fixture): response = client.delete(f"{url}/999999") - assert response.status_code == status.HTTP_404_NOT_FOUND \ No newline at end of file + assert response.status_code == status.HTTP_404_NOT_FOUND + + +@pytest.mark.parametrize( + 'type_id,response_status', + [ + # Неверный id + (999999, status.HTTP_404_NOT_FOUND), + # Неверный ввод + ("invalid", status.HTTP_422_UNPROCESSABLE_ENTITY), + ], +) +def test_delete_item_type_errors(client, item_type_fixture, type_id, response_status): + response = client.delete(f"{url}/{type_id}") + assert response.status_code == response_status From 1ebbcef930e7fa79b07d816b886f98ab042a9be7 Mon Sep 17 00:00:00 2001 From: Artem Bratyashin Date: Sat, 13 Dec 2025 20:34:18 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_routes/test_item_type.py | 42 +++++++---------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 6008f24..764335a 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -28,17 +28,13 @@ def test_create_item_type(client, item_type_fixture, item_n, response_status): assert post_response.status_code == response_status -def test_get_item_type_successfully(client, item_type_fixture): +def test_get_item_type(client, item_type_fixture): get_response = client.get(url) assert get_response.status_code == status.HTTP_200_OK - - -def test_get_item_type_unsuccessfully(client, item_type_fixture): response = client.delete(f"{url}/{item_type_fixture[0].id}") assert response.status_code == status.HTTP_200_OK response = client.delete(f"{url}/{item_type_fixture[1].id}") assert response.status_code == status.HTTP_200_OK - response = client.delete(f"{url}/{item_type_fixture[0].id}") get_response = client.get(url) assert get_response.status_code == status.HTTP_404_NOT_FOUND @@ -59,11 +55,6 @@ def test_get_item_type_id(client, item_n, item_type_fixture, response_status): assert response.status_code == response_status -def test_get_item_type_id_invalid(client, item_type_fixture): - response = client.get(f'{url}/invalid') - assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY - - @pytest.mark.parametrize( 'item_n,body,response_status', [ @@ -117,37 +108,24 @@ def test_update_item_type_available(client, item_n, count, items_with_same_type_ [ (0, status.HTTP_200_OK), (1, status.HTTP_200_OK), + (2, status.HTTP_404_NOT_FOUND), ], ) def test_delete_item_type(client, item_type_fixture, item_n, response_status): - type_id = item_type_fixture[item_n].id + type_id = -100000 + if item_n < len(item_type_fixture): + type_id = item_type_fixture[item_n].id response = client.delete(f"{url}/{type_id}") assert response.status_code == response_status if response.status_code == status.HTTP_200_OK: - assert client.get(f"{url}/{type_id}").status_code == status.HTTP_404_NOT_FOUND + response = client.get(f"{url}/{type_id}") + assert response.status_code == status.HTTP_404_NOT_FOUND def test_delete_item_type_with_items(client, items_with_same_type_id): type_id = items_with_same_type_id[0].id response = client.delete(f"{url}/{type_id}") + # Есть неудаленные items для данного item_type assert response.status_code == status.HTTP_403_FORBIDDEN - assert client.get(f"{url}/{type_id}").status_code == status.HTTP_200_OK - - -def test_delete_nonexistent_item_type(client, item_type_fixture): - response = client.delete(f"{url}/999999") - assert response.status_code == status.HTTP_404_NOT_FOUND - - -@pytest.mark.parametrize( - 'type_id,response_status', - [ - # Неверный id - (999999, status.HTTP_404_NOT_FOUND), - # Неверный ввод - ("invalid", status.HTTP_422_UNPROCESSABLE_ENTITY), - ], -) -def test_delete_item_type_errors(client, item_type_fixture, type_id, response_status): - response = client.delete(f"{url}/{type_id}") - assert response.status_code == response_status + response = client.get(f"{url}/{type_id}") + assert response.status_code == status.HTTP_200_OK