<s> import time <EOL> from django . test import TestCase <EOL> from . decorators import enable <EOL> class AfterResponseTest ( TestCase ) : <EOL> def test_execution ( self ) : <EOL> self . executed = <NUM_LIT:0> <EOL> @ enable <EOL> def func ( val ) : <EOL> if val : <EOL> self . executed += <NUM_LIT:1> <EOL> self . assertEqual ( self . executed , <NUM_LIT:0> ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:0> ) <EOL> func . after_response ( True ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:0> ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:1> ) <EOL> func . after_response ( True ) <EOL> func . after_response ( True ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:1> ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:3> ) <EOL> func . after_response ( False ) <EOL> func . after_response ( True ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:3> ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:4> ) <EOL> def test_slow_execution ( self ) : <EOL> self . executed = <NUM_LIT:0> <EOL> @ enable <EOL> def slow_func ( ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> self . executed += <NUM_LIT:1> <EOL> slow_func . after_response ( ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:0> ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( self . executed , <NUM_LIT:0> ) <EOL> slow_func . after_response ( ) <EOL> before_time = time . time ( ) <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> after_time = time . time ( ) <EOL> self . assertTrue ( after_time - before_time < <NUM_LIT:0.5> ) </s>
