<s> from django . contrib . messages import constants <EOL> from django . contrib . messages . storage . fallback import ( FallbackStorage , <EOL> CookieStorage ) <EOL> from django . contrib . messages . tests . base import BaseTests <EOL> from django . contrib . messages . tests . test_cookie import ( set_cookie_data , <EOL> stored_cookie_messages_count ) <EOL> from django . contrib . messages . tests . test_session import ( set_session_data , <EOL> stored_session_messages_count ) <EOL> from django . test import TestCase <EOL> class FallbackTest ( BaseTests , TestCase ) : <EOL> storage_class = FallbackStorage <EOL> def get_request ( self ) : <EOL> self . session = { } <EOL> request = super ( FallbackTest , self ) . get_request ( ) <EOL> request . session = self . session <EOL> return request <EOL> def get_cookie_storage ( self , storage ) : <EOL> return storage . storages [ - <NUM_LIT:2> ] <EOL> def get_session_storage ( self , storage ) : <EOL> return storage . storages [ - <NUM_LIT:1> ] <EOL> def stored_cookie_messages_count ( self , storage , response ) : <EOL> return stored_cookie_messages_count ( self . get_cookie_storage ( storage ) , <EOL> response ) <EOL> def stored_session_messages_count ( self , storage , response ) : <EOL> return stored_session_messages_count ( self . get_session_storage ( storage ) ) <EOL> def stored_messages_count ( self , storage , response ) : <EOL> """<STR_LIT>""" <EOL> total = ( self . stored_cookie_messages_count ( storage , response ) + <EOL> self . stored_session_messages_count ( storage , response ) ) <EOL> return total <EOL> def test_get ( self ) : <EOL> request = self . get_request ( ) <EOL> storage = self . storage_class ( request ) <EOL> cookie_storage = self . get_cookie_storage ( storage ) <EOL> example_messages = [ str ( i ) for i in range ( <NUM_LIT:5> ) ] <EOL> set_cookie_data ( cookie_storage , example_messages ) <EOL> self . get_session_storage ( storage ) . _get = None <EOL> self . assertEqual ( list ( storage ) , example_messages ) <EOL> def test_get_empty ( self ) : <EOL> request = self . get_request ( ) <EOL> storage = self . storage_class ( request ) <EOL> self . get_session_storage ( storage ) . _get = None <EOL> self . assertEqual ( list ( storage ) , [ ] ) <EOL> def test_get_fallback ( self ) : <EOL> request = self . get_request ( ) <EOL> storage = self . storage_class ( request ) <EOL> cookie_storage = self . get_cookie_storage ( storage ) <EOL> session_storage = self . get_session_storage ( storage ) <EOL> example_messages = [ str ( i ) for i in range ( <NUM_LIT:5> ) ] <EOL> set_cookie_data ( cookie_storage , example_messages [ : <NUM_LIT:4> ] + <EOL> [ CookieStorage . not_finished ] ) <EOL> set_session_data ( session_storage , example_messages [ <NUM_LIT:4> : ] ) <EOL> self . assertEqual ( list ( storage ) , example_messages ) <EOL> def test_get_fallback_only ( self ) : <EOL> request = self . get_request ( ) <EOL> storage = self . storage_class ( request ) <EOL> cookie_storage = self . get_cookie_storage ( storage ) <EOL> session_storage = self . get_session_storage ( storage ) <EOL> example_messages = [ str ( i ) for i in range ( <NUM_LIT:5> ) ] <EOL> set_cookie_data ( cookie_storage , [ CookieStorage . not_finished ] , <EOL> encode_empty = True ) <EOL> set_session_data ( session_storage , example_messages ) <EOL> self . assertEqual ( list ( storage ) , example_messages ) <EOL> def test_flush_used_backends ( self ) : <EOL> request = self . get_request ( ) <EOL> storage = self . storage_class ( request ) <EOL> cookie_storage = self . get_cookie_storage ( storage ) <EOL> session_storage = self . get_session_storage ( storage ) <EOL> set_cookie_data ( cookie_storage , [ '<STR_LIT>' , CookieStorage . not_finished ] ) <EOL> set_session_data ( session_storage , [ '<STR_LIT>' ] ) <EOL> response = self . get_response ( ) <EOL> list ( storage ) <EOL> storage . update ( response ) <EOL> session_storing = self . stored_session_messages_count ( storage , response ) <EOL> self . assertEqual ( session_storing , <NUM_LIT:0> ) <EOL> def test_no_fallback ( self ) : <EOL> """<STR_LIT>""" <EOL> storage = self . get_storage ( ) <EOL> response = self . get_response ( ) <EOL> self . get_session_storage ( storage ) . _store = None <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> storage . add ( constants . INFO , str ( i ) * <NUM_LIT:100> ) <EOL> storage . update ( response ) <EOL> cookie_storing = self . stored_cookie_messages_count ( storage , response ) <EOL> self . assertEqual ( cookie_storing , <NUM_LIT:5> ) <EOL> session_storing = self . stored_session_messages_count ( storage , response ) <EOL> self . assertEqual ( session_storing , <NUM_LIT:0> ) <EOL> def test_session_fallback ( self ) : <EOL> """<STR_LIT>""" <EOL> storage = self . get_storage ( ) <EOL> response = self . get_response ( ) <EOL> msg_size = int ( ( CookieStorage . max_cookie_size - <NUM_LIT> ) / <NUM_LIT> - <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> storage . add ( constants . INFO , str ( i ) * msg_size ) <EOL> storage . update ( response ) <EOL> cookie_storing = self . stored_cookie_messages_count ( storage , response ) <EOL> self . assertEqual ( cookie_storing , <NUM_LIT:4> ) <EOL> session_storing = self . stored_session_messages_count ( storage , response ) <EOL> self . assertEqual ( session_storing , <NUM_LIT:1> ) <EOL> def test_session_fallback_only ( self ) : <EOL> """<STR_LIT>""" <EOL> storage = self . get_storage ( ) <EOL> response = self . get_response ( ) <EOL> storage . add ( constants . INFO , '<STR_LIT:x>' * <NUM_LIT> ) <EOL> storage . update ( response ) <EOL> cookie_storing = self . stored_cookie_messages_count ( storage , response ) <EOL> self . assertEqual ( cookie_storing , <NUM_LIT:0> ) <EOL> session_storing = self . stored_session_messages_count ( storage , response ) <EOL> self . assertEqual ( session_storing , <NUM_LIT:1> ) </s>
