template: Add is_empty method.

This makes it easy to detect when a user has specifically cleared a
template; i.e., from a specific configuration section.
This commit is contained in:
Brett Smith 2017-12-18 12:35:18 -05:00
parent 474a0390e3
commit 0b665d388e
2 changed files with 9 additions and 0 deletions

View file

@ -260,3 +260,6 @@ class Template:
if key.endswith('_date'):
template_vars[key] = value.strftime(self.date_fmt)
return ''.join(f(template_vars) for f in self.format_funcs)
def is_empty(self):
return not self.format_funcs

View file

@ -26,6 +26,7 @@ def assert_easy_render(tmpl, entity, amount, currency, expect_date, expect_amt):
" Accrued:Accounts Receivable " + expect_amt,
" Income:Donations " + expect_amt.replace(amount, "-" + amount),
]
assert not tmpl.is_empty()
def test_easy_template():
tmpl = template_from('Simplest')
@ -39,6 +40,11 @@ def test_currency_formatting():
tmpl = template_from('Simplest', signed_currencies=['USD'])
assert_easy_render(tmpl, 'CC', '7.99', 'USD', '2015/03/14', '$7.99')
def test_empty_template():
tmpl = template.Template("\n \n")
assert tmpl.render('BB', decimal.Decimal('8.99'), 'USD', DATE) == ''
assert tmpl.is_empty()
def test_complex_template():
template_vars = {
'entity': 'T-T',