예제 #1
0
def test_conv_getnewyearfactintent_valid_year(client):
    """
    User should get a new fact based on a valid year, Amazon
    should keep the session open, and should reprompt user.

    :param client
    """

    # Get some valid years
    facts_str = ' '.join([v for k, v in FACTS.items()])
    years = re.findall(r'\d{4}', facts_str)

    if not years:
        # Grab invalid year(9999) event
        event = json.load(requests.get_new_year_fact())
        # Modify the year value in the json dict
        event['request']['intent']['slots']['FACT_YEAR']['value'] = years[0]

        response = post(client, json.dumps(event))
    else:
        response = post(client, requests.get_new_year_fact())

    assert response['response']['reprompt'],\
        "should have a reprompt available"

    assert not response['response']['shouldEndSession'],\
        "should not end the alexa session"
예제 #2
0
def test_getnewyearfactintent_valid_year(client):
    facts_str = ' '.join([v for k, v in FACTS.items()])
    years = re.findall(r'\d{4}', facts_str)

    if years:
        # Grab invalid year(9999) event
        event = json.load(requests.get_new_year_fact())
        # Modify the year value in the json dict
        event['request']['intent']['slots']['FACT_YEAR']['value'] = years[0]

        response = post(client, json.dumps(event))
    else:
        response = post(client, requests.get_new_year_fact())

    assert response['response'],\
        "should have a speechlet response"

    assert response['response']['outputSpeech'],\
        "should have a spoken response"

    assert response['response']['card'],\
        "should have a card response"

    assert years[0] in response['response']['outputSpeech']['text'],\
        "should have year in the spoken response"
예제 #3
0
def test_conv_getnewfactintent_3(client):
    """
    User should get a new fact, Amazon should keep the session open,
    and should include at least 5 different phrase options to prefix
    the get fact message. Further, the prefix should be randomly
    assigned.

    :param client
    """
    response = post(client, requests.get_new_fact())

    assert response['response']['outputSpeech']['text'],\
        "should have a response"

    RESULTS.append(response['response']['outputSpeech']['text'])

    assert response['response']['shouldEndSession'] is not None,\
        "should not end the alexa session"
    assert not response['response']['shouldEndSession'],\
        "should not end the alexa session"

    assert len(FACT_MSGS) >= 5,\
        "should include at least 5 different phrase options"

    assert get_num_included_phrases(RESULTS, FACT_MSGS),\
        "should randomly include segments from the GET_FACT_MESSAGE templates"
예제 #4
0
def test_getnewyearfactintent_non_matching_year_2(client):
    response = post(client, requests.get_new_year_fact())

    assert response['response']['outputSpeech']['text'],\
        "should receive response"

    RESULTS.append(response['response']['outputSpeech']['text'])
예제 #5
0
def test_get_new_fact_2(client):
    """
    """
    response = post(client, requests.get_new_fact())

    assert response['response']['card'],\
        "should have a card response"

    # add fact to array
    msg = response['response']['outputSpeech']['text']
    RESULTS.append(msg)
예제 #6
0
def test_getnewyearfactintent_non_matching_year_3(client):
    response = post(client, requests.get_new_year_fact())

    assert response['response']['outputSpeech']['text'],\
        "should receive response"

    RESULTS.append(response['response']['outputSpeech']['text'])

    assert len(RESULTS) >= 3,\
        "should ahve run three times"

    assert RESULTS[0] != RESULTS[1] or RESULTS[1] != RESULTS[2],\
        "should have a random spoken sequence"
예제 #7
0
def test_get_new_fact_3(client):
    """
    """
    response = post(client, requests.get_new_fact())

    # add fact to array
    msg = response['response']['outputSpeech']['text']
    RESULTS.append(msg)

    assert len(RESULTS) >= 3,\
        "should have run three times"

    assert RESULTS[0] != RESULTS[1] or RESULTS[1] != RESULTS[2],\
        "should have a random spoken sequence"
예제 #8
0
def test_conv_getnewyearfactintent_non_matching(client):
    """
    User should get a new fact based on a invalid year, Amazon
    should keep the session open, and should reprompt user.

    :param client
    """
    response = post(client, requests.get_new_year_fact())

    assert response['response']['reprompt'],\
        "should have a reprompt available"

    assert not response['response']['shouldEndSession'],\
        "should not end the alexa session"
예제 #9
0
def test_conv_getnewfactintent_1(client):
    """
    User should get a new fact and be reprompted

    :param client
    """
    response = post(client, requests.get_new_fact())

    assert response['response']['outputSpeech']['text'],\
        "should have a response"

    RESULTS.append(response['response']['outputSpeech']['text'])

    assert response['response']['reprompt'],\
        "should have reprompt"
예제 #10
0
def test_stop(client):
    """
    User should be able to stop the interactions according to Amazon

    :param client
    """
    response = post(client, requests.stop())

    assert response['response']['shouldEndSession'],\
        "should end the alexa session"

    assert response['response']['outputSpeech'],\
        "should have a spoken response"

    with pytest.raises(KeyError, message="should have no reprompt"):
        response['response']['reprompt']
예제 #11
0
def test_conv_getnewfactintent_2(client):
    """
    User should get a new fact and Amazon should keep the session open

    :param client
    """
    response = post(client, requests.get_new_fact())

    assert response['response']['outputSpeech']['text'],\
        "should have a response"

    RESULTS.append(response['response']['outputSpeech']['text'])

    assert response['response']['shouldEndSession'] is not None,\
        "should not end the alexa session"
    assert not response['response']['shouldEndSession'],\
        "should not end the alexa session"
예제 #12
0
def test_help(client):
    """
    User should be able to ask for help and also be reprompted

    :param client
    """
    response = post(client, requests.help())

    assert response['response'],\
        "should have a speechlet response"

    assert response['response']['outputSpeech'],\
        "should have a spoken response"

    assert response['response']['reprompt'],\
        "should have a reprompt available"

    assert response['response']['shouldEndSession'] is not None,\
        "should not end the alexa session"
    assert not response['response']['shouldEndSession'],\
        "should not end the alexa session"