<s> from django . conf import settings <EOL> from django . test import Client <EOL> from django . test . utils import setup_test_environment <EOL> from django . template import Template , Context <EOL> from test_utils . testmaker import processors <EOL> from test_utils . testmaker import serializers <EOL> from test_utils . testmaker import Testmaker <EOL> debug = getattr ( settings , '<STR_LIT>' , False ) <EOL> """<STR_LIT>""" <EOL> if not Testmaker . enabled : <EOL> testmaker = Testmaker ( verbosity = <NUM_LIT:0> ) <EOL> testmaker . prepare ( ) <EOL> SHOW_TESTMAKER_HEADER = getattr ( settings , '<STR_LIT>' , False ) <EOL> RESPONSE_TEMPLATE = Template ( """<STR_LIT>""" ) <EOL> class TestMakerMiddleware ( object ) : <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> serializer_pref = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> processor_pref = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . serializer = serializers . get_serializer ( serializer_pref ) ( ) <EOL> self . processor = processors . get_processor ( processor_pref ) ( ) <EOL> def process_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in request . REQUEST : <EOL> request . logfile = Testmaker . logfile ( ) <EOL> self . serializer . save_request ( request ) <EOL> self . processor . save_request ( request ) <EOL> if request . method . lower ( ) == "<STR_LIT>" : <EOL> setup_test_environment ( ) <EOL> c = Client ( REMOTE_ADDR = '<STR_LIT:127.0.0.1>' ) <EOL> getdict = request . GET . copy ( ) <EOL> getdict [ '<STR_LIT>' ] = '<STR_LIT:yes>' <EOL> response = c . get ( request . path , getdict ) <EOL> self . serializer . save_response ( request , response ) <EOL> self . processor . save_response ( request , response ) <EOL> return None <EOL> def process_response ( self , request , response ) : <EOL> if '<STR_LIT>' not in request . REQUEST and SHOW_TESTMAKER_HEADER : <EOL> c = Context ( { '<STR_LIT:file>' : Testmaker . logfile ( ) } ) <EOL> s = RESPONSE_TEMPLATE . render ( c ) <EOL> response . content = str ( s ) + str ( response . content ) <EOL> return response </s>
