Browse Source

Don't render None as "null"

In a config file you never want the string "null" in place of a null
value. Just render an empty string instead.

Change-Id: Ibe145c4929d4944cd8d51c07a64aee6fd5f831f2
Closes-Bug: #1830967
Story: 2005797
(cherry picked from commit 75d527ab8fd13185f8db05ad69c43b3c89e06dc3)
changes/47/664747/1
Zane Bitter 2 years ago
committed by Emilien Macchi
parent
commit
e817b6d0ca
2 changed files with 7 additions and 0 deletions
  1. +2
    -0
      os_apply_config/renderers.py
  2. +5
    -0
      os_apply_config/tests/test_apply_config.py

+ 2
- 0
os_apply_config/renderers.py View File

@ -38,4 +38,6 @@ class JsonRenderer(pystache.Renderer):
partials, missing_tags)
def str_coerce(self, val):
if val is None:
return b''
return json.dumps(val)

+ 5
- 0
os_apply_config/tests/test_apply_config.py View File

@ -337,6 +337,11 @@ class OSConfigApplierTestCase(testtools.TestCase):
def test_render_moustache_bad_key(self):
self.assertEqual(u'', apply_config.render_moustache("{{badkey}}", {}))
def test_render_moustache_none(self):
self.assertEqual('foo: ',
apply_config.render_moustache("foo: {{foo}}",
{'foo': None}))
def test_render_executable(self):
params = {"x": "foo"}
self.assertEqual("foo\n", apply_config.render_executable(


Loading…
Cancel
Save