3
0
Fork 0

fix: make WuttaQuantity serialize w/ app handler, remove custom widget

turns out we need to always serialize the value via render_quantity()
and the widget becomes redundant
This commit is contained in:
Lance Edgar 2025-01-07 13:34:42 -06:00
parent b5b88e2a7b
commit b73127e350
5 changed files with 31 additions and 76 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8; -*-
import datetime
import decimal
from unittest import TestCase
from unittest.mock import patch
@ -15,7 +16,7 @@ from wuttaweb.forms import widgets
from wuttaweb.testing import DataTestCase, WebTestCase
class TestWutaDateTime(TestCase):
class TestWuttaDateTime(TestCase):
def test_deserialize(self):
typ = mod.WuttaDateTime()
@ -91,11 +92,25 @@ class TestWuttaMoney(WebTestCase):
class TestWuttaQuantity(WebTestCase):
def test_widget_maker(self):
enum = self.app.enum
typ = mod.WuttaQuantity(self.request)
widget = typ.widget_maker()
self.assertIsInstance(widget, widgets.WuttaQuantityWidget)
def test_serialize(self):
node = colander.SchemaNode(mod.WuttaQuantity(self.request))
typ = node.typ
# null
result = typ.serialize(node, colander.null)
self.assertIs(result, colander.null)
result = typ.serialize(node, None)
self.assertIs(result, colander.null)
# quantity
result = typ.serialize(node, 42)
self.assertEqual(result, '42')
result = typ.serialize(node, 42.00)
self.assertEqual(result, '42')
result = typ.serialize(node, decimal.Decimal('42.00'))
self.assertEqual(result, '42')
result = typ.serialize(node, 42.13)
self.assertEqual(result, '42.13')
class TestObjectRef(DataTestCase):