44from proxy import Proxy , NoTalkProxy
55from io import StringIO
66import sys
7+ from time import time
78
89if sys .version_info < (2 , 7 ):
910 import unittest2 as unittest
@@ -28,21 +29,31 @@ def tearDown(self):
2829 self .output .close ()
2930 sys .stdout = self .saved_stdout
3031
31- def test_sales_manager_shall_work_through_proxy (self ):
32+ def test_sales_manager_shall_work_through_proxy_with_delay (self ):
3233 self .p .busy = 'No'
34+ start_time = time ()
3335 self .p .work ()
36+ end_time = time ()
37+ execution_time = end_time - start_time
3438 print_output = self .output .getvalue ()
3539 expected_print_output = 'Proxy checking for Sales Manager availability\n \
3640 Sales Manager ready to talk\n '
3741 self .assertEqual (print_output , expected_print_output )
42+ expected_execution_time = 2
43+ self .assertEqual (int (execution_time ), expected_execution_time )
3844
39- def test_sales_manager_shall_respond_through_proxy (self ):
45+ def test_sales_manager_shall_respond_through_proxy_with_delay (self ):
4046 self .p .busy = 'Yes'
47+ start_time = time ()
4148 self .p .work ()
49+ end_time = time ()
50+ execution_time = end_time - start_time
4251 print_output = self .output .getvalue ()
4352 expected_print_output = 'Proxy checking for Sales Manager availability\n \
4453 Sales Manager is busy\n '
4554 self .assertEqual (print_output , expected_print_output )
55+ expected_execution_time = 2
56+ self .assertEqual (int (execution_time ), expected_execution_time )
4657
4758class NoTalkProxyTest (unittest .TestCase ):
4859
@@ -62,21 +73,31 @@ def tearDown(self):
6273 self .output .close ()
6374 sys .stdout = self .saved_stdout
6475
65- def test_sales_manager_shall_not_work_through_proxy (self ):
76+ def test_sales_manager_shall_not_work_through_proxy_with_delay (self ):
6677 self .ntp .busy = 'No'
78+ start_time = time ()
6779 self .ntp .work ()
80+ end_time = time ()
81+ execution_time = end_time - start_time
6882 print_output = self .output .getvalue ()
6983 expected_print_output = 'Proxy checking for Sales Manager availability\n \
7084 This Sales Manager will not talk to you whether he/she is busy or not\n '
7185 self .assertEqual (print_output , expected_print_output )
86+ expected_execution_time = 2
87+ self .assertEqual (int (execution_time ), expected_execution_time )
7288
73- def test_sales_manager_shall_not_respond_through_proxy (self ):
89+ def test_sales_manager_shall_not_respond_through_proxy_with_delay (self ):
7490 self .ntp .busy = 'Yes'
91+ start_time = time ()
7592 self .ntp .work ()
93+ end_time = time ()
94+ execution_time = end_time - start_time
7695 print_output = self .output .getvalue ()
7796 expected_print_output = 'Proxy checking for Sales Manager availability\n \
7897 This Sales Manager will not talk to you whether he/she is busy or not\n '
7998 self .assertEqual (print_output , expected_print_output )
99+ expected_execution_time = 2
100+ self .assertEqual (int (execution_time ), expected_execution_time )
80101
81102if __name__ == "__main__" :
82103 unittest .main ()
0 commit comments