def test_speech_validator_regex_matched():
    """Tests the SpeechValidator using regex"""
    alexa_test = AlexaTest(handler)
    alexa_test.test(
        [
            TestItem(
                LaunchRequestBuilder(skill_settings).build(),
                expected_speech=(r"Salve.+", True),
                expected_repromt=(speechs["launch_repromt"], False),
                check_question=False
            )
        ]
    )
def test_speech_validator_correct():
    """Tests the SpeechValidator with correct speech and repromt"""
    alexa_test = AlexaTest(handler)
    alexa_test.test(
        [
            TestItem(
                LaunchRequestBuilder(skill_settings).build(),
                expected_speech=speechs["launch"],
                expected_repromt=speechs["launch_repromt"],
                check_question=False
            )
        ]
    )
def test_end_session_validator_wrong():
    """Tests the EndSessionValidator when it should alert"""
    alexa_test = AlexaTest(handler)
    with pytest.raises(AssertionError):
        alexa_test.test([
            TestItem(LaunchRequestBuilder(skill_settings).build(),
                     check_question=False,
                     should_end_session=True)
        ])
    with pytest.raises(AssertionError):
        alexa_test.test([
            TestItem(IntentRequestBuilder("DeiIntent", skill_settings).build(),
                     should_end_session=False)
        ])
def test_speech_validator_no_repromt():
    """Tests the SpeechValidator expecting a None reprompt"""
    alexa_test = AlexaTest(handler)
    with pytest.raises(AssertionError):
        alexa_test.test(
            [
                TestItem(
                    LaunchRequestBuilder(skill_settings).build(),
                    expected_speech=speechs["launch"],
                    expected_repromt="",
                    check_question=False
                )
            ]
        )
def test_speech_validator_wrong_speech():
    """Tests the SpeechValidator with wrong speech"""
    alexa_test = AlexaTest(handler)
    with pytest.raises(AssertionError):
        alexa_test.test(
            [
                TestItem(
                    LaunchRequestBuilder(skill_settings).build(),
                    expected_speech="Foo Bar",
                    expected_repromt="Bar",
                    check_question=False
                )
            ]
        )
Esempio n. 6
0
def test_launch_request():
    """Tests the LaunchRequest's speech and repromt output"""
    alexa_test = AlexaTest(handler)
    alexa_test.test([
        _TestItem(
            LaunchRequestBuilder(skill_settings).build(),
            # expected_speech="Welcome to Simple 21. I've shuffled the cards. Say 'Ready' if you want to start or say "
            # "'Explain' to learn about this great game",
            expected_speech=(speach_for_tests.WELCOME, True),
            expected_repromt=
            "Welcome to Simple 21. I've shuffled the cards. Say 'Ready' if you want to start or say "
            "'Explain' to learn about this great game",
            check_question=False,
        )
    ])
def test_end_session_validator_correct():
    """Tests the EndSessionValidator when it should not alert"""
    alexa_test = AlexaTest(handler)
    alexa_test.test([
        TestItem(LaunchRequestBuilder(skill_settings).build(),
                 check_question=False,
                 should_end_session=False)
    ])
    alexa_test.test([
        TestItem(IntentRequestBuilder("DeiIntent", skill_settings).build(),
                 should_end_session=True)
    ])
    alexa_test.test([
        TestItem(SessionEndedRequestBuilder(SessionEndedReason.USER_INITIATED,
                                            skill_settings).build(),
                 should_end_session=True)
    ])
def test_dialog_validator_elicit_slot():
    """Tests the DialogValidator for a slot to be elicited"""
    alexa_test = AlexaTest(handler)
    alexa_test.test([
        TestItem(IntentRequestBuilder("VarusIntent", skill_settings).build(),
                 check_question=False,
                 expected_slot_to_elicit="legiones"),
        TestItem(IntentRequestBuilder(
            "VarusIntent", skill_settings).with_empty_slot("legiones").build(),
                 check_question=False,
                 expected_slot_to_elicit="legiones"),
        TestItem(IntentRequestBuilder("VarusIntent", skill_settings).with_slot(
            "legiones", "3").with_slot_with_resolution_no_match(
                "ballistae", "heus", "ballistaeSlotType").build(),
                 check_question=False,
                 expected_slot_to_elicit="ballistae"),
        TestItem(IntentRequestBuilder("VarusIntent", skill_settings).with_slot(
            "legiones", "2").with_slot("legiones", "3").build(),
                 check_question=False,
                 expected_slot_to_elicit="ballistae")
    ])
    alexa_test.test([
        TestItem(IntentRequestBuilder("VarusIntent", skill_settings).with_slot(
            "legiones", "3").with_slot_with_resolution(
                "ballistae", "magni", "ballistaeSlotType",
                "magnae").with_slot_with_resolution("ballistae", "magnae",
                                                    "ballistaeSlotType",
                                                    "magnae").build(),
                 check_question=False,
                 expected_slot_to_elicit="legati"),
    ])
    with pytest.raises(AssertionError):
        alexa_test.test([
            TestItem(IntentRequestBuilder("VarusIntent",
                                          skill_settings).build(),
                     check_question=False,
                     expected_slot_to_elicit="legati"),
        ])
    with pytest.raises(AssertionError):
        alexa_test.test([
            TestItem(LaunchRequestBuilder(skill_settings).build(),
                     check_question=False,
                     expected_slot_to_elicit="romani"),
        ])