<s> from mockito import any , mock , verify , when <EOL> from models . entity import entity , entity_repository <EOL> from config . schema import map_entities <EOL> class entity_repository_spec ( ) : <EOL> map_entities ( ) <EOL> def setup ( self ) : <EOL> self . session = mock ( ) <EOL> self . repository = entity_repository ( self . session ) <EOL> self . msg = entity ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def should_load_instances ( self ) : <EOL> query = mock ( ) <EOL> filtered_query = mock ( ) <EOL> when ( self . session ) . query ( entity ) . thenReturn ( query ) <EOL> when ( query ) . filter ( any ( ) ) . thenReturn ( filtered_query ) <EOL> when ( filtered_query ) . first ( ) . thenReturn ( self . msg ) <EOL> assert self . repository . load ( <NUM_LIT:1> ) == self . msg <EOL> def should_save_instances ( self ) : <EOL> self . repository . save ( self . msg ) <EOL> verify ( self . session ) . add ( self . msg ) <EOL> verify ( self . session ) . commit ( ) <EOL> def should_delete_instances ( self ) : <EOL> self . repository . remove ( self . msg ) <EOL> verify ( self . session ) . delete ( self . msg ) <EOL> verify ( self . session ) . commit ( ) <EOL> def should_list_instances ( self ) : <EOL> query = mock ( ) <EOL> when ( self . session ) . query ( entity ) . thenReturn ( query ) <EOL> when ( query ) . all ( ) . thenReturn ( [ self . msg ] ) <EOL> assert self . repository . list ( ) == [ self . msg ] </s>
