From cfbd33809e2ec54221ee96d943aa5ef43c959524 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:27:17 +0000 Subject: [PATCH 1/6] Remove acme.util --- acme/util.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 acme/util.py diff --git a/acme/util.py b/acme/util.py deleted file mode 100644 index 8bea9091a..000000000 --- a/acme/util.py +++ /dev/null @@ -1,9 +0,0 @@ -"""ACME utilities.""" -import json -import pkg_resources - - -def load_schema(name): - """Load JSON schema from distribution.""" - return json.load(open(pkg_resources.resource_filename( - __name__, "schemata/%s.json" % name))) From 7abff038dc8b276075382377bb50bc0283407001 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:31:42 +0000 Subject: [PATCH 2/6] Display tests: move test_visual to tests/display.py script. --- letsencrypt/tests/display/util_test.py | 82 ++++++++++---------------- tests/display.py | 22 +++++++ 2 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 tests/display.py diff --git a/letsencrypt/tests/display/util_test.py b/letsencrypt/tests/display/util_test.py index 64ae3b713..41075c9ce 100644 --- a/letsencrypt/tests/display/util_test.py +++ b/letsencrypt/tests/display/util_test.py @@ -7,35 +7,20 @@ import mock from letsencrypt.display import util as display_util -class DisplayT(unittest.TestCase): - """Base class for both utility classes.""" - # pylint: disable=too-few-public-methods - def setUp(self): - self.choices = [("First", "Description1"), ("Second", "Description2")] - self.tags = ["tag1", "tag2", "tag3"] - self.tags_choices = [("1", "tag1"), ("2", "tag2"), ("3", "tag3")] +CHOICES = [("First", "Description1"), ("Second", "Description2")] +TAGS = ["tag1", "tag2", "tag3"] +TAGS_CHOICES = [("1", "tag1"), ("2", "tag2"), ("3", "tag3")] -def visual(displayer, choices): - """Visually test all of the display functions.""" - displayer.notification("Random notification!") - displayer.menu("Question?", choices, - ok_label="O", cancel_label="Can", help_label="??") - displayer.menu("Question?", [choice[1] for choice in choices], - ok_label="O", cancel_label="Can", help_label="??") - displayer.input("Input Message") - displayer.yesno("YesNo Message", yes_label="Yessir", no_label="Nosir") - displayer.checklist("Checklist Message", [choice[0] for choice in choices]) - - -class NcursesDisplayTest(DisplayT): +class NcursesDisplayTest(unittest.TestCase): """Test ncurses display. - Since this is mostly a wrapper, it might be more helpful to test the actual - dialog boxes. The test_visual function will actually display the various - boxes but requires the user to do the verification. If something seems amiss - please use the test_visual function to debug it, the automatic tests rely - on too much mocking. + Since this is mostly a wrapper, it might be more helpful to test the + actual dialog boxes. The test file located in ./tests/display.py + (relative to the root of the repository) will actually display the + various boxes but requires the user to do the verification. If + something seems amiss please use that test script to debug it, the + automatic tests rely on too much mocking. """ def setUp(self): @@ -43,7 +28,7 @@ class NcursesDisplayTest(DisplayT): self.displayer = display_util.NcursesDisplay() self.default_menu_options = { - "choices": self.choices, + "choices": CHOICES, "ok_label": "OK", "cancel_label": "Cancel", "help_button": False, @@ -63,7 +48,7 @@ class NcursesDisplayTest(DisplayT): def test_menu_tag_and_desc(self, mock_menu): mock_menu.return_value = (display_util.OK, "First") - ret = self.displayer.menu("Message", self.choices) + ret = self.displayer.menu("Message", CHOICES) mock_menu.assert_called_with("Message", **self.default_menu_options) self.assertEqual(ret, (display_util.OK, 0)) @@ -72,7 +57,7 @@ class NcursesDisplayTest(DisplayT): def test_menu_tag_and_desc_cancel(self, mock_menu): mock_menu.return_value = (display_util.CANCEL, "") - ret = self.displayer.menu("Message", self.choices) + ret = self.displayer.menu("Message", CHOICES) mock_menu.assert_called_with("Message", **self.default_menu_options) @@ -82,10 +67,10 @@ class NcursesDisplayTest(DisplayT): def test_menu_desc_only(self, mock_menu): mock_menu.return_value = (display_util.OK, "1") - ret = self.displayer.menu("Message", self.tags, help_label="More Info") + ret = self.displayer.menu("Message", TAGS, help_label="More Info") self.default_menu_options.update( - choices=self.tags_choices, help_button=True, help_label="More Info") + choices=TAGS_CHOICES, help_button=True, help_label="More Info") mock_menu.assert_called_with("Message", **self.default_menu_options) self.assertEqual(ret, (display_util.OK, 0)) @@ -94,7 +79,7 @@ class NcursesDisplayTest(DisplayT): def test_menu_desc_only_help(self, mock_menu): mock_menu.return_value = (display_util.HELP, "2") - ret = self.displayer.menu("Message", self.tags, help_label="More Info") + ret = self.displayer.menu("Message", TAGS, help_label="More Info") self.assertEqual(ret, (display_util.HELP, 1)) @@ -102,7 +87,7 @@ class NcursesDisplayTest(DisplayT): def test_menu_desc_only_cancel(self, mock_menu): mock_menu.return_value = (display_util.CANCEL, "") - ret = self.displayer.menu("Message", self.tags, help_label="More Info") + ret = self.displayer.menu("Message", TAGS, help_label="More Info") self.assertEqual(ret, (display_util.CANCEL, -1)) @@ -125,22 +110,19 @@ class NcursesDisplayTest(DisplayT): @mock.patch("letsencrypt.display.util." "dialog.Dialog.checklist") def test_checklist(self, mock_checklist): - self.displayer.checklist("message", self.tags) + self.displayer.checklist("message", TAGS) choices = [ - (self.tags[0], "", True), - (self.tags[1], "", True), - (self.tags[2], "", True), + (TAGS[0], "", True), + (TAGS[1], "", True), + (TAGS[2], "", True), ] mock_checklist.assert_called_with( "message", width=display_util.WIDTH, height=display_util.HEIGHT, choices=choices) - # def test_visual(self): - # visual(self.displayer, self.choices) - -class FileOutputDisplayTest(DisplayT): +class FileOutputDisplayTest(unittest.TestCase): """Test stdout display. Most of this class has to deal with visual output. In order to test how the @@ -168,7 +150,7 @@ class FileOutputDisplayTest(DisplayT): "FileDisplay._get_valid_int_ans") def test_menu(self, mock_ans): mock_ans.return_value = (display_util.OK, 1) - ret = self.displayer.menu("message", self.choices) + ret = self.displayer.menu("message", CHOICES) self.assertEqual(ret, (display_util.OK, 0)) def test_input_cancel(self): @@ -202,7 +184,7 @@ class FileOutputDisplayTest(DisplayT): @mock.patch("letsencrypt.display.util.FileDisplay.input") def test_checklist_valid(self, mock_input): mock_input.return_value = (display_util.OK, "2 1") - code, tag_list = self.displayer.checklist("msg", self.tags) + code, tag_list = self.displayer.checklist("msg", TAGS) self.assertEqual( (code, set(tag_list)), (display_util.OK, set(["tag1", "tag2"]))) @@ -214,7 +196,7 @@ class FileOutputDisplayTest(DisplayT): (display_util.OK, "1") ] - ret = self.displayer.checklist("msg", self.tags) + ret = self.displayer.checklist("msg", TAGS) self.assertEqual(ret, (display_util.OK, ["tag1"])) @mock.patch("letsencrypt.display.util.FileDisplay.input") @@ -223,7 +205,7 @@ class FileOutputDisplayTest(DisplayT): (display_util.OK, "10"), (display_util.CANCEL, "1") ] - ret = self.displayer.checklist("msg", self.tags) + ret = self.displayer.checklist("msg", TAGS) self.assertEqual(ret, (display_util.CANCEL, [])) def test_scrub_checklist_input_valid(self): @@ -240,7 +222,7 @@ class FileOutputDisplayTest(DisplayT): ] for i, list_ in enumerate(indices): set_tags = set( - self.displayer._scrub_checklist_input(list_, self.tags)) + self.displayer._scrub_checklist_input(list_, TAGS)) self.assertEqual(set_tags, exp[i]) def test_scrub_checklist_input_invalid(self): @@ -254,13 +236,13 @@ class FileOutputDisplayTest(DisplayT): ] for list_ in indices: self.assertEqual( - self.displayer._scrub_checklist_input(list_, self.tags), []) + self.displayer._scrub_checklist_input(list_, TAGS), []) def test_print_menu(self): # pylint: disable=protected-access # This is purely cosmetic... just make sure there aren't any exceptions - self.displayer._print_menu("msg", self.choices) - self.displayer._print_menu("msg", self.tags) + self.displayer._print_menu("msg", CHOICES) + self.displayer._print_menu("msg", TAGS) def test_wrap_lines(self): # pylint: disable=protected-access @@ -296,10 +278,6 @@ class FileOutputDisplayTest(DisplayT): self.displayer._get_valid_int_ans(3), (display_util.CANCEL, -1)) - # def test_visual(self): - # self.displayer = display_util.FileDisplay(sys.stdout) - # visual(self.displayer, self.choices) - class SeparateListInputTest(unittest.TestCase): """Test Module functions.""" diff --git a/tests/display.py b/tests/display.py new file mode 100644 index 000000000..dff56e42e --- /dev/null +++ b/tests/display.py @@ -0,0 +1,22 @@ +"""Manual test of display functions.""" +import sys + +from letsencrypt.display import util +from letsencrypt.tests.display import util_test + + +def test_visual(displayer, choices): + """Visually test all of the display functions.""" + displayer.notification("Random notification!") + displayer.menu("Question?", choices, + ok_label="O", cancel_label="Can", help_label="??") + displayer.menu("Question?", [choice[1] for choice in choices], + ok_label="O", cancel_label="Can", help_label="??") + displayer.input("Input Message") + displayer.yesno("YesNo Message", yes_label="Yessir", no_label="Nosir") + displayer.checklist("Checklist Message", [choice[0] for choice in choices]) + + +if __name__ == "__main__": + for displayer in util.NcursesDisplay(), util.FileDisplay(sys.stdout): + test_visual(displayer, util_test.CHOICES) From 46707406b5c788a650337040e5792cc5f938df91 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:38:03 +0000 Subject: [PATCH 3/6] Tests: don't cover plugins.common test functions. --- letsencrypt/plugins/common.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/letsencrypt/plugins/common.py b/letsencrypt/plugins/common.py index 03ddf7df7..1c5ccbefd 100644 --- a/letsencrypt/plugins/common.py +++ b/letsencrypt/plugins/common.py @@ -173,16 +173,18 @@ class Dvsni(object): return response -# test utils +# test utils used by letsencrypt_apache/letsencrypt_nginx (hence +# "pragma: no cover") TODO: this might quickly lead to dead code (also +# c.f. #383) -def setup_ssl_options(config_dir, src, dest): +def setup_ssl_options(config_dir, src, dest): # pragma: no cover """Move the ssl_options into position and return the path.""" option_path = os.path.join(config_dir, dest) shutil.copyfile(src, option_path) return option_path -def dir_setup(test_dir, pkg): +def dir_setup(test_dir, pkg): # pragma: no cover """Setup the directories necessary for the configurator.""" temp_dir = tempfile.mkdtemp("temp") config_dir = tempfile.mkdtemp("config") From 051a351a437f3f6b89baa08aa80277fcce5f91be Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:39:21 +0000 Subject: [PATCH 4/6] Move test_add_chal from letsencrypt_nginx (plugins.common 100% coverage). --- letsencrypt/plugins/common_test.py | 5 +++++ letsencrypt_nginx/tests/dvsni_test.py | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/letsencrypt/plugins/common_test.py b/letsencrypt/plugins/common_test.py index 6de86f2b8..c81d3939f 100644 --- a/letsencrypt/plugins/common_test.py +++ b/letsencrypt/plugins/common_test.py @@ -140,6 +140,11 @@ class DvsniTest(unittest.TestCase): from letsencrypt.plugins.common import Dvsni self.sni = Dvsni(configurator=mock.MagicMock()) + def test_add_chall(self): + self.sni.add_chall(self.achalls[0], 0) + self.assertEqual(1, len(self.sni.achalls)) + self.assertEqual([0], self.sni.indices) + def test_setup_challenge_cert(self): # This is a helper function that can be used for handling # open context managers more elegantly. It avoids dealing with diff --git a/letsencrypt_nginx/tests/dvsni_test.py b/letsencrypt_nginx/tests/dvsni_test.py index 5b46e8da6..4680c5c1e 100644 --- a/letsencrypt_nginx/tests/dvsni_test.py +++ b/letsencrypt_nginx/tests/dvsni_test.py @@ -61,11 +61,6 @@ class DvsniPerformTest(util.NginxTest): shutil.rmtree(self.config_dir) shutil.rmtree(self.work_dir) - def test_add_chall(self): - self.sni.add_chall(self.achalls[0], 0) - self.assertEqual(1, len(self.sni.achalls)) - self.assertEqual([0], self.sni.indices) - @mock.patch("letsencrypt_nginx.configurator" ".NginxConfigurator.choose_vhost") def test_perform(self, mock_choose): From bfba30701ea3cc93be2f4454bf96688da5c1d564 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:41:33 +0000 Subject: [PATCH 5/6] Bump core coverage --- tox.cover.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.cover.sh b/tox.cover.sh index 172d2e05b..554f9bfc5 100755 --- a/tox.cover.sh +++ b/tox.cover.sh @@ -20,5 +20,7 @@ rm -f .coverage # --cover-erase is off, make sure stats are correct # don't use sequential composition (;), if letsencrypt_nginx returns # 0, coveralls submit will be triggered (c.f. .travis.yml, # after_success) -cover letsencrypt 95 && cover acme 100 && \ - cover letsencrypt_apache 76 && cover letsencrypt_nginx 96 +cover letsencrypt 97 && \ + cover acme 100 && \ + cover letsencrypt_apache 76 && \ + cover letsencrypt_nginx 96 From 60478e213bb03781135735b8f6191f40339b35cd Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 28 Jun 2015 09:42:43 +0000 Subject: [PATCH 6/6] Bump apache coverage. --- tox.cover.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.cover.sh b/tox.cover.sh index 554f9bfc5..f1d882cee 100755 --- a/tox.cover.sh +++ b/tox.cover.sh @@ -22,5 +22,5 @@ rm -f .coverage # --cover-erase is off, make sure stats are correct # after_success) cover letsencrypt 97 && \ cover acme 100 && \ - cover letsencrypt_apache 76 && \ + cover letsencrypt_apache 78 && \ cover letsencrypt_nginx 96