Beispiel #1
0
 def test_prepare_request_empty_slot(self):
     slots = {
         "bot": "demo_bot",
         "http_action_config": "http_action_name",
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     http_action_config_params = [
         HttpActionRequestBody(key="param1", value="value1"),
         HttpActionRequestBody(key="param3",
                               value="",
                               parameter_type="slot")
     ]
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     try:
         ActionUtility.prepare_request(
             tracker=tracker,
             http_action_config_params=http_action_config_params)
         assert False
     except HttpActionFailure as ex:
         assert str(ex) == ("Coudn't find value for key param3 from slot")
Beispiel #2
0
 def test_prepare_request_sender_id(self):
     slots = {
         "bot": "demo_bot",
         "http_action_config": "http_action_name",
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     http_action_config_params = [
         HttpActionRequestBody(key="param1", value="value1"),
         HttpActionRequestBody(key="user_id",
                               value="",
                               parameter_type="sender_id")
     ]
     tracker = Tracker(sender_id="*****@*****.**",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     request_params = ActionUtility.prepare_request(
         tracker=tracker,
         http_action_config_params=http_action_config_params)
     assert request_params['param1'] == "value1"
     assert request_params['user_id'] == "*****@*****.**"
Beispiel #3
0
 def test_prepare_request(self):
     slots = {
         "bot": "demo_bot",
         "http_action_config": "http_action_name",
         "slot_name": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     http_action_config_params = [
         HttpActionRequestBody(key="param1", value="value1"),
         HttpActionRequestBody(key="param2",
                               value="slot_name",
                               parameter_type="slot")
     ]
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     actual_request_body = ActionUtility.prepare_request(
         tracker=tracker,
         http_action_config_params=http_action_config_params)
     assert actual_request_body
     assert actual_request_body['param1'] == 'value1'
     assert actual_request_body['param2'] == 'param2value'
Beispiel #4
0
 def test_prepare_request_no_request_params(self):
     slots = {"bot": "demo_bot", "http_action_config": "http_action_name", "param2": "param2value"}
     events: List[Dict] = None
     http_action_config_params: List[HttpActionRequestBody] = None
     tracker = Tracker(sender_id="sender1", slots=slots, events=events, paused=False, latest_message=None,
                       followup_action=None, active_loop=None, latest_action_name=None)
     actual_request_body = ActionUtility.prepare_request(tracker=tracker,
                                                         http_action_config_params=http_action_config_params)
     #  deepcode ignore C1801: empty request body for http request with no request body params
     assert len(actual_request_body) == 0