feat: added tests for web
This commit is contained in:
+2
-5
@@ -1,6 +1,7 @@
|
||||
import django_filters
|
||||
from django.utils.text import gettext_lazy as _
|
||||
from django_filters import OrderingFilter
|
||||
|
||||
from shop.models import Product
|
||||
|
||||
|
||||
@@ -9,11 +10,7 @@ class ProductFilter(django_filters.FilterSet):
|
||||
field_name="name", lookup_expr="icontains", label=_("Nombre")
|
||||
)
|
||||
tags = django_filters.BaseInFilter(field_name="tags", label=_("Etiquetas"))
|
||||
ordering = OrderingFilter(
|
||||
fields={
|
||||
'name': 'name'
|
||||
}
|
||||
)
|
||||
ordering = OrderingFilter(fields={"name": "name"})
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
|
||||
@@ -36,5 +36,5 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
migrations.RunPython(
|
||||
add_product_slug,
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
+5
-2
@@ -3,7 +3,8 @@ from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.text import gettext_lazy as _, slugify
|
||||
from django.utils.text import gettext_lazy as _
|
||||
from django.utils.text import slugify
|
||||
|
||||
|
||||
class TimestampedModel(models.Model):
|
||||
@@ -70,7 +71,9 @@ class Product(TimestampedModel):
|
||||
on_delete=models.SET_NULL,
|
||||
verbose_name=_("marca"),
|
||||
)
|
||||
slug = models.SlugField(default="", blank=True, null=True, max_length=128, verbose_name=_('Slug'))
|
||||
slug = models.SlugField(
|
||||
default="", blank=True, null=True, max_length=128, verbose_name=_("Slug")
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.utils.timezone import now
|
||||
|
||||
from shop.models import Product, ProductPrice, Tax
|
||||
|
||||
|
||||
class CreateProductsMixin:
|
||||
def create_product(
|
||||
self,
|
||||
sku="000001",
|
||||
name="Producto 1",
|
||||
description="Descripción",
|
||||
price=Decimal("10.00"),
|
||||
) -> Product:
|
||||
tax = Tax.objects.create(
|
||||
code="IVA",
|
||||
value=21,
|
||||
)
|
||||
product = Product.objects.create(
|
||||
sku=sku,
|
||||
name=name,
|
||||
description=description,
|
||||
)
|
||||
ProductPrice.objects.create(
|
||||
price=price,
|
||||
product=product,
|
||||
date=now(),
|
||||
tax=tax,
|
||||
)
|
||||
return product
|
||||
@@ -0,0 +1,22 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from shop.tests.mixins import CreateProductsMixin
|
||||
|
||||
|
||||
class TestIndex(TestCase, CreateProductsMixin):
|
||||
def setUp(self):
|
||||
self.product = self.create_product()
|
||||
|
||||
def test_index_view(self):
|
||||
response = self.client.get(reverse("shop:index"))
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_product_detail_view(self):
|
||||
response = self.client.get(
|
||||
reverse(
|
||||
"shop:product_detail",
|
||||
kwargs={"pk": self.product.pk, "slug": self.product.slug},
|
||||
)
|
||||
)
|
||||
assert response.status_code == 200
|
||||
Reference in New Issue
Block a user