Create product categories in tests

This commit is contained in:
Gabriel Augendre 2023-04-02 19:37:57 +02:00
parent 61edce6e69
commit 55b6cb9cb8
2 changed files with 15 additions and 1 deletions

View file

@ -6,7 +6,7 @@ from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import Group, Permission
from common.models import User
from purchase.models import Basket, BasketItem, PaymentMethod, Product
from purchase.models import Basket, BasketItem, PaymentMethod, Product, ProductCategory
USER_PASSWORD = "test_password"
@ -26,12 +26,21 @@ class CashierFactory(factory.django.DjangoModelFactory):
self.groups.add(CashierGroupFactory())
class ProductCategoryFactory(factory.django.DjangoModelFactory):
class Meta:
model = ProductCategory
name = factory.Faker("text", max_nb_chars=30)
color_hue = factory.LazyFunction(partial(random.randint, 0, 360))
class ProductFactory(factory.django.DjangoModelFactory):
class Meta:
model = Product
name = factory.Faker("text", max_nb_chars=80)
unit_price_cents = factory.LazyFunction(partial(random.randint, 80, 650))
category = factory.Iterator(ProductCategory.objects.all())
class PaymentMethodFactory(factory.django.DjangoModelFactory):

View file

@ -16,6 +16,7 @@ from purchase.tests.factories import (
BasketWithItemsFactory,
CashierFactory,
PaymentMethodFactory,
ProductCategoryFactory,
ProductFactory,
)
@ -30,6 +31,8 @@ def test_cashier_create_and_update_basket( # noqa: PLR0915
# Setup data
cashier = CashierFactory()
ProductCategoryFactory()
ProductCategoryFactory()
products = [
ProductFactory(),
ProductFactory(),
@ -257,6 +260,8 @@ def test_baskets_list(live_server: LiveServer, selenium: WebDriver):
# Setup test data
cashier = CashierFactory()
ProductCategoryFactory()
ProductCategoryFactory()
_ = [
ProductFactory(),
ProductFactory(),