Skip to content

Commit 772077d

Browse files
author
thinwybk
committed
add: unit test for proxy class in proxy.py
1 parent 541af87 commit 772077d

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎test_proxy.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from proxy import Proxy
2+
from io import StringIO
3+
import sys
4+
5+
if sys.version_info < (2, 7):
6+
import unittest2 as unittest
7+
else:
8+
import unittest
9+
10+
class ProxyTest(unittest.TestCase):
11+
12+
@classmethod
13+
def setUpClass(self):
14+
""" Class scope setup. """
15+
self.p = Proxy()
16+
17+
def setUp(self):
18+
""" Function/test case scope setup. """
19+
self.output = StringIO()
20+
self.saved_stdout = sys.stdout
21+
sys.stdout = self.output
22+
23+
def tearDown(self):
24+
""" Function/test case scope teardown. """
25+
self.output.close()
26+
sys.stdout = self.saved_stdout
27+
28+
def test_sales_manager_shall_work_through_proxy(self):
29+
self.p.busy = 'No'
30+
self.p.work()
31+
print_output = self.output.getvalue()
32+
expected_print_output = 'Proxy checking for Sales Manager availability\n\
33+
Sales Manager ready to talk\n'
34+
self.assertEqual(print_output, expected_print_output)
35+
36+
def test_sales_manager_shall_respond_through_proxy(self):
37+
self.p.busy = 'Yes'
38+
self.p.work()
39+
print_output = self.output.getvalue()
40+
expected_print_output = 'Proxy checking for Sales Manager availability\n\
41+
Sales Manager is busy\n'
42+
self.assertEqual(print_output, expected_print_output)
43+
44+
if __name__ == "__main__":
45+
unittest.main()

0 commit comments

Comments
 (0)