Beispiel #1
0
    def test_configurable_test_state(self):
        """
        Test test.configurable_test_state with and without comment
        """
        # Configure mock parameters
        mock_name = "cheese_shop"
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            "testing": {
                "old": "Unchanged",
                "new": "Something pretended to change"
            }
        }

        # Test default state with comment
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": "",
            }
            ret = test.configurable_test_state(mock_name)
            self.assertDictEqual(ret, mock_ret)

        # Test default state without comment
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": mock_comment,
            }
            ret = test.configurable_test_state(mock_name, comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)
Beispiel #2
0
def test_configurable_test_state():
    """
    Test test.configurable_test_state with and without comment
    """
    mock_name = "cheese_shop"
    mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
    mock_changes = {
        "testing": {
            "old": "Unchanged",
            "new": "Something pretended to change"
        }
    }

    with patch.dict(test.__opts__, {"test": False}):
        mock_ret = {
            "name": mock_name,
            "changes": mock_changes,
            "result": True,
            "comment": "",
        }
        ret = test.configurable_test_state(mock_name)
        assert ret == mock_ret

    with patch.dict(test.__opts__, {"test": False}):
        mock_ret = {
            "name": mock_name,
            "changes": mock_changes,
            "result": True,
            "comment": mock_comment,
        }
        ret = test.configurable_test_state(mock_name, comment=mock_comment)
        assert ret == mock_ret
Beispiel #3
0
    def test_configurable_test_state(self):
        '''
        Test test.configurable_test_state with and without comment
        '''
        # Configure mock parameters
        mock_name = 'cheese_shop'
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            'testing': {
                'old': 'Unchanged',
                'new': 'Something pretended to change'
            }
        }

        # Test default state with comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {
                'name': mock_name,
                'changes': mock_changes,
                'result': True,
                'comment': ''
            }
            ret = test.configurable_test_state(mock_name)
            self.assertDictEqual(ret, mock_ret)

        # Test default state without comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {
                'name': mock_name,
                'changes': mock_changes,
                'result': True,
                'comment': mock_comment
            }
            ret = test.configurable_test_state(mock_name, comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)
Beispiel #4
0
    def test_configurable_test_state(self):
        '''
        Test test.configurable_test_state with and without comment
        '''
        # Configure mock parameters
        mock_name = 'cheese_shop'
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            'testing': {
                'old': 'Unchanged',
                'new': 'Something pretended to change'
            }
        }

        # Test default state with comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': ''}
            ret = test.configurable_test_state(mock_name)
            self.assertDictEqual(ret, mock_ret)

        # Test default state without comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': mock_comment}
            ret = test.configurable_test_state(mock_name,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)
