From f118de3d211e665c2337730a65af82327b341ed5 Mon Sep 17 00:00:00 2001 From: Daniel Goldberg Date: Sun, 24 Nov 2019 10:42:56 +0200 Subject: [PATCH] Rename test classes to match PEP. Add test case with multiple classes in file. Remove setup in test runner. --- .../utils/plugins/pluginTests/BadInit.py | 2 +- .../utils/plugins/pluginTests/ComboFile.py | 15 +++++++++++++++ .../utils/plugins/pluginTests/PluginWorking.py | 2 +- .../utils/plugins/plugin_test.py | 17 +++++++++++------ 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py diff --git a/monkey/infection_monkey/utils/plugins/pluginTests/BadInit.py b/monkey/infection_monkey/utils/plugins/pluginTests/BadInit.py index b7909b33a..18e83c052 100644 --- a/monkey/infection_monkey/utils/plugins/pluginTests/BadInit.py +++ b/monkey/infection_monkey/utils/plugins/pluginTests/BadInit.py @@ -1,7 +1,7 @@ from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin -class badPluginInit(TestPlugin): +class BadPluginInit(TestPlugin): def __init__(self): raise Exception("TestException") diff --git a/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py b/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py new file mode 100644 index 000000000..2d73cd65b --- /dev/null +++ b/monkey/infection_monkey/utils/plugins/pluginTests/ComboFile.py @@ -0,0 +1,15 @@ +from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin + + +class NoInheritance: + pass + + +class BadInit(TestPlugin): + + def __init__(self): + raise Exception("TestException") + + +class ProperClass(TestPlugin): + pass diff --git a/monkey/infection_monkey/utils/plugins/pluginTests/PluginWorking.py b/monkey/infection_monkey/utils/plugins/pluginTests/PluginWorking.py index d762a1f82..a3fe237b6 100644 --- a/monkey/infection_monkey/utils/plugins/pluginTests/PluginWorking.py +++ b/monkey/infection_monkey/utils/plugins/pluginTests/PluginWorking.py @@ -1,5 +1,5 @@ from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin -class pluginWorking(TestPlugin): +class PluginWorking(TestPlugin): pass diff --git a/monkey/infection_monkey/utils/plugins/plugin_test.py b/monkey/infection_monkey/utils/plugins/plugin_test.py index 67077a8ad..7841c6c6a 100644 --- a/monkey/infection_monkey/utils/plugins/plugin_test.py +++ b/monkey/infection_monkey/utils/plugins/plugin_test.py @@ -1,18 +1,23 @@ from unittest import TestCase -from infection_monkey.utils.plugins.pluginTests.PluginWorking import pluginWorking +from infection_monkey.utils.plugins.pluginTests.ComboFile import BadInit, ProperClass +from infection_monkey.utils.plugins.pluginTests.PluginWorking import PluginWorking from infection_monkey.utils.plugins.pluginTests.BadImport import SomeDummyPlugin -from infection_monkey.utils.plugins.pluginTests.BadInit import badPluginInit +from infection_monkey.utils.plugins.pluginTests.BadInit import BadPluginInit from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin class PluginTester(TestCase): - def setUp(self): - pass + def test_combo_file(self): + TestPlugin.classes_to_load = [BadInit.__name__, ProperClass.__name__] + to_init = TestPlugin.get_classes() + self.assertEqual(len(to_init), 2) + objects = TestPlugin.get_instances() + self.assertEqual(len(objects), 1) def test_bad_init(self): - TestPlugin.classes_to_load = [badPluginInit.__name__] + TestPlugin.classes_to_load = [BadPluginInit.__name__] to_init = TestPlugin.get_classes() self.assertEqual(len(to_init), 1) objects = TestPlugin.get_instances() @@ -24,7 +29,7 @@ class PluginTester(TestCase): self.assertEqual(len(to_init), 0) def test_flow(self): - TestPlugin.classes_to_load = [pluginWorking.__name__] + TestPlugin.classes_to_load = [PluginWorking.__name__] to_init = TestPlugin.get_classes() self.assertEqual(len(to_init), 1) objects = TestPlugin.get_instances()