Ejemplo n.º 1
0
 def test_run_invalid_http_action(self):
     slots = {
         "bot": "5f50fd0a56b698ca10d35d2e",
         "http_action_config": "test_run_invalid_http_action",
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     HttpActionConfig(
         auth_token="bearer kjflksjflksajfljsdflinlsufisnflisjbjsdalibvs",
         action_name="test_run_invalid_http_action1",
         response="json",
         http_url="http://www.google.com",
         request_method="GET",
         params_list=None,
         bot="5f50fd0a56b698ca10d35d2e",
         user="******").save()
     dispatcher: CollectingDispatcher = CollectingDispatcher()
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     domain: Dict[Text, Any] = None
     HttpAction().run(dispatcher, tracker, domain)
     str(dispatcher.messages[0]['text']).__contains__(
         "I have failed to process your request: No HTTP action found for bot"
     )
Ejemplo n.º 2
0
 def test_run_no_connection(self):
     slots = {
         "bot": "5f50fd0a56b698ca10d35d2e",
         "http_action_config_test_run": "test_run_with_post"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     dispatcher: CollectingDispatcher = CollectingDispatcher()
     latest_message = {
         'text': 'get intents',
         'intent_ranking': [{
             'name': 'test_run'
         }]
     }
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=latest_message,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     domain: Dict[Text, Any] = None
     HttpActionConfig(auth_token="",
                      action_name="test_run_with_post",
                      response="This should be response",
                      http_url="http://localhost:8080/mock",
                      request_method="GET",
                      params_list=None,
                      bot="5f50fd0a56b698ca10d35d2e",
                      user="******").save()
     actual: List[Dict[Text,
                       Any]] = HttpAction().run(dispatcher, tracker, domain)
     assert actual is not None
     assert str(actual[0]['name']).__contains__(
         'I have failed to process your request')
Ejemplo n.º 3
0
 def test_run_no_http_action(self):
     slots = {
         "bot": "jhgfsjgfausyfgus",
         "http_action_config_http_action": None,
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     dispatcher: CollectingDispatcher = CollectingDispatcher()
     latest_message = {
         'text': 'get intents',
         'intent_ranking': [{
             'name': 'http_action'
         }]
     }
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=latest_message,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     domain: Dict[Text, Any] = None
     actual: List[Dict[Text,
                       Any]] = HttpAction().run(dispatcher, tracker, domain)
     assert actual is not None
     assert actual[0]['name'] is not None
     assert str(
         actual[0]['name']) == 'I have failed to process your request'
Ejemplo n.º 4
0
    def test_run_with_get_placeholder_vs_string_response(self):
        http_url = 'http://localhost:8080/mock'
        resp_msg = "This is string http response"
        responses.add(
            method=responses.GET,
            url=http_url,
            body=resp_msg,
            status=200,
        )

        slots = {"bot": "5f50fd0a56b698ca10d35d2e",
                 "http_action_config": "test_run_with_get_string_http_response_placeholder_required"}
        events = [{"event1": "hello"}, {"event2": "how are you"}]
        dispatcher: CollectingDispatcher = CollectingDispatcher()
        tracker = Tracker(sender_id="sender1", slots=slots, events=events, paused=False, latest_message=None,
                          followup_action=None, active_form=None, latest_action_name=None)
        domain: Dict[Text, Any] = None
        HttpActionConfig(
            auth_token="",
            action_name="test_run_with_get_string_http_response_placeholder_required",
            response="The value of ${a.b.3} in ${a.b.d.0} is ${a.b.d}",
            http_url="http://localhost:8080/mock",
            request_method="GET",
            params_list=None,
            bot="5f50fd0a56b698ca10d35d2e",
            user="******"
        ).save().to_mongo().to_dict()
        actual: List[Dict[Text, Any]] = HttpAction().run(dispatcher, tracker, domain)
        assert actual is not None
        assert str(
            actual[0]['name']) == 'I have failed to process your request: Could not find value for keys in response'
Ejemplo n.º 5
0
    def test_run_with_post(self):
        # request_params = {'data': 'test_data', 'test_class': [{'key': 'value'}, {'key2': 'value2'}]}
        # request_params = [HttpActionRequestBody(key='data', value="test_data"),
        #                   HttpActionRequestBody(key='test_class', value=[{'key': 'value'}, {'key2': 'value2'}])]
        http_url = 'http://localhost:8080/mock'
        resp_msg = "5000"
        responses.add(
            method=responses.POST,
            url=http_url,
            body=resp_msg,
            status=200,
        )

        slots = {"bot": "5f50fd0a56b698ca10d35d2e", "http_action_config": "test_run_with_post"}
        events = [{"event1": "hello"}, {"event2": "how are you"}]
        dispatcher: CollectingDispatcher = CollectingDispatcher()
        tracker = Tracker(sender_id="sender1", slots=slots, events=events, paused=False, latest_message=None,
                          followup_action=None, active_form=None, latest_action_name=None)
        domain: Dict[Text, Any] = None
        HttpActionConfig(
            auth_token="",
            action_name="test_run_with_post",
            response="Data added successfully, id:${RESPONSE}",
            http_url="http://localhost:8080/mock",
            request_method="POST",
            params_list=None,
            bot="5f50fd0a56b698ca10d35d2e",
            user="******"
        ).save().to_mongo().to_dict()
        actual: List[Dict[Text, Any]] = HttpAction().run(dispatcher, tracker, domain)
        assert actual is not None
        assert actual[0]['name'] == 'Data added successfully, id:5000'
Ejemplo n.º 6
0
 def test_run(self):
     slots = {
         "bot": "5f50fd0a56b698ca10d35d2e",
         "http_action_config": "test_run",
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     dispatcher: CollectingDispatcher = CollectingDispatcher()
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     domain: Dict[Text, Any] = None
     HttpActionConfig(
         auth_token="bearer kjflksjflksajfljsdflinlsufisnflisjbjsdalibvs",
         action_name="test_run",
         response="This should be response",
         http_url="http://www.google.com",
         request_method="GET",
         params_list=None,
         bot="5f50fd0a56b698ca10d35d2e",
         user="******").save().to_mongo().to_dict()
     actual: List[Dict[Text,
                       Any]] = HttpAction().run(dispatcher, tracker, domain)
     assert actual is not None
     assert actual[0]['name'] == 'This should be response'
Ejemplo n.º 7
0
 def test_run_no_http_action(self):
     slots = {
         "bot": "jhgfsjgfausyfgus",
         "http_action_config": None,
         "param2": "param2value"
     }
     events = [{"event1": "hello"}, {"event2": "how are you"}]
     dispatcher: CollectingDispatcher = CollectingDispatcher()
     tracker = Tracker(sender_id="sender1",
                       slots=slots,
                       events=events,
                       paused=False,
                       latest_message=None,
                       followup_action=None,
                       active_loop=None,
                       latest_action_name=None)
     domain: Dict[Text, Any] = None
     actual: List[Dict[Text,
                       Any]] = HttpAction().run(dispatcher, tracker, domain)
     assert actual is not None
     assert actual[0]['name'] is not None
     assert isinstance(actual[0]['name'], HttpActionFailure)
     assert str(
         actual[0]['name']
     ) == 'I have failed to process your request: Bot id and HTTP action configuration name not found in slot'
Ejemplo n.º 8
0
    def test_run_with_get(self):
        http_url = 'http://localhost:8080/mock'
        resp_msg = json.dumps({
            "a": {
                "b": {
                    "3": 2,
                    "43": 30,
                    "c": [],
                    "d": ['red', 'buggy', 'bumpers'],
                }
            }
        })
        responses.add(
            method=responses.GET,
            url=http_url,
            body=resp_msg,
            status=200,
        )

        slots = {
            "bot": "5f50fd0a56b698ca10d35d2e",
            "http_action_config_test_run": "test_run_with_post"
        }
        events = [{"event1": "hello"}, {"event2": "how are you"}]
        dispatcher: CollectingDispatcher = CollectingDispatcher()
        latest_message = {
            'text': 'get intents',
            'intent_ranking': [{
                'name': 'test_run'
            }]
        }
        tracker = Tracker(sender_id="sender1",
                          slots=slots,
                          events=events,
                          paused=False,
                          latest_message=latest_message,
                          followup_action=None,
                          active_loop=None,
                          latest_action_name=None)
        domain: Dict[Text, Any] = None
        HttpActionConfig(
            auth_token="",
            action_name="test_run_with_post",
            response="The value of ${a.b.3} in ${a.b.d.0} is ${a.b.d}",
            http_url="http://localhost:8080/mock",
            request_method="GET",
            params_list=None,
            bot="5f50fd0a56b698ca10d35d2e",
            user="******").save().to_mongo().to_dict()
        actual: List[Dict[Text,
                          Any]] = HttpAction().run(dispatcher, tracker, domain)
        assert actual is not None
        assert str(
            actual[0]['name']
        ) == 'The value of 2 in red is [\'red\', \'buggy\', \'bumpers\']'
Ejemplo n.º 9
0
 async def test_name(self):
     assert HttpAction().name() == "kairon_http_action"
Ejemplo n.º 10
0
 def test_name(self):
     assert HttpAction().name() == "http_action"