Beispiel #5
0
    def test_configurable_test_state_result(self):
        """
        Test test.configurable_test_state with permutations of result and with
        comment
        """
        # Configure mock parameters
        mock_name = "cheese_shop"
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            "testing": {
                "old": "Unchanged",
                "new": "Something pretended to change"
            }
        }

        # Test result=Random and comment
        with patch.dict(test.__opts__, {"test": False}):
            ret = test.configurable_test_state(mock_name,
                                               result="Random",
                                               comment=mock_comment)
            self.assertEqual(ret["name"], mock_name)
            self.assertEqual(ret["changes"], mock_changes)
            self.assertIn(ret["result"], [True, False])
            self.assertEqual(ret["comment"], mock_comment)

        # Test result=True and comment
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": mock_comment,
            }
            ret = test.configurable_test_state(mock_name,
                                               result=True,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=False and comment
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": False,
                "comment": mock_comment,
            }
            ret = test.configurable_test_state(mock_name,
                                               result=False,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=Cheese
        with patch.dict(test.__opts__, {"test": False}):
            self.assertRaises(
                SaltInvocationError,
                test.configurable_test_state,
                mock_name,
                result="Cheese",
            )
Beispiel #6
0
    def test_configurable_test_state_result(self):
        '''
        Test test.configurable_test_state with permutations of result and with
        comment
        '''
        # Configure mock parameters
        mock_name = 'cheese_shop'
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            'testing': {
                'old': 'Unchanged',
                'new': 'Something pretended to change'
            }
        }

        # Test result=Random and comment
        with patch.dict(test.__opts__, {'test': False}):
            ret = test.configurable_test_state(mock_name,
                                               result='Random',
                                               comment=mock_comment)
            self.assertEqual(ret['name'], mock_name)
            self.assertEqual(ret['changes'], mock_changes)
            self.assertIn(ret['result'], [True, False])
            self.assertEqual(ret['comment'], mock_comment)

        # Test result=True and comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {
                'name': mock_name,
                'changes': mock_changes,
                'result': True,
                'comment': mock_comment
            }
            ret = test.configurable_test_state(mock_name,
                                               result=True,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=False and comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {
                'name': mock_name,
                'changes': mock_changes,
                'result': False,
                'comment': mock_comment
            }
            ret = test.configurable_test_state(mock_name,
                                               result=False,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=Cheese
        with patch.dict(test.__opts__, {'test': False}):
            self.assertRaises(SaltInvocationError,
                              test.configurable_test_state,
                              mock_name,
                              result='Cheese')
Beispiel #7
0
def test_configurable_test_state_result():
    """
    Test test.configurable_test_state with permutations of result and with
    comment
    """
    mock_name = "cheese_shop"
    mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
    mock_changes = {
        "testing": {
            "old": "Unchanged",
            "new": "Something pretended to change"
        }
    }

    with patch.dict(test.__opts__, {"test": False}):
        ret = test.configurable_test_state(mock_name,
                                           result="Random",
                                           comment=mock_comment)
        assert ret["name"] == mock_name
        assert ret["changes"] == mock_changes
        assert ret["result"] in [True, False]
        assert ret["comment"] == mock_comment

    with patch.dict(test.__opts__, {"test": False}):
        mock_ret = {
            "name": mock_name,
            "changes": mock_changes,
            "result": True,
            "comment": mock_comment,
        }
        ret = test.configurable_test_state(mock_name,
                                           result=True,
                                           comment=mock_comment)
        assert ret == mock_ret

    with patch.dict(test.__opts__, {"test": False}):
        mock_ret = {
            "name": mock_name,
            "changes": mock_changes,
            "result": False,
            "comment": mock_comment,
        }
        ret = test.configurable_test_state(mock_name,
                                           result=False,
                                           comment=mock_comment)
        assert ret == mock_ret

    with patch.dict(test.__opts__, {"test": False}):
        pytest.raises(
            SaltInvocationError,
            test.configurable_test_state,
            mock_name,
            result="Cheese",
        )
Beispiel #8
0
    def test_configurable_test_state_warnings(self):
        """
        Test test.configurable_test_state with and without warnings
        """
        # Configure mock parameters
        mock_name = "cheese_shop"
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_warning = "Today the van broke down."
        mock_warning_list = [mock_warning, "Oooooooooohhh........!"]
        mock_changes = {
            "testing": {
                "old": "Unchanged",
                "new": "Something pretended to change"
            }
        }

        # Test default state without warnings
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": "",
            }
            ret = test.configurable_test_state(mock_name)
            self.assertDictEqual(ret, mock_ret)

        # Test default state with warnings (string)
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": "",
                "warnings": mock_warning_list,
            }
            ret = test.configurable_test_state(mock_name,
                                               warnings=mock_warning_list)
            self.assertDictEqual(ret, mock_ret)

        # Test default state with warnings (list)
        with patch.dict(test.__opts__, {"test": False}):
            mock_ret = {
                "name": mock_name,
                "changes": mock_changes,
                "result": True,
                "comment": "",
                "warnings": ["Today the van broke down."],
            }
            ret = test.configurable_test_state(mock_name,
                                               warnings=mock_warning)

            self.assertDictEqual(ret, mock_ret)
Beispiel #9
0
    def test_configurable_test_state_result(self):
        '''
        Test test.configurable_test_state with permutations of result and with
        comment
        '''
        # Configure mock parameters
        mock_name = 'cheese_shop'
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_changes = {
            'testing': {
                'old': 'Unchanged',
                'new': 'Something pretended to change'
            }
        }

        # Test result=Random and comment
        with patch.dict(test.__opts__, {'test': False}):
            ret = test.configurable_test_state(mock_name,
                                               result='Random',
                                               comment=mock_comment)
            self.assertEqual(ret['name'], mock_name)
            self.assertEqual(ret['changes'], mock_changes)
            self.assertIn(ret['result'], [True, False])
            self.assertEqual(ret['comment'], mock_comment)

        # Test result=True and comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': mock_comment}
            ret = test.configurable_test_state(mock_name,
                                               result=True,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=False and comment
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': False,
                        'comment': mock_comment}
            ret = test.configurable_test_state(mock_name,
                                               result=False,
                                               comment=mock_comment)
            self.assertDictEqual(ret, mock_ret)

        # Test result=Cheese
        with patch.dict(test.__opts__, {'test': False}):
            self.assertRaises(SaltInvocationError,
                              test.configurable_test_state,
                              mock_name,
                              result='Cheese')
Beispiel #10
0
    def test_configurable_test_state_warnings(self):
        '''
        Test test.configurable_test_state with and without warnings
        '''
        # Configure mock parameters
        mock_name = 'cheese_shop'
        mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
        mock_warning = 'Today the van broke down.'
        mock_warning_list = [
            mock_warning,
            "Oooooooooohhh........!"
        ]
        mock_changes = {
            'testing': {
                'old': 'Unchanged',
                'new': 'Something pretended to change'
            }
        }

        # Test default state without warnings
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': ''}
            ret = test.configurable_test_state(mock_name)
            self.assertDictEqual(ret, mock_ret)

        # Test default state with warnings (string)
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': '',
                        'warnings': mock_warning_list}
            ret = test.configurable_test_state(mock_name,
                                               warnings=mock_warning_list)
            self.assertDictEqual(ret, mock_ret)

        # Test default state with warnings (list)
        with patch.dict(test.__opts__, {'test': False}):
            mock_ret = {'name': mock_name,
                        'changes': mock_changes,
                        'result': True,
                        'comment': '',
                        'warnings': ['Today the van broke down.']}
            ret = test.configurable_test_state(mock_name,
                                               warnings=mock_warning)

            self.assertDictEqual(ret, mock_ret)