File: configurator_reverter_test.py

package info (click to toggle)
python-certbot-apache 4.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,468 kB
  • sloc: python: 7,517; sh: 44; makefile: 10
file content (82 lines) | stat: -rw-r--r-- 2,816 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Test for certbot_apache._internal.configurator implementations of reverter"""
import shutil
import sys
import unittest
from unittest import mock

import pytest

from certbot import errors
from certbot_apache._internal.tests import util


class ConfiguratorReverterTest(util.ApacheTest):
    """Test for ApacheConfigurator reverter methods"""

    def setUp(self):  # pylint: disable=arguments-differ
        super().setUp()

        self.config = util.get_apache_configurator(
            self.config_path, self.vhost_path, self.config_dir, self.work_dir)

        self.vh_truth = util.get_vh_truth(self.temp_dir, "debian_apache_2_4/multiple_vhosts")

    def tearDown(self):
        shutil.rmtree(self.config_dir)
        shutil.rmtree(self.work_dir)
        shutil.rmtree(self.temp_dir)

    def test_bad_save_checkpoint(self):
        self.config.reverter.add_to_checkpoint = mock.Mock(side_effect=errors.ReverterError)
        self.config.parser.add_dir(self.vh_truth[0].path, "Test", "bad_save_ckpt")
        with pytest.raises(errors.PluginError):
            self.config.save()

    def test_bad_save_finalize_checkpoint(self):
        self.config.reverter.finalize_checkpoint = mock.Mock(side_effect=errors.ReverterError)
        self.config.parser.add_dir(self.vh_truth[0].path, "Test", "bad_save_ckpt")
        with pytest.raises(errors.PluginError):
            self.config.save("Title")

    def test_finalize_save(self):
        mock_finalize = mock.Mock()
        self.config.reverter = mock_finalize
        self.config.save("Example Title")

        assert mock_finalize.is_called

    def test_revert_challenge_config(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load

        self.config.revert_challenge_config()
        assert mock_load.call_count == 1

    def test_revert_challenge_config_error(self):
        self.config.reverter.revert_temporary_config = mock.Mock(
            side_effect=errors.ReverterError)

        with pytest.raises(errors.PluginError):
            self.config.revert_challenge_config()

    def test_rollback_checkpoints(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load

        self.config.rollback_checkpoints()
        assert mock_load.call_count == 1

    def test_rollback_error(self):
        self.config.reverter.rollback_checkpoints = mock.Mock(side_effect=errors.ReverterError)
        with pytest.raises(errors.PluginError):
            self.config.rollback_checkpoints()

    def test_recovery_routine_reload(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load
        self.config.recovery_routine()
        assert mock_load.call_count == 1


if __name__ == "__main__":
    sys.exit(pytest.main(sys.argv[1:] + [__file__]))  # pragma: no cover