コード例 #1
0
    def test_configfile(self):
        """
        Test to allows for inputting a yaml dictionary into a file
        for apache configuration files.
        """
        with patch("os.path.exists", MagicMock(return_value=True)):
            name = "/etc/distro/specific/apache.conf"
            config = 'VirtualHost: this: "*:80"'
            new_config = 'LiteralHost: that: "*:79"'

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

            with patch.object(salt.utils.files, "fopen",
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=config)
                with patch.dict(apache.__salt__,
                                {"apache.config": mock_config}):
                    ret.update({"comment": "Configuration is up to date."})
                    self.assertDictEqual(apache.configfile(name, config), ret)

            with patch.object(salt.utils.files, "fopen",
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=new_config)
                with patch.dict(apache.__salt__,
                                {"apache.config": mock_config}):
                    ret.update({
                        "comment": "Configuration will update.",
                        "changes": {
                            "new": new_config,
                            "old": config
                        },
                        "result": None,
                    })
                    with patch.dict(apache.__opts__, {"test": True}):
                        self.assertDictEqual(
                            apache.configfile(name, new_config), ret)

            with patch.object(salt.utils.files, "fopen",
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=new_config)
                with patch.dict(apache.__salt__,
                                {"apache.config": mock_config}):
                    ret.update({
                        "comment": "Successfully created configuration.",
                        "result": True,
                    })
                    with patch.dict(apache.__opts__, {"test": False}):
                        self.assertDictEqual(apache.configfile(name, config),
                                             ret)
コード例 #2
0
ファイル: test_apache.py プロジェクト: zhangxc73912/salt
    def test_configfile(self):
        '''
        Test to allows for inputting a yaml dictionary into a file
        for apache configuration files.
        '''
        with patch('os.path.exists', MagicMock(return_value=True)):
            name = '/etc/distro/specific/apache.conf'
            config = 'VirtualHost: this: "*:80"'
            new_config = 'LiteralHost: that: "*:79"'

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

            with patch.object(salt.utils, 'fopen',
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=config)
                with patch.dict(apache.__salt__,
                                {'apache.config': mock_config}):
                    ret.update({'comment': 'Configuration is up to date.'})
                    self.assertDictEqual(apache.configfile(name, config), ret)

            with patch.object(salt.utils, 'fopen',
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=new_config)
                with patch.dict(apache.__salt__,
                                {'apache.config': mock_config}):
                    ret.update({
                        'comment': 'Configuration will update.',
                        'changes': {
                            'new': new_config,
                            'old': config
                        },
                        'result': None
                    })
                    with patch.dict(apache.__opts__, {'test': True}):
                        self.assertDictEqual(
                            apache.configfile(name, new_config), ret)

            with patch.object(salt.utils, 'fopen',
                              mock_open(read_data=config)):
                mock_config = MagicMock(return_value=new_config)
                with patch.dict(apache.__salt__,
                                {'apache.config': mock_config}):
                    ret.update({
                        'comment': 'Successfully created configuration.',
                        'result': True
                    })
                    with patch.dict(apache.__opts__, {'test': False}):
                        self.assertDictEqual(apache.configfile(name, config),
                                             ret)
コード例 #3
0
ファイル: apache_test.py プロジェクト: DaveQB/salt
    def test_configfile(self):
        '''
        Test to allows for inputting a yaml dictionary into a file
        for apache configuration files.
        '''
        name = '/etc/distro/specific/apache.conf'
        config = 'VirtualHost: this: "*:80"'
        new_config = 'LiteralHost: that: "*:79"'

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

        with patch.object(salt.utils, 'fopen', mock_open(read_data=config)):
            mock_config = MagicMock(return_value=config)
            with patch.dict(apache.__salt__, {'apache.config': mock_config}):
                ret.update({'comment': 'Configuration is up to date.'})
                self.assertDictEqual(apache.configfile(name, config), ret)

        with patch.object(salt.utils, 'fopen', mock_open(read_data=config)):
            mock_config = MagicMock(return_value=new_config)
            with patch.dict(apache.__salt__, {'apache.config': mock_config}):
                ret.update({'comment': 'Configuration will update.',
                            'changes': {'new': new_config,
                                        'old': config},
                            'result': None})
                with patch.dict(apache.__opts__, {'test': True}):
                    self.assertDictEqual(apache.configfile(name, new_config), ret)

        with patch.object(salt.utils, 'fopen', mock_open(read_data=config)):
            mock_config = MagicMock(return_value=new_config)
            with patch.dict(apache.__salt__, {'apache.config': mock_config}):
                ret.update({'comment': 'Successfully created configuration.',
                            'result': True})
                with patch.dict(apache.__opts__, {'test': False}):
                    self.assertDictEqual(apache.configfile(name, config), ret)