def test_docs_context(docs_assist): # adds 'vegetarian' context with docs_assist.app.test_client() as client: payload = build_payload("give-diet", params={"diet": "vegetarian"}) resp = get_query_response(client, payload) context_obj = Context("vegetarian") assert context_obj in docs_assist.context_manager.active next_payload = build_payload("get-food", contexts=resp["outputContexts"]) next_resp = get_query_response(client, next_payload) assert "farmers market" in next_resp["fulfillmentText"] # adds 'carnivore' context with docs_assist.app.test_client() as client: payload = build_payload("give-diet", params={"diet": "carnivore"}) resp = get_query_response(client, payload) context_obj = Context("carnivore") assert context_obj in docs_assist.context_manager.active next_payload = build_payload("get-food", contexts=resp["outputContexts"]) next_resp = get_query_response(client, next_payload) assert "farmers market" not in next_resp["fulfillmentText"] assert "BBQ" in next_resp["fulfillmentText"]
def test_intent_with_context_injects_and_params(assist): client = assist.app.test_client() payload = build_payload("add_context_1") resp = get_query_response(client, payload) payload = build_payload("intent_with_context_injects_params", contexts=resp["outputContexts"], params={ "p1": "blue", "p2": "female" }) resp = get_query_response(client, payload) assert "context_1:TEST INJECTED:blue:female:42" in resp["fulfillmentText"]
def test_add_context_to_manager(context_assist): # with statement allows context locals to be accessed # remains within the actual request to the flask app with context_assist.app.test_client() as client: payload = build_payload('AddContext') resp = get_query_response(client, payload) context_obj = Context('SampleContext') assert context_obj in context_assist.context_manager.active
def test_intent_with_injects_and_2_params(assist): client = assist.app.test_client() payload = build_payload("intent_with_injects_and_2_param", params={ "p1": "blue", "p2": "female" }) resp = get_query_response(client, payload) assert "TEST INJECTED:blue:female:42" in resp["fulfillmentText"]
def test_add_context_to_response(context_assist): client = context_assist.app.test_client() payload = build_payload("AddContext") resp = get_query_response(client, payload) # full_name = f"projects/{context_assist._project_id}/agent/sessions/{context_assist.session_id}/contexts/SampleContext" # context_item = {"lifespanCount": 5, "name": full_name, "parameters": {}} # TODO access context_manager from assist, check for full context name assert "SampleContext" in resp["outputContexts"][0]["name"]
def test_docs_context(docs_assist): # adds 'vegetarian' context with docs_assist.app.test_client() as client: payload = build_payload('give-diet', params={'diet': 'vegetarian'}) resp = get_query_response(client, payload) context_obj = Context('vegetarian') assert context_obj in docs_assist.context_manager.active next_payload = build_payload('get-food', contexts=resp['contextOut']) next_resp = get_query_response(client, next_payload) assert 'farmers market' in next_resp['speech'] # adds 'carnivore' context with docs_assist.app.test_client() as client: payload = build_payload('give-diet', params={'diet': 'carnivore'}) resp = get_query_response(client, payload) context_obj = Context('carnivore') assert context_obj in docs_assist.context_manager.active next_payload = build_payload('get-food', contexts=resp['contextOut']) next_resp = get_query_response(client, next_payload) assert 'farmers market' not in next_resp['speech'] assert 'BBQ' in next_resp['speech']
def test_add_context_to_response(context_assist): client = context_assist.app.test_client() payload = build_payload('AddContext') resp = get_query_response(client, payload) context_item = {'lifespan': 5, 'name': 'SampleContext', 'parameters': {}} assert context_item in resp['contextOut']
def test_hello_world_greeting(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload('greeting') resp = get_query_response(client, payload) assert 'male or female' in resp['speech']
def test_hello_world_give_color(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload('give-color', params={'color': 'blue'}) resp = get_query_response(client, payload) assert 'Ok, blue is an okay' in resp['speech']
def test_hello_world_give_color(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload("give-color", params={"color": "blue"}) resp = get_query_response(client, payload) assert "Ok, blue is an okay" in resp["fulfillmentText"]
def test_simple_intent_with_inject_and_param(assist): client = assist.app.test_client() payload = build_payload("simple_intent_with_inject_and_param", params={"param": "blue"}) resp = get_query_response(client, payload) assert "blue.TEST INJECTED" in resp["fulfillmentText"]
def test_simple_intent_with_injection(assist): client = assist.app.test_client() payload = build_payload("simple_intent_with_inject") resp = get_query_response(client, payload) assert "TEST INJECTED" in resp["fulfillmentText"]
def test_simple_intent(assist): client = assist.app.test_client() payload = build_payload("simple_intent") resp = get_query_response(client, payload) assert "Yes" in resp["fulfillmentText"]
def test_hello_world_greeting(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload("greeting") resp = get_query_response(client, payload) assert "male or female" in resp["fulfillmentText"]
def test_hello_world_give_gender(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload('give-gender', params={'gender': 'male'}) resp = get_query_response(client, payload) assert 'Sup bro' in resp['speech'] assert 'What is your favorite color?' in resp['speech']
def intent_payload(request): return build_payload(intent=request.param)
def test_hello_world_give_gender(hello_world_assist): client = hello_world_assist.app.test_client() payload = build_payload("give-gender", params={"gender": "male"}) resp = get_query_response(client, payload) assert "Sup bro" in resp["fulfillmentText"] assert "What is your favorite color?" in resp["fulfillmentText"]