feat: added tags
This commit is contained in:
@@ -5,7 +5,7 @@ from rest_framework.test import APITestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from config.tests.mixins import TestUserAuthenticationMixin
|
||||
from shop.models import Product, ProductPrice, Tax, ProductBatch
|
||||
from shop.models import Product, ProductPrice, Tax, ProductBatch, Tag
|
||||
|
||||
|
||||
class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
@@ -17,6 +17,7 @@ class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
code="IVA",
|
||||
value=21,
|
||||
)
|
||||
self.tag = Tag.objects.create(name="Alimentos")
|
||||
|
||||
def create_products(self):
|
||||
self.product = Product.objects.create(
|
||||
@@ -58,6 +59,7 @@ class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
"price": "1.20",
|
||||
"stock": "100",
|
||||
"tax": self.tax.pk,
|
||||
"tags": [self.tag.pk],
|
||||
},
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
@@ -78,6 +80,9 @@ class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
"price": "1.20",
|
||||
"stock": "100",
|
||||
"tax": self.tax.pk,
|
||||
"tags": [
|
||||
self.tag.pk,
|
||||
],
|
||||
},
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
@@ -105,6 +110,9 @@ class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
"price": "1.20",
|
||||
"stock": "100",
|
||||
"tax": self.tax.pk,
|
||||
"tags": [
|
||||
self.tag.pk,
|
||||
],
|
||||
},
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
@@ -127,3 +135,32 @@ class TestProductsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
|
||||
response = self.client.delete(f"/api/v1/shop/products/{self.product.pk}/")
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
def test_create_update_product_tags(self):
|
||||
self.login()
|
||||
tag = Tag.objects.create(name="Alimentación")
|
||||
response = self.client.post(
|
||||
"/api/v1/shop/products/",
|
||||
{
|
||||
"name": "Papafritas",
|
||||
"description": "Las mejores papafritas",
|
||||
"is_digital_asset": False,
|
||||
"url": "",
|
||||
"price": "1.20",
|
||||
"stock": "100",
|
||||
"tax": self.tax.pk,
|
||||
"tags": [
|
||||
self.tag.pk,
|
||||
],
|
||||
},
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
pk = response.data.get("id")
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/products/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response = self.client.patch(f"/api/v1/shop/products/{pk}/", {"tags": [tag.pk]})
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
response = self.client.get(f"/api/v1/shop/products/{pk}/")
|
||||
assert response.data.get("tags", [])[0] == tag.pk
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from config.tests.mixins import TestUserAuthenticationMixin
|
||||
from shop.models import Tag
|
||||
|
||||
|
||||
class TestTagsAPI(APITestCase, TestUserAuthenticationMixin):
|
||||
model_name = "tag"
|
||||
|
||||
def setUp(self):
|
||||
self.create_user()
|
||||
|
||||
def create_tags(self):
|
||||
Tag.objects.create(name="Deportes")
|
||||
|
||||
def test_fetch_taxes(self):
|
||||
self.create_tags()
|
||||
self.login()
|
||||
response = self.client.get("/api/v1/shop/tags/")
|
||||
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/tags/", {"name": "Videojuegos"})
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
pk = response.data.get("id")
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/tags/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
def test_create_update_tax(self):
|
||||
self.login()
|
||||
response = self.client.post("/api/v1/shop/tags/", {"name": "Videojuegos"})
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
pk = response.data.get("id")
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/tags/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response = self.client.patch(
|
||||
f"/api/v1/shop/tags/{pk}/", {"name": "Juegos de mesa"}
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response = self.client.get(f"/api/v1/shop/tags/{pk}/")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
assert response.data.get("name") == "Juegos de mesa"
|
||||
Reference in New Issue
Block a user