feat: added lots of tests

This commit is contained in:
2024-05-13 12:35:58 +02:00
parent 05caeb9607
commit 9d83c3b30f
8 changed files with 545 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
from rest_framework import status
from rest_framework.test import APITestCase
from config.tests.mixins import TestUserAuthenticationMixin
from shop.models import Tax
class TestTaxesAPI(APITestCase, TestUserAuthenticationMixin):
model_name = "tax"
def setUp(self):
self.create_user()
def create_taxes(self):
Tax.objects.create(
code="IVA",
value=21,
)
def test_fetch_taxes(self):
self.create_taxes()
self.login()
response = self.client.get("/api/v1/shop/taxes/")
assert response.status_code == status.HTTP_200_OK
assert len(response.data.get("results")) == 1
def test_create_retrieve_tax(self):
self.login()
response = self.client.post("/api/v1/shop/taxes/", {"code": "IVA5", "value": 5})
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id")
response = self.client.get(f"/api/v1/shop/taxes/{pk}/")
assert response.status_code == status.HTTP_200_OK
def test_create_update_tax(self):
self.login()
response = self.client.post("/api/v1/shop/taxes/", {"code": "IVA5", "value": 5})
assert response.status_code == status.HTTP_201_CREATED
pk = response.data.get("id")
response = self.client.get(f"/api/v1/shop/taxes/{pk}/")
assert response.status_code == status.HTTP_200_OK
response = self.client.patch(
f"/api/v1/shop/taxes/{pk}/", {"code": "IVA10", "value": 10}
)
assert response.status_code == status.HTTP_200_OK
response = self.client.get(f"/api/v1/shop/taxes/{pk}/")
assert response.status_code == status.HTTP_200_OK
assert response.data.get("code") == "IVA10"
assert response.data.get("value") == 10