diff --git a/src/testers.py b/src/testers.py index 57a42b9..76c9491 100644 --- a/src/testers.py +++ b/src/testers.py @@ -38,7 +38,7 @@ def run(self, each, end): break if len(result) < len(self.tests): - result = result + [{ + result += [{ 'name': x.name, 'severity': x.severity, 'title': x.title, @@ -100,12 +100,8 @@ class Test(object): def __init__(self, test, tester): """ Args: - name (str): test name - severity (str): - title (str): - caption (str): - message (str[] or function): messages to display when the test is completed - breaks (bool): True if the test suite should stop False otherwise + test dict(): + tester Tester: Notes: message should contain an array with the messages for the different results that @@ -118,8 +114,6 @@ def __init__(self, test, tester): def run(self): """ - Args: - cred (dict(str:str)): parsed MongoDB URI Returns: tuple(int, str): test result value and message """ @@ -191,7 +185,7 @@ def valid_role(role): Returns: Bool: True if the role is not administrative """ - return not role in [ + return role not in [ 'userAdminAnyDatabase', 'dbAdminAnyDatabase' 'dbAdmin', @@ -230,7 +224,7 @@ def reduce_roles(roles): """ return reduce(lambda x, y: combine_result(x, y), [validate_role(r) for r in roles]) - def basic_validation(role): + def basic_validation(roles): """ Basic validation in case validate role fails due to lack of permissions Returns: @@ -361,7 +355,7 @@ def alerts_feb252015(test): def alerts_jun172014(test): version = test.tester.info["version"] - return not version in ["2.6.0", "2.6.1"] + return version not in ["2.6.0", "2.6.1"] def alerts_may052014(test): @@ -378,23 +372,27 @@ def alerts_jun052013(test): version = test.tester.info["version"] return not in_range(version, "2.4.0", "2.4.4") + def alerts_mar062014(test): version = test.tester.info["version"] return version > "2.3.1" + def alerts_oct012013(test): version = test.tester.info["version"] return version > "2.2.3" + def alerts_aug152013(test): version = test.tester.info["version"] return version > "2.5.1" + TEST_FUNCTIONS = { "1": lambda test: not (test.tester.cred['nodelist'][0][1] == 27017 and bool(test.tester.info)), "2": try_socket, "3": lambda test: try_socket(test, 28017), - "4": lambda test: not "version" in test.tester.info, + "4": lambda test: "version" not in test.tester.info, "5": lambda test: [test.tester.info["version"] > "2.4", str(test.tester.info["version"])], "6": lambda test: bool(test.tester.info["OpenSSLVersion"]) if ("OpenSSLVersion" in test.tester.info) diff --git a/src/widgets.py b/src/widgets.py index efc65ad..c019d78 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -226,18 +226,19 @@ class TestRunner(urwid.WidgetWrap): def __init__(self, title, cred, tests, callback): self.app = None + self.tester = Tester(cred, tests) urn = cred["nodelist"][0][0] + ":" + str(cred["nodelist"][0][1]) + ( "/" + (cred["database"]) if bool(cred["database"]) else "") self.data = {"title": title, "callback": callback, - "tester": Tester(cred, tests), "urn": urn, "num_tests": len(tests)} + "urn": urn, "num_tests": len(tests)} self.progress_text = urwid.Text( - ('progress', '0/' + str(self.data["num_test"]))) + ('progress', '0/' + str(self.data["num_tests"]))) running_display = urwid.Columns( [(14, urwid.Text(('text', 'Running test'))), self.progress_text]) self.progress_bar = CustomProgressBar( - 'progress', 'remaining', 0, self.data["num_test"]) + 'progress', 'remaining', 0, self.data["num_tests"]) self.text_running = urwid.Text(('text', '')) box = urwid.BoxAdapter(urwid.Filler( self.text_running, valign='top'), 2) @@ -250,7 +251,7 @@ def each(self, test): """ current = self.progress_bar.get_current() + 1 self.progress_text.set_text( - ('progress', '%s/%s' % (str(current), str(self.data["num_test"])))) + ('progress', '%s/%s' % (str(current), str(self.data["num_tests"])))) self.progress_bar.set_completion(current) self.text_running.set_text('Checking if %s...' % test.title) self.app.loop.draw_screen()