diff --git a/tests/test_routes/test_item_type.py b/tests/test_routes/test_item_type.py index 8dd0806..764335a 100644 --- a/tests/test_routes/test_item_type.py +++ b/tests/test_routes/test_item_type.py @@ -29,14 +29,12 @@ def test_create_item_type(client, item_type_fixture, item_n, response_status): def test_get_item_type(client, item_type_fixture): - # 200_OK as any item types are found get_response = client.get(url) assert get_response.status_code == status.HTTP_200_OK 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 get_response = client.get(url) assert get_response.status_code == status.HTTP_404_NOT_FOUND @@ -62,8 +60,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): @@ -78,36 +78,54 @@ def test_update_item_type(client, dbsession, item_n, body, item_type_fixture, re assert json_response["name"] == body["name"] +@pytest.mark.parametrize( + 'item_n,count,response_status', + [ + (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), + # Несуществующий id + (2, 1, status.HTTP_404_NOT_FOUND), + # Некорректное число + (0, -1, status.HTTP_422_UNPROCESSABLE_ENTITY), + ], +) +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 + 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["total_available"] == min(count, len(items_with_same_type_id[item_n].items)) + + @pytest.mark.parametrize( 'item_n,response_status', [ - # Есть один item available (0, status.HTTP_200_OK), - # type_id без items - (1, status.HTTP_404_NOT_FOUND), - # Несуществующий type_id + (1, status.HTTP_200_OK), (2, status.HTTP_404_NOT_FOUND), ], ) -def test_update_item_type_available(client, item_n, items_with_same_type_id, response_status): +def test_delete_item_type(client, item_type_fixture, item_n, 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}") + 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: - response = client.patch(f"{url}/available/{type_id}") + response = client.get(f"{url}/{type_id}") assert response.status_code == status.HTTP_404_NOT_FOUND -def test_delete_item_type(client, item_type_fixture): - response = client.delete(f"{url}/{item_type_fixture[0].id}") +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 + response = client.get(f"{url}/{type_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