def test_check_pillar_present(): """ Test to ensure the check_pillar function works properly with the 'present' keyword in the absence of a 'type' keyword. """ ret = {"name": "salt", "changes": {}, "result": True, "comment": ""} pillar_return = "I am a pillar." pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert test.check_pillar("salt", present="my_pillar") == ret
def test_check_pillar_dictionary(self): ''' Test to ensure the check_pillar function works properly with the 'key_type' checks, using the dictionary key_type. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} pillar_return = {'this': 'dictionary'} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
def test_check_pillar_present(self): ''' Test to ensure the check_pillar function works properly with the 'present' keyword in the absence of a 'type' keyword. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} pillar_return = 'I am a pillar.' pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', present='my_pillar'), ret)
def test_check_pillar_dictionary(): """ Test to ensure the check_pillar function works properly with the 'key_type' checks, using the dictionary key_type. """ ret = {"name": "salt", "changes": {}, "result": True, "comment": ""} pillar_return = {"this": "dictionary"} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert test.check_pillar("salt", dictionary="my_pillar") == ret pillar_return = OrderedDict({"this": "dictionary"}) pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert test.check_pillar("salt", dictionary="my_pillar") == ret pillar_return = "I am a pillar." pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert not test.check_pillar("salt", dictionary="my_pillar")["result"] pillar_return = ["I am a pillar."] pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert not test.check_pillar("salt", dictionary="my_pillar")["result"] pillar_return = True pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert not test.check_pillar("salt", dictionary="my_pillar")["result"] pillar_return = 1 pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): assert not test.check_pillar("salt", dictionary="my_pillar")["result"]
def test_check_pillar_dictionary(self): ''' Test to ensure the check_pillar function works properly with the 'key_type' checks, using the dictionary key_type. ''' ret = { 'name': 'salt', 'changes': {}, 'result': True, 'comment': '' } pillar_return = {'this': 'dictionary'} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
def test_check_pillar_present(self): ''' Test to ensure the check_pillar function works properly with the 'present' keyword in the absence of a 'type' keyword. ''' ret = { 'name': 'salt', 'changes': {}, 'result': True, 'comment': '' } pillar_return = 'I am a pillar.' pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', present='my_pillar'), ret)
def test_check_pillar_dictionary(self): """ Test to ensure the check_pillar function works properly with the 'key_type' checks, using the dictionary key_type. """ ret = {"name": "salt", "changes": {}, "result": True, "comment": ""} pillar_return = {"this": "dictionary"} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertEqual(test.check_pillar("salt", dictionary="my_pillar"), ret) # With an ordered dict pillar_return = OrderedDict({"this": "dictionary"}) pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertEqual(test.check_pillar("salt", dictionary="my_pillar"), ret) # With a string pillar_return = "I am a pillar." pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", dictionary="my_pillar")["result"] ) # With a list pillar_return = ["I am a pillar."] pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", dictionary="my_pillar")["result"] ) # With a boolean pillar_return = True pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", dictionary="my_pillar")["result"] ) # With an int pillar_return = 1 pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", dictionary="my_pillar")["result"] )
def test_check_pillar_string(self): """ Test to ensure the check_pillar function works properly with the 'key_type' checks, using the string key_type. """ ret = {"name": "salt", "changes": {}, "result": True, "comment": ""} pillar_return = "I am a pillar." pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertEqual(test.check_pillar("salt", string="my_pillar"), ret) # With unicode (py2) or str (py3) strings pillar_return = six.text_type("I am a pillar.") pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertEqual(test.check_pillar("salt", string="my_pillar"), ret) # With a dict pillar_return = {"this": "dictionary"} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", string="my_pillar")["result"]) # With a list pillar_return = ["I am a pillar."] pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", string="my_pillar")["result"]) # With a boolean pillar_return = True pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", string="my_pillar")["result"]) # With an int pillar_return = 1 pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {"pillar.get": pillar_mock}): self.assertFalse( test.check_pillar("salt", string="my_pillar")["result"])
def test_check_pillar_dictionary(self): ''' Test to ensure the check_pillar function works properly with the 'key_type' checks, using the dictionary key_type. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} pillar_return = {'this': 'dictionary'} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret) # With an ordered dict pillar_return = OrderedDict({'this': 'dictionary'}) pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret) # With a string pillar_return = 'I am a pillar.' pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', dictionary='my_pillar')['result']) # With a list pillar_return = ['I am a pillar.'] pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', dictionary='my_pillar')['result']) # With a boolean pillar_return = True pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', dictionary='my_pillar')['result']) # With an int pillar_return = 1 pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', dictionary='my_pillar')['result'])
def test_check_pillar_string(self): ''' Test to ensure the check_pillar function works properly with the 'key_type' checks, using the string key_type. ''' ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} pillar_return = 'I am a pillar.' pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', string='my_pillar'), ret) # With unicode (py2) or str (py3) strings pillar_return = six.text_type('I am a pillar.') pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertEqual(test.check_pillar('salt', string='my_pillar'), ret) # With a dict pillar_return = {'this': 'dictionary'} pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', string='my_pillar')['result']) # With a list pillar_return = ['I am a pillar.'] pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', string='my_pillar')['result']) # With a boolean pillar_return = True pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', string='my_pillar')['result']) # With an int pillar_return = 1 pillar_mock = MagicMock(return_value=pillar_return) with patch.dict(test.__salt__, {'pillar.get': pillar_mock}): self.assertFalse( test.check_pillar('salt', string='my_pillar')['result'])