Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkiro committed Jul 13, 2014
1 parent e3c2d0c commit ce6dd09
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 76 deletions.
36 changes: 33 additions & 3 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setUp(self):
unittest.TestCase.setUp(self)

self.thread = 33715
self.timeout = None

patch("pyzor.account.sign_msg", return_value="TestSig").start()
patch("pyzor.account.hash_key").start()
Expand Down Expand Up @@ -80,7 +81,8 @@ def check_client(self, accounts, method, *args, **kwargs):
"""Tests if the request and response are sent
and read correctly by the client.
"""
client = pyzor.client.Client(accounts)
client = pyzor.client.Client(accounts=accounts,
timeout=self.timeout)
got_response = getattr(client, method)(*args, **kwargs)

self.assertEqual(str(got_response), self.mresponse[0].decode())
Expand Down Expand Up @@ -156,10 +158,11 @@ def test_handle_invalid_thread(self):
def test_set_timeout(self):
self.expected = None
self.patch_all()
self.timeout = 10
self.check_client(None, "ping")

calls = [call('socket().settimeout', (10,), {}), ]
self.mock_socket.has_calls(calls)
calls = [call.socket().settimeout(10), ]
self.mock_socket.assert_has_calls(calls)


class BatchClientTest(TestBase):
Expand Down Expand Up @@ -330,6 +333,33 @@ def test_info(self):
self.maxDiff = None
self.check_runner(pyzor.client.InfoClientRunner, response, [result])

def test_info_never(self):
response = """Code: 200
Diag: OK
PV: 2.1
Thread: 8521
Entered: 1400221786
Updated: 1400221794
WL-Entered: -1
WL-Updated: -1
Count: 4
WL-Count: 0
"""
response = email.message_from_string(response,
_class=pyzor.message.Response)
server = "%s:%s" % self.server
result = ("%s\t(200, 'OK')\n"
"\tCount: 4\n"
"\tEntered: %s\n"
"\tUpdated: %s\n"
"\tWL-Count: 0\n"
"\tWL-Entered: Never\n"
"\tWL-Updated: Never\n\n" %
(server, time.ctime(1400221786), time.ctime(1400221794)))
self.maxDiff = None
self.check_runner(pyzor.client.InfoClientRunner, response, [result])


def suite():
"""Gather all the tests from this module in a test suite."""
Expand Down
Loading

0 comments on commit ce6dd09

Please sign in to comment.