Use self.setGrains as context manager in grains test

This commit is contained in:
rallytime 2017-04-13 13:39:11 -06:00
parent 3d6c983c69
commit e440d2e8af

View File

@ -841,18 +841,18 @@ class GrainsTestCase(TestCase, LoaderModuleMockMixin):
def test_append_convert_to_list_empty(self):
# Append to an existing list
self.setGrains({'foo': None})
ret = grains.append(name='foo',
value='baz',
convert=True)
self.assertEqual(ret['result'], True)
self.assertEqual(ret['comment'], 'Value baz was added to grain foo')
self.assertEqual(ret['changes'], {'added': 'baz'})
self.assertEqual(
grains.__grains__,
{'foo': ['baz']})
self.assertGrainFileContent("foo:\n"
+ "- baz\n")
with self.setGrains({'foo': None}):
ret = grains.append(name='foo',
value='baz',
convert=True)
self.assertEqual(ret['result'], True)
self.assertEqual(ret['comment'], 'Value baz was added to grain foo')
self.assertEqual(ret['changes'], {'added': 'baz'})
self.assertEqual(
grains.__grains__,
{'foo': ['baz']})
self.assertGrainFileContent("foo:\n"
+ "- baz\n")
# 'list_present' function tests: 7