Skip to content

Commit

Permalink
test: corrected comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 21, 2024
1 parent 763e7af commit 2ae7074
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
27 changes: 12 additions & 15 deletions makedoc/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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),
}
16 changes: 8 additions & 8 deletions makedoc/tests/test_views_makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 2ae7074

Please sign in to comment.