From 2ae707458dd22bcb2e3c41d0893d6f11ce5f9190 Mon Sep 17 00:00:00 2001 From: Lymar Volodymyr Date: Fri, 21 Jun 2024 08:44:56 +0200 Subject: [PATCH] test: corrected comments --- makedoc/tests/conftest.py | 27 ++++++++++++--------------- makedoc/tests/test_views_makedoc.py | 16 ++++++++-------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/makedoc/tests/conftest.py b/makedoc/tests/conftest.py index b4200a7..ff0c90d 100644 --- a/makedoc/tests/conftest.py +++ b/makedoc/tests/conftest.py @@ -1,12 +1,9 @@ import pytest -from faker import Faker from rest_framework.test import APIClient from rest_framework_simplejwt.tokens import RefreshToken from users.models import CustomUser -fake = Faker() - @pytest.fixture def user(django_user_model): @@ -25,19 +22,19 @@ def authorized_client(user): @pytest.fixture -def test_data(): +def make_test_data(faker): return { - "delivery_type": fake.random_element(elements=("auto", "manual")), - "client_id": fake.random_int(min=1, max=100), + "delivery_type": faker.random_element(elements=("auto", "rw", "self-delivery")), + "client_id": faker.random_int(min=1, max=100), "items": [ - {"product_id": fake.random_int(min=1, max=100), - "quantity": fake.random_int(min=1, max=10), - "discount": fake.random_int(min=0, max=50)}, - {"product_id": fake.random_int(min=1, max=100), - "quantity": fake.random_int(min=1, max=10), - "discount": fake.random_int(min=0, max=50)}, + {"product_id": faker.random_int(min=1, max=100), + "quantity": faker.random_int(min=1, max=10), + "discount": faker.random_int(min=0, max=100)}, + {"product_id": faker.random_int(min=1, max=100), + "quantity": faker.random_int(min=1, max=10), + "discount": faker.random_int(min=0, max=100)}, ], - "factory_id": fake.random_int(min=1, max=100), - "destination": fake.city(), - "delivery_cost": fake.random_int(min=100, max=2000), + "factory_id": faker.random_int(min=1, max=100), + "destination": faker.city(), + "delivery_cost": faker.random_int(min=0, max=5000), } diff --git a/makedoc/tests/test_views_makedoc.py b/makedoc/tests/test_views_makedoc.py index a912ae7..6b74bef 100644 --- a/makedoc/tests/test_views_makedoc.py +++ b/makedoc/tests/test_views_makedoc.py @@ -7,34 +7,34 @@ @pytest.mark.django_db -def test__data_doc_view__unauthorized_user_cannot_post_data(test_data): +def test__data_doc_view__unauthorized_user_cannot_post_data(make_test_data): client = APIClient() url = reverse("data") - response = client.post(url, test_data, format="json") + response = client.post(url, make_test_data, format="json") assert response.status_code == 401 @pytest.mark.django_db -def test__data_doc_view__authorized_user_can_post_data(authorized_client, test_data): +def test__data_doc_view__authorized_user_can_post_data(authorized_client, make_test_data): url = reverse("data") - response = authorized_client.post(url, test_data, format="json") + response = authorized_client.post(url, make_test_data, format="json") assert response.status_code == 200 @pytest.mark.django_db def test__data_doc_view__authorized_user_post_data_response_is_correct(authorized_client, - test_data): + make_test_data): url = reverse("data") - response = authorized_client.post(url, test_data, format="json") + response = authorized_client.post(url, make_test_data, format="json") assert response.status_code == 200 assert response.json() == {"Success": True} @pytest.mark.django_db -def test__create_docs_view__authorized_user_get_valid_data(authorized_client, test_data): +def test__create_docs_view__authorized_user_get_valid_data(authorized_client, make_test_data): url = reverse("file") cache_key = f"validated_data_{authorized_client.user.id}" - cache.set(cache_key, json.dumps(test_data), timeout=120) + cache.set(cache_key, json.dumps(make_test_data), timeout=120) response = authorized_client.get(url) assert response.status_code == 200 assert response.json() == {"message": "Documents saved"}