def test_send_audio_file( manager, audio_file, device_state, authentication_headers ): manager.create_connection() manager.mock_response(status_code=200) with patch.object(manager, 'parse_response'): # test request only manager.send_audio_file( device_state=device_state, authentication_headers=authentication_headers, audio_file=audio_file, dialog_request_id='dialogue-id', ) headers = dict(list(manager.connection.recent_stream.headers.items())) assert headers == { b':method': b'POST', b':scheme': b'https', b':authority': b'avs-alexa-eu.amazon.com', b':path': b'/v20160207/events', b'content-type': b'multipart/form-data; boundary=boundary', b'auth': b'value', } parsed = parse_multipart( body=manager.connection._sock.queue[1], content_type=headers[b'content-type'].decode(), ) assert parsed.parts[0].headers == { b'Content-Type': b'application/json;', b'Content-Disposition': ( b'form-data; name="request"; filename="request"' ) } assert json.loads(parsed.parts[0].content.decode()) == { 'context': device_state, 'event': { 'payload': { 'profile': 'CLOSE_TALK', 'format': 'AUDIO_L16_RATE_16000_CHANNELS_1' }, 'header': { 'namespace': 'SpeechRecognizer', 'dialogRequestId': 'dialogue-id', 'name': 'Recognize', 'messageId': 'message-id' } }, } assert parsed.parts[1].headers == { b'Content-Type': b'application/octet-stream', b'Content-Disposition': b'form-data; name="audio"; filename="audio"' } assert parsed.parts[1].content == b'things'
def test_synchronise_device_state( status, manager, authentication_headers, device_state ): manager.create_connection() manager.mock_response(status_code=status) manager.synchronise_device_state( authentication_headers=authentication_headers, device_state=device_state, ) headers = dict(list(manager.connection.recent_stream.headers.items())) assert headers == { b':method': b'GET', b':scheme': b'https', b':authority': b'avs-alexa-eu.amazon.com', b':path': b'/v20160207/events', b'content-type': b'multipart/form-data; boundary=boundary', b'auth': b'value', } parsed = parse_multipart( body=manager.connection._sock.queue[1], content_type=headers[b'content-type'].decode(), ) assert parsed.parts[0].headers == { b'Content-Disposition': ( b'form-data; name="metadata"; filename="metadata"' ), b'Content-Type': b'application/json' } assert json.loads(parsed.parts[0].content.decode()) == { 'context': device_state, 'event': { 'header': { 'messageId': '', 'name': 'SynchronizeState', 'namespace': 'System' }, 'payload': {} }, }