Skip to content

Commit

Permalink
Refs. #5. Add tests for using pyzor with multiple servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkiro committed Jul 11, 2014
1 parent 72d64d5 commit b8ab9fd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
41 changes: 40 additions & 1 deletion tests/functional/test_pyzor.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,49 @@ def test_digest(self):
out = self.check_pyzor("digest", None, input=msg).strip()
self.assertEqual(out.decode("utf8"), digest)

class MultipleServerPyzorScriptTest(PyzorTestBase):
password_file = None
access = """ALL : anonymous : allow
"""
servers = """127.0.0.1:9999
127.0.0.1:9998
127.0.0.1:9997
"""

def test_ping(self):
self.check_pyzor_multiple("ping", None, exit_code=0,
code=[200, 200, 200])

def test_pong(self):
input = "Test1 multiple pong Test2"
self.check_pyzor_multiple("pong", None, input=input, exit_code=0,
code=[200, 200, 200],
counts=[(sys.maxint, 0),
(sys.maxint, 0),
(sys.maxint, 0)])

def test_check(self):
input = "Test1 multiple check Test2"
self.check_pyzor_multiple("check", None, input=input, exit_code=1,
code=[200, 200, 200],
counts=[(0, 0), (0, 0), (0, 0)])

def test_report(self):
input = "Test1 multiple report Test2"
self.check_pyzor_multiple("report", None, input=input, exit_code=0,
code=[200, 200, 200])

def test_whitelist(self):
input = "Test1 multiple whitelist Test2"
self.check_pyzor_multiple("whitelist", None, input=input, exit_code=0,
code=[200, 200, 200])


def suite():
"""Gather all the tests from this module in a test suite."""
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(PyzorScriptTest))
test_suite.addTest(unittest.makeSuite(PyzorScriptTest))
test_suite.addTest(unittest.makeSuite(MultipleServerPyzorScriptTest))
return test_suite

if __name__ == '__main__':
Expand Down
14 changes: 10 additions & 4 deletions tests/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class PyzorTestBase(unittest.TestCase):
"log_file": "--log-file",
}
homedir = "./pyzor-test/"
address = "127.0.0.1"
port = "9999"
threads = "False"
access_file = "pyzord.access"
password_file = "pyzord.passwd"
Expand Down Expand Up @@ -112,7 +110,14 @@ def setUpClass(cls):
if option:
args.append(value)
args.append(option)
cls.pyzord = subprocess.Popen(args)
cls.pyzord = []

for line in cls.servers.splitlines():
line = line.strip()
if not line:
continue
addr, port = line.rsplit(":", 1)
cls.pyzord.append(subprocess.Popen(args + ["-a", addr, "-p", port]))
time.sleep(1) # allow time to initialize server

def setUp(self):
Expand All @@ -131,7 +136,8 @@ def tearDown(self):
@classmethod
def tearDownClass(cls):
super(PyzorTestBase, cls).tearDownClass()
cls.pyzord.kill()
for pyzord in cls.pyzord:
pyzord.kill()
shutil.rmtree(cls.homedir, True)
redis.StrictRedis(db=10).flushdb()

Expand Down

0 comments on commit b8ab9fd

Please sign in to comment.