Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
 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"]})
Пример #4
0
 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"})
Пример #5
0
 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": []})
Пример #6
0
 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'})
Пример #7
0
 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")
Пример #8
0
 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")
Пример #9
0
 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'})
Пример #10
0
 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")
Пример #11
0
 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")
Пример #12
0
 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"})
Пример #13
0
 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")
Пример #14
0
 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")
Пример #15
0
 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")
Пример #16
0
 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")
Пример #17
0
 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']})
Пример #18
0
 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': []})
Пример #19
0
 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")
Пример #20
0
 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"
     )
Пример #21
0
 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"
     )
Пример #22
0
 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"
     )