2019-11-25 12:44:40 -05:00
|
|
|
"""Test certbot_nginx._internal.display_ops."""
|
2018-03-01 17:05:50 -05:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from certbot.display import util as display_util
|
|
|
|
|
from certbot.tests import util as certbot_util
|
2019-11-25 17:30:24 -05:00
|
|
|
from certbot_nginx._internal import parser
|
|
|
|
|
from certbot_nginx._internal.display_ops import select_vhost_multiple
|
2019-11-26 20:45:18 -05:00
|
|
|
import test_util as util
|
2018-03-01 17:05:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class SelectVhostMultiTest(util.NginxTest):
|
2019-11-25 17:30:24 -05:00
|
|
|
"""Tests for certbot_nginx._internal.display_ops.select_vhost_multiple."""
|
2018-03-01 17:05:50 -05:00
|
|
|
|
|
|
|
|
def setUp(self):
|
2021-04-08 16:04:51 -04:00
|
|
|
super().setUp()
|
2018-03-01 17:05:50 -05:00
|
|
|
nparser = parser.NginxParser(self.config_path)
|
|
|
|
|
self.vhosts = nparser.get_vhosts()
|
|
|
|
|
|
|
|
|
|
def test_select_no_input(self):
|
|
|
|
|
self.assertFalse(select_vhost_multiple([]))
|
|
|
|
|
|
2021-07-19 20:09:06 -04:00
|
|
|
@certbot_util.patch_display_util()
|
2018-03-01 17:05:50 -05:00
|
|
|
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]])
|
2022-01-04 17:59:58 -05:00
|
|
|
self.assertIn(self.vhosts[2], vhs)
|
|
|
|
|
self.assertIn(self.vhosts[3], vhs)
|
|
|
|
|
self.assertNotIn(self.vhosts[1], vhs)
|
2018-03-01 17:05:50 -05:00
|
|
|
|
2021-07-19 20:09:06 -04:00
|
|
|
@certbot_util.patch_display_util()
|
2018-03-01 17:05:50 -05:00
|
|
|
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]])
|
2022-01-04 17:59:58 -05:00
|
|
|
self.assertEqual(len(vhs), 0)
|
|
|
|
|
self.assertEqual(vhs, [])
|
2018-03-01 17:05:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main() # pragma: no cover
|