def test_get_morning_sermon_future(self):
     requested_sermon_date: str = (datetime.now() +
                                   timedelta(7)).date().isoformat()
     service_name: str = "Morning"
     service_id: str = "MORNING"
     service_value: str = "morning"
     event = {
         "session": test_session,
         "version": test_version,
         "request": {
             "locale": "en-GB",
             "timestamp": timestamp_now,
             "dialogState": "STARTED",
             "intent": {
                 "slots": {
                     "Date": {
                         "name": "Date",
                         "source": "USER",
                         "value": requested_sermon_date,
                         "confirmationStatus": "NONE"
                     },
                     "Service": {
                         "source": "USER",
                         "resolutions": {
                             "resolutionsPerAuthority": [{
                                 "status": {
                                     "code": "ER_SUCCESS_MATCH"
                                 },
                                 "values": [{
                                     "value": {
                                         "name": service_name,
                                         "id": service_id
                                     }
                                 }],
                                 "authority":
                                 TEST_AUTHORITY
                             }]
                         },
                         "name": "Service",
                         "value": service_value,
                         "confirmationStatus": "NONE"
                     },
                 },
                 "name": "PlaySermon",
                 "confirmationStatus": "NONE"
             },
             "requestId": TEST_REQUEST_ID,
             "type": "IntentRequest"
         },
         "context": test_context
     }
     response: Dict[str, Any] = alexa_main.lambda_handler(event, {})
     self.assertEqual(response["response"]["outputSpeech"], {
         "type": "PlainText",
         "text": "That service hasn't happened yet! "
     })
     self.assertTrue(response["response"]["shouldEndSession"])
Ejemplo n.º 2
0
    def test_lambda_handler_intent_request(self, on_intent):
        test_request_obj = {
            'requestId': TEST_REQUEST_ID,
            'type': 'IntentRequest'
        }
        test_session_obj = {
            'application': {
                'applicationId': TEST_APPLICATION_ID,
            },
            'new': True
        }
        test_context_obj = {"System": {}, "AudioPlayer": {}}

        test_event = {
            'session': test_session_obj,
            'request': test_request_obj,
            'context': test_context_obj
        }

        alexa_main.lambda_handler(test_event, {})
        on_intent.assert_called_once_with(test_request_obj, test_context_obj)
Ejemplo n.º 3
0
    def test_lambda_handler_throws_error_with_invalid_session_id(
            self, on_launch, on_session_started):
        test_invalid_application_id = "iAmAnInvalidId00000"
        test_session_event_with_invalid_id = {
            'session': {
                'application': {
                    'applicationId': test_invalid_application_id
                },
                'new': False
            },
            'request': {
                'requestId': TEST_REQUEST_ID,
                'type': 'LaunchRequest'
            },
            'context': {}
        }
        test_context_only_event_with_invalid_id = {
            'request': {},
            'context': {
                'System': {
                    'application': {
                        'applicationId': test_invalid_application_id
                    }
                }
            }
        }

        with self.assertRaises(ValueError) as cm_session_event:
            alexa_main.lambda_handler(test_session_event_with_invalid_id, None)
        with self.assertRaises(ValueError) as cm_context_event:
            alexa_main.lambda_handler(test_context_only_event_with_invalid_id,
                                      None)
        self.assertEqual(cm_session_event.exception.message,
                         "Invalid Application ID")
        self.assertEqual(cm_context_event.exception.message,
                         "Invalid Application ID")
        on_session_started.assert_not_called()
        on_launch.assert_not_called()
