HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //usr/local/ngfot/letsencrypt/certbot-nginx/certbot_nginx/tests/display_ops_test.py
"""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