Ejemplo n.º 1
0
from collections import OrderedDict

import climax
import requests

from chatbot import app
from chatbot.configs import load_bot_configs, get_all_bot_configs
from test_utils import TestBase, run_tests
from toolbox import st, json, testcli

load_bot_configs(app.config, load_tests=True)

TEST_BASE_URL = app.config.get('TEST_BASE_URL', 'http://127.0.0.1:9000')


def make_request(bot, input_data, convo_id=None, intent_configs=None):
    data = {
        'debug': 1,
        'bot': bot,
        'channel': 'text',  # TODO: allow testing other channels
        'input': json.dumps(input_data)
    }
    if convo_id:
        data['conversation_id'] = convo_id
    if intent_configs:
        data['bot_config'] = json.dumps({'intent_configs': intent_configs})
    resp = requests.post(TEST_BASE_URL + '/chat', data=data)
    resp.raise_for_status()
    if 'Something went wrong' in resp.text:
        print(resp.json()['error'])
        raise Exception('Something went wrong')
Ejemplo n.º 2
0
import unittest

from chatbot import app
from chatbot.core import (Application, ApplicationVersion,
                          ApplicationTrainingStatus, ApplicationTrainingResult,
                          ApplicationPublishResult, Entity, Intent, Utterance)
from chatbot.configs import load_bot_configs
from chatbot.nlu.luis import LUISNLU
from test_utils import run_tests
from toolbox import testcli, climax

load_bot_configs(app.config)


class TestLUIS(unittest.TestCase):
    def setUp(self):
        self.nlu = LUISNLU(app.config['NLU_CONFIG'])

    def tearDown(self):
        pass

    def testGetApplications(self):
        results = self.nlu.get_applications()
        for x in results:
            self.assertIsInstance(x, Application)

    def testGetApplicationVersions(self):
        results = self.nlu.get_application_versions()
        for x in results:
            self.assertIsInstance(x, ApplicationVersion)