Skip to content

Commit

Permalink
Lint testers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kronolynx committed Feb 7, 2017
1 parent ddc1813 commit 2bbb2a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
24 changes: 11 additions & 13 deletions src/testers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
"""
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 2bbb2a5

Please sign in to comment.