def test_ignores_audio_callbacks(self): sqa = SqueezeAlexa() sqa.handle( {'request': { 'requestId': '1234', 'type': 'AudioPlayerStarted' }})
def test_handling_all_intents_without_session_or_slots(self): server = Server(transport=(FakeTransport().start())) alexa = SqueezeAlexa(server=server) for name, func in handler._handlers.items(): request = self.request_for({'name': name, 'slots': {}}, NO_SESSION) output = alexa.handle(request, None) self.validate_response(name, output)
def test_classical(self): fake_output = FakeTransport(fake_status=CLASSICAL_STATUS).start() server = Server(transport=fake_output) alexa = SqueezeAlexa(server=server) resp = alexa.now_playing([], None) speech = speech_in(resp) assert '"Kyrie Eleison"' in speech assert "by Johann Sebastian Bach" in speech
def test_multiple_artists(self): fake_output = FakeTransport(fake_status=MULTI_ARTIST_STATUS).start() server = Server(transport=fake_output) alexa = SqueezeAlexa(server=server) resp = alexa.now_playing([], None) speech = speech_in(resp) assert '"Shut \'Em Down"' in speech assert "by Public Enemy and Pete Rock" in speech
def test_commas_in_title(self): fake_output = FakeTransport().start() server = Server(transport=fake_output) alexa = SqueezeAlexa(server=server) resp = alexa.now_playing([], None) speech = speech_in(resp) assert "I Think, I Love" in speech assert "by Jamie Cullum" in speech
def test_handling_all_intents(self): fake_output = FakeTransport() server = Server(transport=fake_output) alexa = SqueezeAlexa(server=server) for name, func in handler._handlers.items(): intent = {'name': name, 'slots': {'Player': {'name': 'Player', 'value': 'fake'}, 'Volume': {'name': 'Volume', 'value': '5'}}} output = alexa.handle(self.request_for(intent, SOME_SESSION)) self.validate_response(name, output)
class GenreTest(TestCase): def setUp(self): self.alexa = SqueezeAlexa(server=None) def get_results(self, *args): return self.alexa._genres_from_slots(args, GENRES) def test_difficult_ands(self): results = self.get_results(['R', 'B']) assert 'R and B' in results def test_dnb(self): results = self.get_results('Drum', 'Base') assert 'Drum n Bass' in results def test_complete_answer(self): results = self.get_results('blues', 'bluegrass') assert results == {'Blues', 'Bluegrass'} def test_complete_answer_overlapping_words(self): results = self.get_results('funk rock') assert results == {'Funk', 'Rock'} def test_hyphenation(self): results = self.get_results('hip-hop') assert results == {'Hip Hop'} def test_exact(self): results = self.get_results('dub') assert results == {'Dub'} results = self.get_results('House') assert results == {'House'}
def lambda_handler(event, context): """ Route the incoming request based on type (LaunchRequest, IntentRequest, etc.) The JSON body of the request is provided in the event parameter. """ sqa = SqueezeAlexa(app_id=APPLICATION_ID) try: return sqa.handle(event, context) except Exception as e: if not settings.USE_SPOKEN_ERRORS: raise e # Work with AWS stack-trace log magic print_w(format_exc().replace('\n', '\r')) error = str(e.msg if hasattr(e, "msg") else e) return speech_response(title=_("All went wrong"), text=_("Oh dear: {type}. {message}").format( type=type(e).__name__, message=error))
def lambda_handler(event, context, server=None): """ Route the incoming request based on type (LaunchRequest, IntentRequest, etc.) The JSON body of the request is provided in the event parameter. """ try: sqa = SqueezeAlexa(server=server or get_server(), app_id=SKILL_SETTINGS.application_id) return sqa.handle(event, context) except Exception as e: if not SKILL_SETTINGS.use_spoken_errors: raise e # Work with AWS stack-trace log magic print(format_exc().replace('\n', '\r')) error = str(e.msg if hasattr(e, "msg") else e) text = _("Oh dear: {type}. {message}").format( type=type(e).__name__, message=error) return speech_response(title=_("All went wrong"), text=text)
def test_all_handler(self): fake_output = FakeTransport() server = Server(transport=fake_output) alexa = SqueezeAlexa(server=server) for name, func in handler._handlers.items(): print_d(">>> Testing %s() <<<" % func.__name__) session = {'sessionId': None} intent = {'requestId': 'abcd', 'slots': {}} raw = func(alexa, intent, session, None) response = raw['response'] assert 'directives' in response or 'outputSpeech' in response assert 'shouldEndSession' in response
def alexa(mock_server): return SqueezeAlexa(server=mock_server)
def setUp(self): self.alexa = SqueezeAlexa(server=None)
def setUp(self): super(IntegrationTests, self).setUp() self.stub = FakeSqueeze() self.alexa = SqueezeAlexa(server=self.stub)
class IntegrationTests(TestCase): def setUp(self): super(IntegrationTests, self).setUp() self.stub = FakeSqueeze() self.alexa = SqueezeAlexa(server=self.stub) def test_on_pause_resume(self): intent = {} self.alexa.on_pause(intent, None) self.alexa.on_resume(intent, None) assert self.stub.lines == [resp('pause 1'), resp('pause 0 1')] def test_on_pause_resume_player_id(self): intent = {} self.alexa.on_pause(intent, None, pid=SOME_PID) self.alexa.on_resume(intent, None, pid=SOME_PID) assert self.stub.lines == [ resp('pause 1', pid=SOME_PID), resp('pause 0 1', pid=SOME_PID) ] def test_on_random_mix_trickier(self): self.stub._genres = GENRES intent = { 'slots': { 'primaryGenre': { 'value': 'Jungle band Blues' }, 'secondaryGenre': { 'value': 'House' } } } response = self.alexa.on_play_random_mix(intent, None) assert self.stub.lines[-1] == resp('play 2') content = response['response']['card']['content'] assert content.startswith('Playing mix of') assert 'Jungle' in content assert 'House' in content # 3 = reset genres, clear, play. 4 = 2 + 2 assert len(self.stub.lines) <= 4 + 3 def test_on_playlist_play_without_playlists(self): intent = one_slot_intent('Playlist', 'Moody Blues') response = self.alexa.on_play_playlist(intent, FAKE_ID) speech = speech_in(response) assert "No Squeezebox playlists" in speech def test_on_playlist_play(self): self.stub._playlists = ['Black Friday', A_PLAYLIST, 'Happy Mondays'] intent = one_slot_intent('Playlist', 'Mood Blues') response = self.alexa.on_play_playlist(intent, FAKE_ID) last_cmd = self.stub.lines[-1] assert last_cmd.startswith( resp('playlist resume %s' % A_PLAYLIST.replace(' ', '%20'))) content = response['response']['card']['content'] assert content.startswith('Playing "%s" playlist' % A_PLAYLIST) assert len(self.stub.lines) <= 4 + 3 def test_set_invalid_volume(self): intent = one_slot_intent('Volume', 11) response = self.alexa.on_set_vol(intent, FAKE_ID) speech = speech_in(response) assert " between 0 and 10" in speech.lower() def test_set_invalid_percent_volume(self): intent = one_slot_intent('Volume', 999) response = self.alexa.on_set_vol_percent(intent, FAKE_ID) speech = speech_in(response) assert " between 0 and 100" in speech.lower()
class IntegrationTests(TestCase): def setUp(self): super(IntegrationTests, self).setUp() self.stub = FakeSqueeze() self.alexa = SqueezeAlexa(server=self.stub) def test_staleness_gets_new_server(self): self.alexa.get_server() assert self.alexa._server self.stub._created_time = time.time() - 100000 # Hack that global squeezealexa.main.SERVER_HOSTNAME = "not.there" with pytest.raises(TransportError) as e: self.alexa.get_server() # *Something* will go wrong, as there's no config and/or no server assert str(e) def test_get_new_server(self): SqueezeAlexa._server = None squeezealexa.main.SERVER_HOSTNAME = "not.there" with pytest.raises(TransportError): self.alexa.get_server() def test_on_pause_resume(self): intent = {} self.alexa.on_pause(intent, None) self.alexa.on_resume(intent, None) assert self.stub.lines == [resp('pause 1'), resp('pause 0 1')] def test_on_pause_resume_player_id(self): intent = {} self.alexa.on_pause(intent, None, pid=SOME_PID) self.alexa.on_resume(intent, None, pid=SOME_PID) assert self.stub.lines == [resp('pause 1', pid=SOME_PID), resp('pause 0 1', pid=SOME_PID)] def test_on_random_mix_trickier(self): self.stub._genres = GENRES intent = {'slots': {'primaryGenre': {'value': 'Jungle band Blues'}, 'secondaryGenre': {'value': 'House'}}} response = self.alexa.on_play_random_mix(intent, None) assert self.stub.lines[-1] == resp('play 2') content = response['response']['card']['content'] assert content.startswith('Playing mix of') assert 'Jungle' in content assert 'House' in content # 3 = reset genres, clear, play. 4 = 2 + 2 assert len(self.stub.lines) <= 4 + 3 def test_on_playlist_play_without_playlists(self): intent = {'slots': {'Playlist': {'name': 'Playlist', 'value': 'Moody Blues'}}} response = self.alexa.on_play_playlist(intent, FAKE_ID) speech = response['response']['outputSpeech']['text'] assert "No Squeezebox playlists" in speech def test_on_playlist_play(self): self.stub._playlists = ['Black Friday', A_PLAYLIST, 'Happy Mondays'] intent = {'slots': {'Playlist': {'name': 'Playlist', 'value': 'Mood Blues'}}} response = self.alexa.on_play_playlist(intent, FAKE_ID) last_cmd = self.stub.lines[-1] assert last_cmd.startswith(resp('playlist resume %s' % A_PLAYLIST.replace(' ', '%20'))) content = response['response']['card']['content'] assert content.startswith('Playing "%s" playlist' % A_PLAYLIST) assert len(self.stub.lines) <= 4 + 3
def lambda_handler(event, context): """ Route the incoming request based on type (LaunchRequest, IntentRequest, etc.) The JSON body of the request is provided in the event parameter. """ sqa = SqueezeAlexa(app_id=APPLICATION_ID) return sqa.handle(event, context)