54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
import secrets
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
|
|
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,
|
|
"material": v.product_type.material_and_subtype[0],
|
|
"product_type": v.product_type_id,
|
|
"color": v.color_id,
|
|
"spool_type": v.spool_type,
|
|
"quantity": quantity,
|
|
}
|
|
|
|
def handover_confirmation(self, order, **extra):
|
|
url = reverse("order_status", args=[order.pk])
|
|
response = self.client.post(
|
|
url,
|
|
{
|
|
"status": "handed_over",
|
|
"expected_status": order.status,
|
|
"expected_quantity": order.quantity,
|
|
**extra,
|
|
},
|
|
)
|
|
self.assertContains(response, "Übergabe bestätigen und einbuchen")
|
|
return url, response.context["form"].initial
|