38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
import secrets
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import TestCase
|
|
|
|
from filament.models import Color, Manufacturer, ProductType, Variant
|
|
|
|
|
|
class CatalogTestCase(TestCase):
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
cls.password = secrets.token_urlsafe(24)
|
|
cls.alice = get_user_model().objects.create_user("michael", password=cls.password)
|
|
cls.bob = get_user_model().objects.create_user("person-zwei", password=cls.password)
|
|
cls.maker = Manufacturer.objects.create(name="Bambu Lab")
|
|
cls.product = ProductType.objects.create(manufacturer=cls.maker, name="PLA Matte")
|
|
cls.red = Color.objects.create(name="Scharlachrot")
|
|
cls.black = Color.objects.create(name="Kohleschwarz")
|
|
cls.spool = Variant.objects.create(
|
|
product_type=cls.product, color=cls.red, spool_type="spool"
|
|
)
|
|
cls.refill = Variant.objects.create(
|
|
product_type=cls.product, color=cls.red, spool_type="refill"
|
|
)
|
|
cls.black_spool = Variant.objects.create(
|
|
product_type=cls.product, color=cls.black, spool_type="spool"
|
|
)
|
|
|
|
def selection(self, variant=None, quantity=1):
|
|
v = variant or self.spool
|
|
return {
|
|
"manufacturer": v.manufacturer.pk,
|
|
"product_type": v.product_type_id,
|
|
"color": v.color_id,
|
|
"spool_type": v.spool_type,
|
|
"quantity": quantity,
|
|
}
|