<s> import unittest <EOL> from lib import RecordingsSaver <EOL> from cloudasr . test_doubles import SocketSpy <EOL> from cloudasr . messages . helpers import * <EOL> class TestRecordingsSaver ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . model = RecordingsModelSpy ( ) <EOL> self . socket = SocketSpy ( ) <EOL> self . create_socket = lambda : self . socket <EOL> self . saver = RecordingsSaver ( self . create_socket , self . model , self . socket . has_next_message ) <EOL> def test_saver_saves_recordings_received_via_socket ( self ) : <EOL> self . run_saver ( [ <EOL> createSaverMessage ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , b'<STR_LIT>' , <NUM_LIT> , [ ( <NUM_LIT:1.0> , '<STR_LIT>' ) ] ) . SerializeToString ( ) , <EOL> createSaverMessage ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> , '<STR_LIT>' , b'<STR_LIT>' , <NUM_LIT> , [ ( <NUM_LIT:1.0> , '<STR_LIT>' ) ] ) . SerializeToString ( ) , <EOL> ] ) <EOL> self . assertThatSaverSavedRecordings ( [ <EOL> ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , b'<STR_LIT>' , <NUM_LIT> , [ { '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : '<STR_LIT>' } ] ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> , '<STR_LIT>' , b'<STR_LIT>' , <NUM_LIT> , [ { '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> ] ) <EOL> def run_saver ( self , messages ) : <EOL> self . socket . set_messages ( messages ) <EOL> self . saver . run ( ) <EOL> def assertThatSaverSavedRecordings ( self , recordings ) : <EOL> self . assertEquals ( recordings , self . model . saved_recordings ) <EOL> class RecordingsModelSpy : <EOL> def __init__ ( self ) : <EOL> self . saved_recordings = [ ] <EOL> def save_recording ( self , id , part , chunk_id , model , body , frame_rate , alternatives ) : <EOL> self . saved_recordings . append ( ( id , part , chunk_id , model , body , frame_rate , alternatives ) ) </s>
