<s> import json <EOL> from django import http <EOL> from django . utils . encoding import force_unicode <EOL> from django . utils . safestring import mark_safe <EOL> from horizon import messages <EOL> from horizon import middleware <EOL> from horizon . test import helpers as test <EOL> class MessageTests ( test . TestCase ) : <EOL> def test_middleware_header ( self ) : <EOL> req = self . request <EOL> string = "<STR_LIT>" <EOL> expected = [ "<STR_LIT:error>" , force_unicode ( string ) , "<STR_LIT>" ] <EOL> self . assertTrue ( "<STR_LIT>" in req . horizon ) <EOL> self . assertItemsEqual ( req . horizon [ '<STR_LIT>' ] , [ ] ) <EOL> req . META [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> messages . error ( req , string ) <EOL> self . assertItemsEqual ( req . horizon [ '<STR_LIT>' ] , [ expected ] ) <EOL> res = http . HttpResponse ( ) <EOL> res = middleware . HorizonMiddleware ( ) . process_response ( req , res ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , <EOL> json . dumps ( [ expected ] ) ) <EOL> def test_safe_message ( self ) : <EOL> req = self . request <EOL> string = mark_safe ( "<STR_LIT>" ) <EOL> expected = [ "<STR_LIT:error>" , force_unicode ( string ) , "<STR_LIT>" ] <EOL> self . assertTrue ( "<STR_LIT>" in req . horizon ) <EOL> self . assertItemsEqual ( req . horizon [ '<STR_LIT>' ] , [ ] ) <EOL> req . META [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> messages . error ( req , string ) <EOL> self . assertItemsEqual ( req . horizon [ '<STR_LIT>' ] , [ expected ] ) <EOL> res = http . HttpResponse ( ) <EOL> res = middleware . HorizonMiddleware ( ) . process_response ( req , res ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , <EOL> json . dumps ( [ expected ] ) ) </s>
