3
0
Fork 0

feat: add feature to edit email settings, basic message preview

This commit is contained in:
Lance Edgar 2024-12-23 19:24:17 -06:00
parent 3035d1f58a
commit 95ff87fbf3
19 changed files with 826 additions and 4 deletions

View file

@ -392,3 +392,47 @@ class TestFileDownload(DataTestCase):
widget = typ.widget_maker()
self.assertIsInstance(widget, widgets.FileDownloadWidget)
self.assertEqual(widget.url, '/foo')
class TestEmailRecipients(TestCase):
def test_serialize(self):
typ = mod.EmailRecipients()
node = colander.SchemaNode(typ)
recips = [
'alice@example.com',
'bob@example.com',
]
recips_str = ', '.join(recips)
# values
result = typ.serialize(node, recips_str)
self.assertEqual(result, '\n'.join(recips))
# null
result = typ.serialize(node, colander.null)
self.assertIs(result, colander.null)
def test_deserialize(self):
typ = mod.EmailRecipients()
node = colander.SchemaNode(typ)
recips = [
'alice@example.com',
'bob@example.com',
]
recips_str = ', '.join(recips)
# values
result = typ.deserialize(node, recips_str)
self.assertEqual(result, recips_str)
# null
result = typ.deserialize(node, colander.null)
self.assertIs(result, colander.null)
def test_widget_maker(self):
typ = mod.EmailRecipients()
widget = typ.widget_maker()
self.assertIsInstance(widget, widgets.EmailRecipientsWidget)

View file

@ -10,7 +10,7 @@ from pyramid import testing
from wuttaweb import grids
from wuttaweb.forms import widgets as mod
from wuttaweb.forms.schema import (FileDownload, PersonRef, RoleRefs, UserRefs, Permissions,
WuttaDateTime)
WuttaDateTime, EmailRecipients)
from tests.util import WebTestCase
@ -304,6 +304,55 @@ class TestPermissionsWidget(WebTestCase):
self.assertIn("Polish the widgets", html)
class TestEmailRecipientsWidget(WebTestCase):
def make_field(self, node, **kwargs):
# TODO: not sure why default renderer is in use even though
# pyramid_deform was included in setup? but this works..
kwargs.setdefault('renderer', deform.Form.default_renderer)
return deform.Field(node, **kwargs)
def test_serialize(self):
node = colander.SchemaNode(EmailRecipients())
field = self.make_field(node)
widget = mod.EmailRecipientsWidget()
recips = [
'alice@example.com',
'bob@example.com',
]
recips_str = ', '.join(recips)
# readonly
result = widget.serialize(field, recips_str, readonly=True)
self.assertIn('<ul>', result)
self.assertIn('<li>alice@example.com</li>', result)
# editable
result = widget.serialize(field, recips_str)
self.assertIn('<b-input', result)
self.assertIn('type="textarea"', result)
def test_deserialize(self):
node = colander.SchemaNode(EmailRecipients())
field = self.make_field(node)
widget = mod.EmailRecipientsWidget()
recips = [
'alice@example.com',
'bob@example.com',
]
recips_str = ', '.join(recips)
# values
result = widget.deserialize(field, recips_str)
self.assertEqual(result, recips_str)
# null
result = widget.deserialize(field, colander.null)
self.assertIs(result, colander.null)
class TestBatchIdWidget(WebTestCase):
def make_field(self, node, **kwargs):