Example #1
0
    def test_enabled(self):
        '''
        Test to ensure an Apache module is enabled.
        '''
        name = 'cgi'

        ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}

        mock = MagicMock(side_effect=[True, False, False])
        mock_str = MagicMock(return_value={'Status': ['enabled']})
        with patch.dict(apache_module.__salt__, {
                'apache.check_mod_enabled': mock,
                'apache.a2enmod': mock_str
        }):
            comt = '{0} already enabled.'.format(name)
            ret.update({'comment': comt})
            self.assertDictEqual(apache_module.enabled(name), ret)

            comt = 'Apache module {0} is set to be enabled.'.format(name)
            ret.update({
                'comment': comt,
                'result': None,
                'changes': {
                    'new': 'cgi',
                    'old': None
                }
            })
            with patch.dict(apache_module.__opts__, {'test': True}):
                self.assertDictEqual(apache_module.enabled(name), ret)

            comt = 'Failed to enable {0} Apache module'.format(name)
            ret.update({'comment': comt, 'result': False, 'changes': {}})
            with patch.dict(apache_module.__opts__, {'test': False}):
                self.assertDictEqual(apache_module.enabled(name), ret)
    def test_enabled(self):
        '''
        Test to ensure an Apache module is enabled.
        '''
        name = 'cgi'

        ret = {'name': name,
               'result': True,
               'changes': {},
               'comment': ''}

        mock = MagicMock(side_effect=[True, False, False])
        mock_str = MagicMock(return_value={'Status': ['enabled']})
        with patch.dict(apache_module.__salt__,
                        {'apache.check_mod_enabled': mock,
                         'apache.a2enmod': mock_str}):
            comt = ('{0} already enabled.'.format(name))
            ret.update({'comment': comt})
            self.assertDictEqual(apache_module.enabled(name), ret)

            comt = ('Apache module {0} is set to be enabled.'.format(name))
            ret.update({'comment': comt, 'result': None,
                        'changes': {'new': 'cgi', 'old': None}})
            with patch.dict(apache_module.__opts__, {'test': True}):
                self.assertDictEqual(apache_module.enabled(name), ret)

            comt = ('Failed to enable {0} Apache module'.format(name))
            ret.update({'comment': comt, 'result': False, 'changes': {}})
            with patch.dict(apache_module.__opts__, {'test': False}):
                self.assertDictEqual(apache_module.enabled(name), ret)
Example #3
0
    def test_enabled(self):
        """
        Test to ensure an Apache module is enabled.
        """
        name = "cgi"

        ret = {"name": name, "result": True, "changes": {}, "comment": ""}

        mock = MagicMock(side_effect=[True, False, False])
        mock_str = MagicMock(return_value={"Status": ["enabled"]})
        with patch.dict(
                apache_module.__salt__,
            {
                "apache.check_mod_enabled": mock,
                "apache.a2enmod": mock_str
            },
        ):
            comt = "{0} already enabled.".format(name)
            ret.update({"comment": comt})
            self.assertDictEqual(apache_module.enabled(name), ret)

            comt = "Apache module {0} is set to be enabled.".format(name)
            ret.update({
                "comment": comt,
                "result": None,
                "changes": {
                    "new": "cgi",
                    "old": None
                },
            })
            with patch.dict(apache_module.__opts__, {"test": True}):
                self.assertDictEqual(apache_module.enabled(name), ret)

            comt = "Failed to enable {0} Apache module".format(name)
            ret.update({"comment": comt, "result": False, "changes": {}})
            with patch.dict(apache_module.__opts__, {"test": False}):
                self.assertDictEqual(apache_module.enabled(name), ret)