Skip to content

Commit a70d878

Browse files
author
thinwybk
committed
add: tests for NoTalkProxy class in proxy.py
1 parent 772077d commit a70d878

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

‎test_proxy.py‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from proxy import Proxy
1+
from proxy import Proxy, NoTalkProxy
22
from io import StringIO
33
import sys
44

@@ -41,5 +41,39 @@ def test_sales_manager_shall_respond_through_proxy(self):
4141
Sales Manager is busy\n'
4242
self.assertEqual(print_output, expected_print_output)
4343

44+
class NoTalkProxyTest(unittest.TestCase):
45+
46+
@classmethod
47+
def setUpClass(self):
48+
""" Class scope setup. """
49+
self.ntp = NoTalkProxy()
50+
51+
def setUp(self):
52+
""" Function/test case scope setup. """
53+
self.output = StringIO()
54+
self.saved_stdout = sys.stdout
55+
sys.stdout = self.output
56+
57+
def tearDown(self):
58+
""" Function/test case scope teardown. """
59+
self.output.close()
60+
sys.stdout = self.saved_stdout
61+
62+
def test_sales_manager_shall_not_work_through_proxy(self):
63+
self.ntp.busy = 'No'
64+
self.ntp.work()
65+
print_output = self.output.getvalue()
66+
expected_print_output = 'Proxy checking for Sales Manager availability\n\
67+
This Sales Manager will not talk to you whether he/she is busy or not\n'
68+
self.assertEqual(print_output, expected_print_output)
69+
70+
def test_sales_manager_shall_not_respond_through_proxy(self):
71+
self.ntp.busy = 'Yes'
72+
self.ntp.work()
73+
print_output = self.output.getvalue()
74+
expected_print_output = 'Proxy checking for Sales Manager availability\n\
75+
This Sales Manager will not talk to you whether he/she is busy or not\n'
76+
self.assertEqual(print_output, expected_print_output)
77+
4478
if __name__ == "__main__":
4579
unittest.main()

0 commit comments

Comments
 (0)