Example #1
0
 def test_get_http_action_no_bot(self):
     try:
         ActionUtility.get_http_action_config(bot=None,
                                              action_name="http_action")
         assert False
     except HttpActionFailure as ex:
         assert str(ex) == "Bot name and action name are required"
Example #2
0
 def test_get_http_action_invalid_db_url(self):
     disconnect()
     try:
         ActionUtility.get_http_action_config("mongodb://localhost:8000/test", "bot", "http_action")
         assert False
     except HttpActionFailure:
         assert True
Example #3
0
 def test_get_http_action_no_http_action(self):
     try:
         ActionUtility.get_http_action_config(db_url=pytest.db_url,
                                              bot="bot",
                                              action_name=None)
         assert False
     except HttpActionFailure as ex:
         assert str(
             ex) == "Database url, bot name and action name are required"
Example #4
0
    def test_get_http_action_config(self):
        http_params = [HttpActionRequestBody(key="key1", value="value1", parameter_type="slot"),
                       HttpActionRequestBody(key="key2", value="value2")]
        expected = HttpActionConfig(
            auth_token="bearer kjflksjflksajfljsdflinlsufisnflisjbjsdalibvs",
            action_name="http_action",
            response="json",
            http_url="http://test.com",
            request_method="GET",
            params_list=http_params,
            bot="bot",
            user="******"
        ).save().to_mongo().to_dict()

        actual = ActionUtility.get_http_action_config("bot", "http_action")
        assert actual is not None
        assert expected['auth_token'] == actual['auth_token']
        assert expected['action_name'] == actual['action_name']
        assert expected['response'] == actual['response']
        assert expected['http_url'] == actual['http_url']
        assert expected['request_method'] == actual['request_method']
        assert expected['params_list'] is not None
        assert expected['params_list'][0]['key'] == actual['params_list'][0]['key']
        assert expected['params_list'][0]['value'] == actual['params_list'][0]['value']
        assert expected['params_list'][0]['parameter_type'] == actual['params_list'][0]['parameter_type']
        assert expected['params_list'][1]['key'] == actual['params_list'][1]['key']
        assert expected['params_list'][1]['value'] == actual['params_list'][1]['value']
        assert expected['params_list'][1]['parameter_type'] == actual['params_list'][1]['parameter_type']
        assert actual['status']
Example #5
0
    def test_get_http_action_no_request_body(self):
        http_params = []
        HttpActionConfig(
            auth_token="bearer kjflksjflksajfljsdflinlsufisnflisjbjsdalibvs",
            action_name="http_action",
            response="json",
            http_url="http://test.com",
            request_method="GET",
            params_list=http_params,
            bot="bot",
            user="******").save().to_mongo().to_dict()

        try:
            ActionUtility.get_http_action_config("bot", "http_action1")
            assert False
        except HttpActionFailure as ex:
            assert str(ex).__contains__("No HTTP action found for bot")
Example #6
0
    def test_get_http_action_invalid_http_action(self):
        http_params = [HttpActionRequestBody(key="key1", value="value1", parameter_type="slot"),
                       HttpActionRequestBody(key="key2", value="value2")]
        HttpActionConfig(
            auth_token="bearer kjflksjflksajfljsdflinlsufisnflisjbjsdalibvs",
            action_name="http_action",
            response="json",
            http_url="http://test.com",
            request_method="GET",
            params_list=http_params,
            bot="bot",
            user="******"
        ).save().to_mongo().to_dict()

        try:
            ActionUtility.get_http_action_config(pytest.db_url, "bot", "http_action1")
            assert False
        except HttpActionFailure as ex:
            assert str(ex).__contains__("No HTTP action found for bot")