Skip to content

Commit

Permalink
test: add tests for document download view and create docs view
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 19, 2024
1 parent 51a0f03 commit 59225d1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions makedoc/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def authorized_client(user):
client = APIClient()
refresh = RefreshToken.for_user(user)
client.credentials(HTTP_AUTHORIZATION=f"Bearer {str(refresh.access_token)}")
client.user = user
return client
44 changes: 43 additions & 1 deletion makedoc/tests/test_views_makedoc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json

import pytest
from django.core.cache import cache
from django.urls import reverse
from rest_framework.test import APIClient

Expand Down Expand Up @@ -55,4 +58,43 @@ def test__data_doc_view__authorized_user_post_data_response_is_correct(authorize
"delivery_cost": 1500,
}
response = authorized_client.post(url, data, format="json")
assert response.json() == {"success": True, "data": data}
assert response.status_code == 200
assert response.json() == {"Success": True}


@pytest.mark.django_db
def test_create_docs_view_get_valid_data(authorized_client):
url = reverse("file")
cache_key = f"validated_data_{authorized_client.user.id}"
data = {
"delivery_type": "auto",
"client_id": 1,
"items": [
{"product_id": 1, "quantity": 2, "discount": 10},
{"product_id": 2, "quantity": 5, "discount": 4},
],
"factory_id": 1,
"destination": "New York",
"delivery_cost": 1500,
}
cache.set(cache_key, json.dumps(data), timeout=120)
response = authorized_client.get(url)
assert response.status_code == 200
assert response.json() == {"message": "Documents saved"}
cache.delete(cache_key)


@pytest.mark.django_db
def test_create_docs_view_get_no_data(authorized_client):
url = reverse("file")
response = authorized_client.get(url)
assert response.status_code == 400
assert response.json() == {"error": "No data found in cache"}


@pytest.mark.django_db
def test_download_doc_view(authorized_client):
url = reverse("downloadxls")
response = authorized_client.get(url)
assert response.status_code == 404
assert response.json() == {"error": "No file found"}

0 comments on commit 59225d1

Please sign in to comment.