From 55b6cb9cb8fe9a759220be39f838e00510d90ee6 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 2 Apr 2023 19:37:57 +0200 Subject: [PATCH] Create product categories in tests --- src/purchase/tests/factories.py | 11 ++++++++++- src/purchase/tests/test_cashier_flow.py | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/purchase/tests/factories.py b/src/purchase/tests/factories.py index 10037d8..4c641e0 100644 --- a/src/purchase/tests/factories.py +++ b/src/purchase/tests/factories.py @@ -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): diff --git a/src/purchase/tests/test_cashier_flow.py b/src/purchase/tests/test_cashier_flow.py index b1658d5..b67295d 100644 --- a/src/purchase/tests/test_cashier_flow.py +++ b/src/purchase/tests/test_cashier_flow.py @@ -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(),