55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
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
|