<s> from django . contrib . messages import constants <EOL> from django . contrib . messages . storage . base import Message <EOL> from django . contrib . messages . storage . session import SessionStorage <EOL> from django . test import TestCase <EOL> from django . utils . safestring import SafeData , mark_safe <EOL> from . base import BaseTests <EOL> def set_session_data ( storage , messages ) : <EOL> """<STR_LIT>""" <EOL> storage . request . session [ storage . session_key ] = storage . serialize_messages ( messages ) <EOL> if hasattr ( storage , '<STR_LIT>' ) : <EOL> del storage . _loaded_data <EOL> def stored_session_messages_count ( storage ) : <EOL> data = storage . deserialize_messages ( storage . request . session . get ( storage . session_key , [ ] ) ) <EOL> return len ( data ) <EOL> class SessionTest ( BaseTests , TestCase ) : <EOL> storage_class = SessionStorage <EOL> def get_request ( self ) : <EOL> self . session = { } <EOL> request = super ( SessionTest , self ) . get_request ( ) <EOL> request . session = self . session <EOL> return request <EOL> def stored_messages_count ( self , storage , response ) : <EOL> return stored_session_messages_count ( storage ) <EOL> def test_get ( self ) : <EOL> storage = self . storage_class ( self . get_request ( ) ) <EOL> example_messages = [ '<STR_LIT:test>' , '<STR_LIT>' ] <EOL> set_session_data ( storage , example_messages ) <EOL> self . assertEqual ( list ( storage ) , example_messages ) <EOL> def test_safedata ( self ) : <EOL> """<STR_LIT>""" <EOL> storage = self . get_storage ( ) <EOL> message = Message ( constants . DEBUG , mark_safe ( "<STR_LIT>" ) ) <EOL> set_session_data ( storage , [ message ] ) <EOL> self . assertIsInstance ( list ( storage ) [ <NUM_LIT:0> ] . message , SafeData ) </s>
