def _load_bot(self, target_dir='.'): project_id = self._get_current_project_id() event = {'sender': {'id': '-1'}, 'channel': 'console'} context = {} nlus = self.api.get_project_nlus(project_id) context['nlu'] = dict([(nlu['nlu'], nlu['credentials']) for nlu in nlus]) channel_client = ConsoleChannelClient() http_storage_client = ExternalHttpStorageClient( self.config.get('auth_token'), project_id, ) storage_client = CachedStorageClient(http_storage_client) nlu_client_factory = NluClientFactory(context) bot_class = get_bot_class(target_dir) bot = bot_class(channel_client=channel_client, storage_client=storage_client, nlu_client_factory=nlu_client_factory, event=event) return { 'bot': bot, 'channel_client': channel_client, 'storage_client': storage_client, 'nlu_client_factory': nlu_client_factory }
def test_get_headers_should_returns_header_dict(): client = ExternalHttpStorageClient('mytoken', 1) assert client.get_headers() == { 'Authorization': 'Bearer mytoken', 'Content-Type': 'application/json' }
def test_get_current_user_data_should_construct_request(): with requests_mock.mock() as m: m.get('https://api.bothub.studio/api/projects/1/user-properties/channels/console/users/1', text='{"data": true}') client = ExternalHttpStorageClient('mytoken', 1) assert client.get_current_user_data() is True
def test_set_user_data_should_construct_request(): with requests_mock.mock() as m: m.post('https://api.bothub.studio/api/projects/1/user-properties/channels/mychannel/users/12345', text='{"data": true}') client = ExternalHttpStorageClient('mytoken', 1) assert client.set_user_data('mychannel', '12345', {'mytoken': 'value'}) is True
def test_set_project_data_should_construct_request(): with requests_mock.mock() as m: m.post('https://api.bothub.studio/api/projects/1/properties', text='{"data": true}') client = ExternalHttpStorageClient('mytoken', 1) assert client.set_project_data({'key': 'value'}) is True