def test_nlg_fill_response_text_and_custom(text_slot_name, text_slot_value, cust_slot_name, cust_slot_value): response = { "text": f"{{{text_slot_name}}}", "custom": { "field": f"{{{cust_slot_name}}}", "properties": { "field_prefixed": f"prefix_{{{cust_slot_name}}}" }, }, } t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response( response=response, filled_slots={ text_slot_name: text_slot_value, cust_slot_name: cust_slot_value }, ) assert result == { "text": str(text_slot_value), "custom": { "field": str(cust_slot_value), "properties": { "field_prefixed": f"prefix_{str(cust_slot_value)}" }, }, }
def test_nlg_fill_response_custom(slot_name: Text, slot_value: Any): response = { "custom": { "field": f"{{{slot_name}}}", "properties": { "field_prefixed": f"prefix_{{{slot_name}}}" }, "bool_field": True, "int_field:": 42, "empty_field": None, } } t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response=response, filled_slots={slot_name: slot_value}) assert result == { "custom": { "field": str(slot_value), "properties": { "field_prefixed": f"prefix_{slot_value}" }, "bool_field": True, "int_field:": 42, "empty_field": None, } }
def test_nlg_fill_response_quick_replies(quick_replies_slot_name, quick_replies_slot_value): response = {"quick_replies": f"{{{quick_replies_slot_name}}}"} t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response( response=response, filled_slots={quick_replies_slot_name: quick_replies_slot_value}, ) assert result == {"quick_replies": str(quick_replies_slot_value)}
def test_nlg_fill_response_text_with_json(response_text, expected): response = {"text": response_text} t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response=response, filled_slots={ "slot_1": "foo", "slot_2": "bar" }) assert result == {"text": expected}
def test_nlg_fill_response_button(button_slot_name, button_slot_value): response = { "buttons": [{ "payload": f'/choose{{{{"some_slot": "{{{button_slot_name}}}"}}}}', "title": f"{{{button_slot_name}}}", }] } t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response( response=response, filled_slots={button_slot_name: button_slot_value}) assert result == { "buttons": [{ "payload": f'/choose{{"some_slot": "{button_slot_value}"}}', "title": f"{button_slot_value}", }] }
def test_nlg_fill_response_image_and_text(text_slot_name, text_slot_value, img_slot_name, img_slot_value): response = { "text": f"{{{text_slot_name}}}", "image": f"{{{img_slot_name}}}" } t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response( response=response, filled_slots={ text_slot_name: text_slot_value, img_slot_name: img_slot_value }, ) assert result == { "text": str(text_slot_value), "image": str(img_slot_value) }
def test_nlg_fill_response_custom_with_list(): response = { "custom": { "blocks": [{ "fields": [{ "text": "*Departure date:*\n{test}" }] }], "other": ["{test}"], } } t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response=response, filled_slots={"test": 5}) assert result == { "custom": { "blocks": [{ "fields": [{ "text": "*Departure date:*\n5" }] }], "other": ["5"], } }
def test_nlg_fill_response_attachment(attach_slot_name, attach_slot_value): response = {"attachment": "{" + attach_slot_name + "}"} t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response( response=response, filled_slots={attach_slot_name: attach_slot_value}) assert result == {"attachment": str(attach_slot_value)}
def test_nlg_fill_response_with_bad_slot_name(slot_name, slot_value): response_text = f"{{{slot_name}}}" t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response={"text": response_text}, filled_slots={slot_name: slot_value}) assert result["text"] == response_text
def test_nlg_fill_response_image(img_slot_name: Text, img_slot_value: Text): response = {"image": f"{{{img_slot_name}}}"} t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response=response, filled_slots={img_slot_name: img_slot_value}) assert result == {"image": str(img_slot_value)}
def test_nlg_fill_response_text(slot_name: Text, slot_value: Any): response = {"text": f"{{{slot_name}}}"} t = TemplatedNaturalLanguageGenerator(responses=dict()) result = t._fill_response(response=response, filled_slots={slot_name: slot_value}) assert result == {"text": str(slot_value)}