Ejemplo n.º 4
0
    def test_lambda_handler_on_session_started_launch_request(
            self, on_launch, on_session_started):
        test_session_obj = {
            'application': {
                'applicationId': TEST_APPLICATION_ID
            },
            'new': True
        }

        test_event = {
            'session': test_session_obj,
            'request': {
                'requestId': TEST_REQUEST_ID,
                'type': 'LaunchRequest'
            },
            'context': {}
        }

        alexa_main.lambda_handler(test_event, None)
        on_session_started.assert_called_once_with(
            {
                'requestId': TEST_REQUEST_ID,
            }, test_session_obj)
        on_launch.assert_called_once()
 def test_get_next_event(self):
     event = {
         "session": test_session,
         "version": test_version,
         "request": {
             "locale": "en-GB",
             "timestamp": timestamp_now,
             "dialogState": "STARTED",
             "intent": {
                 "name": "GetNextEvent",
                 "confirmationStatus": "NONE"
             },
             "requestId": TEST_REQUEST_ID,
             "type": "IntentRequest"
         },
         "context": test_context
     }
     response: Dict[str, Any] = alexa_main.lambda_handler(event, {})
     self.assertEqual(response["response"]["outputSpeech"]["type"],
                      "PlainText")
     self.assertEqual(type(response["response"]["outputSpeech"]["text"]),
                      str)
     self.assertTrue(
         bool(
             re.match(
                 r"The next event is .+ on \w+ \d+ \w+ at \d\d?( \d\d)? [AP]M. ",
                 response["response"]["outputSpeech"]["text"])),
         "The speech output is wrong")
     self.assertTrue(response["response"]["shouldEndSession"])
     self.assertTrue(
         bool(
             re.match(r".+ - \d\d:\d\d, \w+ \d\d \w+",
                      response["response"]["card"]["title"])),
         "The card title is wrong")
     self.assertIn(response["response"]["card"]["type"],
                   {"Standard", "Simple"})
     card_text: str = (response["response"]["card"]["content"]
                       if response["response"]["card"]["type"] == "Simple"
                       else response["response"]["card"]["text"])
     self.assertTrue(bool(re.match(r".+\nLocation: .+", card_text)),
                     "The card text is wrong")
    def test_get_bible_passage_coming_sunday_evening_undecided_read(self):
        requested_passage_date: str = (
            datetime.now() +
            timedelta(6 - datetime.now().weekday())).date().isoformat()
        service_name: str = "Evening"
        service_id: str = "EVENING"
        service_value: str = "evening"
        event = {
            "session": test_session,
            "version": test_version,
            "request": {
                "locale": "en-GB",
                "timestamp": timestamp_now,
                "dialogState": "STARTED",
                "intent": {
                    "slots": {
                        "ReadPassage": {
                            "name": "ReadPassage",
                            "confirmationStatus": "NONE"
                        },
                        "Service": {
                            "source": "USER",
                            "resolutions": {
                                "resolutionsPerAuthority": [{
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [{
                                        "value": {
                                            "name": service_name,
                                            "id": service_id
                                        }
                                    }],
                                    "authority":
                                    TEST_AUTHORITY
                                }]
                            },
                            "name": "Service",
                            "value": service_value,
                            "confirmationStatus": "NONE"
                        },
                        "Date": {
                            "name": "Date",
                            "source": "USER",
                            "value": requested_passage_date,
                            "confirmationStatus": "NONE"
                        },
                    },
                    "name": "GetSermonPassage",
                    "confirmationStatus": "NONE"
                },
                "requestId": TEST_REQUEST_ID,
                "type": "IntentRequest"
            },
            "context": test_context
        }
        response: Dict[str, Any] = alexa_main.lambda_handler(event, {})

        self.assertEqual(response["response"]["outputSpeech"]["type"],
                         "PlainText")
        self.assertEqual(type(response["response"]["outputSpeech"]["text"]),
                         str)
        self.assertTrue(
            len(response["response"]["outputSpeech"]["text"]) > 0,
            "No speech for Bible passage request")
        self.assertTrue(
            bool(
                re.match(r"It's.+\. .*Would you like me to read it out\? ",
                         response["response"]["outputSpeech"]["text"])),
            "The speech output is wrong")
        self.assertFalse(response["response"]["shouldEndSession"])
        self.assertEqual(type(response["response"]["directives"]), list)
        self.assertTrue(len(response["response"]["directives"]) > 0)
        self.assertTrue({
            "type": "Dialog.ElicitSlot",
            "slotToElicit": "ReadPassage"
        } in response["response"]["directives"])
        self.assertTrue(
            bool(
                re.match(
                    r"Bible reading for \d+[a-z][a-z] \w+ \d\d\d\d \w+ service",
                    response["response"]["card"]["title"])),
            "The card title is wrong")
        self.assertTrue(
            len(response["response"]["card"]["title"]) +
            len(response["response"]["card"]["content"]) <=
            MAX_CARD_CHARACTERS, "The card is too large")
        self.assertEqual(type(response["response"]["card"]["content"]), str)
        self.assertEqual(type(response["response"]["card"]["title"]), str)
        self.assertEqual(response["response"]["card"]["type"], "Simple")
    def test_get_bible_passage_coming_week_morning_do_not_read(self):
        requested_passage_date: str = (
            datetime.now() +
            timedelta(6 - datetime.now().weekday())).date().isoformat()
        read_passage_name: str = "No"
        read_passage_id: str = "NO"
        read_passage_value: str = "no"
        service_name: str = "Morning"
        service_id: str = "MORNING"
        service_value: str = "morning"
        event = {
            "session": test_session,
            "version": test_version,
            "request": {
                "locale": "en-GB",
                "timestamp": timestamp_now,
                "dialogState": "STARTED",
                "intent": {
                    "slots": {
                        "ReadPassage": {
                            "resolutions": {
                                "resolutionsPerAuthority": [{
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [{
                                        "value": {
                                            "name": read_passage_name,
                                            "id": read_passage_id
                                        }
                                    }],
                                    "authority":
                                    TEST_AUTHORITY
                                }]
                            },
                            "name": "ReadPassage",
                            "value": read_passage_value,
                            "confirmationStatus": "NONE"
                        },
                        "Service": {
                            "source": "USER",
                            "resolutions": {
                                "resolutionsPerAuthority": [{
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [{
                                        "value": {
                                            "name": service_name,
                                            "id": service_id
                                        }
                                    }],
                                    "authority":
                                    TEST_AUTHORITY
                                }]
                            },
                            "name": "Service",
                            "value": service_value,
                            "confirmationStatus": "NONE"
                        },
                        "Date": {
                            "name": "Date",
                            "source": "USER",
                            "value": requested_passage_date,
                            "confirmationStatus": "NONE"
                        },
                    },
                    "name": "GetSermonPassage",
                    "confirmationStatus": "NONE"
                },
                "requestId": TEST_REQUEST_ID,
                "type": "IntentRequest"
            },
            "context": test_context
        }
        response: Dict[str, Any] = alexa_main.lambda_handler(event, {})

        self.assertEqual(response["response"]["outputSpeech"]["type"],
                         "PlainText")
        self.assertEqual(response["response"]["outputSpeech"]["text"], "Okay ")
        self.assertTrue(response["response"]["shouldEndSession"])
    def test_get_evening_sermon_three_weeks_ago(self):
        requested_sermon_date: str = (datetime.now() -
                                      timedelta(21)).date().isoformat()
        service_name: str = "Evening"
        service_id: str = "EVENING"
        service_value: str = "evening"
        event = {
            "session": test_session,
            "version": test_version,
            "request": {
                "locale": "en-GB",
                "timestamp": timestamp_now,
                "dialogState": "STARTED",
                "intent": {
                    "slots": {
                        "Date": {
                            "name": "Date",
                            "source": "USER",
                            "value": requested_sermon_date,
                            "confirmationStatus": "NONE"
                        },
                        "Service": {
                            "source": "USER",
                            "resolutions": {
                                "resolutionsPerAuthority": [{
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [{
                                        "value": {
                                            "name": service_name,
                                            "id": service_id
                                        }
                                    }],
                                    "authority":
                                    TEST_AUTHORITY
                                }]
                            },
                            "name": "Service",
                            "value": service_value,
                            "confirmationStatus": "NONE"
                        },
                    },
                    "name": "PlaySermon",
                    "confirmationStatus": "NONE"
                },
                "requestId": TEST_REQUEST_ID,
                "type": "IntentRequest"
            },
            "context": test_context
        }
        response: Dict[str, Any] = alexa_main.lambda_handler(event, {})

        self.assertEqual(response["response"]["outputSpeech"]["type"],
                         "PlainText")
        self.assertTrue(
            bool(
                re.match(r"Here's the sermon, .+, by .+ ",
                         response["response"]["outputSpeech"]["text"])),
            "The speech output is wrong")
        self.assertEqual(len(response["response"]["directives"]), 1)
        self.assertEqual(response["response"]["directives"][0]["type"],
                         "AudioPlayer.Play")
        self.assertEqual(response["response"]["directives"][0]["playBehavior"],
                         "REPLACE_ALL")
        self.assertTrue(
            bool(
                re.match(
                    r"https://.+\.mp3", response["response"]["directives"][0]
                    ["audioItem"]["stream"]["url"])),
            "The audio stream URL is not an HTTPS URL to an MP3 file")
        self.assertEqual(response["response"]["card"]["type"], "Simple")
        self.assertEqual(type(response["response"]["card"]["title"]), str)
        self.assertEqual(type(response["response"]["card"]["content"]), str)