This commit is contained in:
2026-05-18 14:08:13 -04:00
commit 377326ec2c
36 changed files with 1473 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
from decimal import Decimal
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from inventory.models import Item, ItemTemplate
User = get_user_model()
class TemplateFieldsIntegrationTests(TestCase):
def setUp(self):
self.user = User.objects.create_user(username="alice", password="password123")
def test_create_item_with_template_fields(self):
tmpl = ItemTemplate.objects.create(
name="VHS Player",
category="Electronics",
field_definitions=[
{"name": "rewind", "label": "Has Rewind", "type": "boolean"},
{"name": "outputs", "label": "Output Count", "type": "number"},
],
)
self.client.login(username="alice", password="password123")
response = self.client.post(
reverse("item-create"),
{
"template": tmpl.id,
"title": "Panasonic VHS",
"brand": "Panasonic",
"category": "",
"purchase_price": "5.00",
"prop_rewind": "on",
"prop_outputs": "2",
},
)
self.assertEqual(response.status_code, 302)
item = Item.objects.get(title="Panasonic VHS")
self.assertTrue(item.properties.get("rewind"))
self.assertEqual(item.properties.get("outputs"), "2")