File: display_ops_test.py

package info (click to toggle)
python-certbot-nginx 0.28.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 628 kB
  • sloc: python: 4,190; makefile: 171
file content (45 lines) | stat: -rw-r--r-- 1,548 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
"""Test certbot_apache.display_ops."""
import unittest

from certbot.display import util as display_util

from certbot.tests import util as certbot_util

from certbot_nginx import parser

from certbot_nginx.display_ops import select_vhost_multiple
from certbot_nginx.tests import util


class SelectVhostMultiTest(util.NginxTest):
    """Tests for certbot_nginx.display_ops.select_vhost_multiple."""

    def setUp(self):
        super(SelectVhostMultiTest, self).setUp()
        nparser = parser.NginxParser(self.config_path)
        self.vhosts = nparser.get_vhosts()

    def test_select_no_input(self):
        self.assertFalse(select_vhost_multiple([]))

    @certbot_util.patch_get_utility()
    def test_select_correct(self, mock_util):
        mock_util().checklist.return_value = (
            display_util.OK, [self.vhosts[3].display_repr(),
                              self.vhosts[2].display_repr()])
        vhs = select_vhost_multiple([self.vhosts[3],
                                     self.vhosts[2],
                                     self.vhosts[1]])
        self.assertTrue(self.vhosts[2] in vhs)
        self.assertTrue(self.vhosts[3] in vhs)
        self.assertFalse(self.vhosts[1] in vhs)

    @certbot_util.patch_get_utility()
    def test_select_cancel(self, mock_util):
        mock_util().checklist.return_value = (display_util.CANCEL, "whatever")
        vhs = select_vhost_multiple([self.vhosts[2], self.vhosts[3]])
        self.assertFalse(vhs)


if __name__ == "__main__":
    unittest.main()  # pragma: no cover