def test_list_absent(self): ''' Test to delete a value from a grain formed as a list ''' ret = {'changes': {}, 'name': self.name, 'result': True, 'comment': 'Value edam is absent from grain cheese'} ret1 = {'changes': {'deleted': self.value}, 'name': self.name, 'result': None, 'comment': 'Value edam in grain cheese is set to be deleted'} ret2 = {'changes': {}, 'name': self.name, 'result': True, 'comment': 'Grain cheese does not exist'} ret3 = {'changes': {}, 'name': self.name, 'result': False, 'comment': 'Grain cheese is not a valid list'} with patch.dict(grains.__grains__, {self.name: ['eves']}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret) with patch.dict(grains.__opts__, {'test': True}): with patch.dict(grains.__grains__, {self.name: [self.value]}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret1) self.assertDictEqual(grains.list_absent(self.name, self.value), ret2) with patch.dict(grains.__grains__, {self.name: 'eves'}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret3)
def test_list_absent(self): ''' Test to delete a value from a grain formed as a list ''' ret = { 'changes': {}, 'name': self.name, 'result': True, 'comment': 'Value edam is absent from grain cheese' } ret1 = { 'changes': { 'deleted': self.value }, 'name': self.name, 'result': None, 'comment': 'Value edam in grain cheese is set to be deleted' } ret2 = { 'changes': {}, 'name': self.name, 'result': True, 'comment': 'Grain cheese does not exist' } ret3 = { 'changes': {}, 'name': self.name, 'result': False, 'comment': 'Grain cheese is not a valid list' } with patch.dict(grains.__grains__, {self.name: ['eves']}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret) with patch.dict(grains.__opts__, {'test': True}): with patch.dict(grains.__grains__, {self.name: [self.value]}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret1) self.assertDictEqual(grains.list_absent(self.name, self.value), ret2) with patch.dict(grains.__grains__, {self.name: 'eves'}): self.assertDictEqual(grains.list_absent(self.name, self.value), ret3)
def test_list_absent_already(self): grains.__grains__ = grainsmod.__grains__ = {"a": "aval", "foo": ["bar"]} ret = grains.list_absent(name="foo", value="baz") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Value baz is absent from grain foo") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": ["bar"]})
def test_list_absent_inexistent(self): grains.__grains__ = grainsmod.__grains__ = {"a": "aval"} ret = grains.list_absent(name="foo", value="baz") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Grain foo does not exist") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval"})
def test_list_absent(self): grains.__grains__ = grainsmod.__grains__ = {"a": "aval", "foo": ["bar"]} ret = grains.list_absent(name="foo", value="bar") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Value bar was deleted from grain foo") self.assertEqual(ret["changes"], {"deleted": "bar"}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": []})
def test_list_absent_inexistent(self): grains.__grains__ = grainsmod.__grains__ = {'a': 'aval'} ret = grains.list_absent(name='foo', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Grain foo does not exist') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval'})
def test_list_absent_inexistent_nested(self): with self.setGrains({'a': 'aval'}): ret = grains.list_absent(name='foo:list', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Grain foo:list does not exist') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval'}) self.assertGrainFileContent("a: aval\n")
def test_list_absent_already(self): self.setGrains({'a': 'aval', 'foo': ['bar']}) ret = grains.list_absent(name='foo', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value baz is absent from grain foo') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval', 'foo': ['bar']}) self.assertGrainFileContent("a: aval\n" + "foo:\n" + "- bar\n")
def test_list_absent_not_a_list(self): grains.__grains__ = grainsmod.__grains__ = {'a': 'aval', 'foo': 'bar'} ret = grains.list_absent(name='foo', value='bar') # Note from dr4Ke: should be false, IMO self.assertEqual(ret['result'], False) self.assertEqual(ret['comment'], 'Grain foo is not a valid list') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval', 'foo': 'bar'})
def test_list_absent_not_a_list(self): with self.setGrains({"a": "aval", "foo": "bar"}): ret = grains.list_absent(name="foo", value="bar") self.assertEqual(ret["result"], False) self.assertEqual(ret["comment"], "Grain foo is not a valid list") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": "bar"}) self.assertGrainFileContent("a: aval\n" + "foo: bar\n")
def test_list_absent_inexistent_nested(self): with self.setGrains({"a": "aval"}): ret = grains.list_absent(name="foo:list", value="baz") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Grain foo:list does not exist") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval"}) self.assertGrainFileContent("a: aval\n")
def test_list_absent_not_a_list(self): grains.__grains__ = grainsmod.__grains__ = {"a": "aval", "foo": "bar"} ret = grains.list_absent(name="foo", value="bar") # Note from dr4Ke: should be false, IMO self.assertEqual(ret["result"], False) self.assertEqual(ret["comment"], "Grain foo is not a valid list") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": "bar"})
def test_list_absent_not_a_list(self): with self.setGrains({'a': 'aval', 'foo': 'bar'}): ret = grains.list_absent(name='foo', value='bar') self.assertEqual(ret['result'], False) self.assertEqual(ret['comment'], 'Grain foo is not a valid list') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval', 'foo': 'bar'}) self.assertGrainFileContent("a: aval\n" + "foo: bar\n")
def test_list_absent(self): with self.setGrains({'a': 'aval', 'foo': ['bar']}): ret = grains.list_absent(name='foo', value='bar') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value bar was deleted from grain foo') self.assertEqual(ret['changes'], {'deleted': ['bar']}) self.assertEqual(grains.__grains__, {'a': 'aval', 'foo': []}) self.assertGrainFileContent("a: aval\n" + "foo: []\n")
def test_list_absent(self): with self.setGrains({"a": "aval", "foo": ["bar"]}): ret = grains.list_absent(name="foo", value="bar") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Value bar was deleted from grain foo") self.assertEqual(ret["changes"], {"deleted": ["bar"]}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": []}) self.assertGrainFileContent("a: aval\n" + "foo: []\n")
def test_list_absent_already(self): with self.setGrains({"a": "aval", "foo": ["bar"]}): ret = grains.list_absent(name="foo", value="baz") self.assertEqual(ret["result"], True) self.assertEqual(ret["comment"], "Value baz is absent from grain foo") self.assertEqual(ret["changes"], {}) self.assertEqual(grains.__grains__, {"a": "aval", "foo": ["bar"]}) self.assertGrainFileContent("a: aval\n" + "foo:\n" + "- bar\n")
def test_list_absent_already(self): grains.__grains__ = grainsmod.__grains__ = { 'a': 'aval', 'foo': ['bar'] } ret = grains.list_absent(name='foo', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value baz is absent from grain foo') self.assertEqual(ret['changes'], {}) self.assertEqual(grains.__grains__, {'a': 'aval', 'foo': ['bar']})
def test_list_absent(self): grains.__grains__ = grainsmod.__grains__ = {'a': 'aval', 'foo': ['bar']} ret = grains.list_absent( name='foo', value='bar') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value bar was deleted from grain foo') self.assertEqual(ret['changes'], {'deleted': 'bar'}) self.assertEqual( grains.__grains__, {'a': 'aval', 'foo': []})
def test_list_absent_inexistent_nested(self): self.setGrains({'a': 'aval'}) ret = grains.list_absent( name='foo:list', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Grain foo:list does not exist') self.assertEqual(ret['changes'], {}) self.assertEqual( grains.__grains__, {'a': 'aval'}) self.assertGrainFileContent("a: aval\n")
def test_list_absent(self): self.setGrains({'a': 'aval', 'foo': ['bar']}) ret = grains.list_absent( name='foo', value='bar') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value bar was deleted from grain foo') self.assertEqual(ret['changes'], {'deleted': ['bar']}) self.assertEqual( grains.__grains__, {'a': 'aval', 'foo': []}) self.assertGrainFileContent("a: aval\n" + "foo: []\n" )
def test_list_absent_not_a_list(self): self.setGrains({'a': 'aval', 'foo': 'bar'}) ret = grains.list_absent( name='foo', value='bar') self.assertEqual(ret['result'], False) self.assertEqual(ret['comment'], 'Grain foo is not a valid list') self.assertEqual(ret['changes'], {}) self.assertEqual( grains.__grains__, {'a': 'aval', 'foo': 'bar'}) self.assertGrainFileContent("a: aval\n" + "foo: bar\n" )
def test_list_absent_already(self): self.setGrains({'a': 'aval', 'foo': ['bar']}) ret = grains.list_absent( name='foo', value='baz') self.assertEqual(ret['result'], True) self.assertEqual(ret['comment'], 'Value baz is absent from grain foo') self.assertEqual(ret['changes'], {}) self.assertEqual( grains.__grains__, {'a': 'aval', 'foo': ['bar']}) self.assertGrainFileContent("a: aval\n" + "foo:\n" + "- bar\n" )