Files
arbit/inventory/tests_template_fields.py
2026-05-18 14:08:13 -04:00

44 lines
1.4 KiB
Python

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")