async def test_trigger_data_importer_rules_only(self, monkeypatch, get_training_data): bot = 'test_trigger_data_importer_rules_only' user = '******' test_data_path = os.path.join(pytest.tmp_dir, str(datetime.utcnow())) data_path = os.path.join(test_data_path, 'data') Utility.make_dirs(data_path) shutil.copy2('tests/testing_data/validator/valid/data/rules.yml', data_path) nlu, story_graph, domain, config, http_actions = await get_training_data( 'tests/testing_data/validator/valid') mongo_processor = MongoProcessor() mongo_processor.save_domain(domain, bot, user) mongo_processor.save_nlu(nlu, bot, user) config["bot"] = bot config["user"] = user config_obj = Configs._from_son(config) config_obj.save() mongo_processor.save_stories(story_graph.story_steps, bot, user) mongo_processor.save_http_action(http_actions, bot, user) def _path(*args, **kwargs): return test_data_path monkeypatch.setattr(Utility, "get_latest_file", _path) DataImporterLogProcessor.add_log(bot, user, files_received=["rules"]) await EventsTrigger.trigger_data_importer(bot, user, True, False) logs = list(DataImporterLogProcessor.get_logs(bot)) assert len(logs) == 1 assert not logs[0].get('intents').get('data') assert not logs[0].get('stories').get('data') assert not logs[0].get('utterances').get('data') assert not logs[0].get('http_actions').get('data') assert not logs[0].get('training_examples').get('data') assert not logs[0].get('domain').get('data') assert not logs[0].get('config').get('data') assert not logs[0].get('exception') assert logs[0]['is_data_uploaded'] assert logs[0]['start_timestamp'] assert logs[0]['end_timestamp'] assert logs[0]['status'] == 'Success' assert logs[0]['event_status'] == EVENT_STATUS.COMPLETED.value assert len(mongo_processor.fetch_stories(bot)) == 2 assert len(list(mongo_processor.fetch_training_examples(bot))) == 7 assert len(list(mongo_processor.fetch_responses(bot))) == 2 assert len(mongo_processor.fetch_actions(bot)) == 2 assert len(mongo_processor.fetch_rule_block_names(bot)) == 3
def test_add_bot_for_existing_user(self): bot_response = AccountProcessor.add_bot("test_version_2", pytest.account, "*****@*****.**", False) bot = Bot.objects(name="test_version_2").get().to_mongo().to_dict() assert bot['_id'].__str__() == bot_response['_id'].__str__() user = User.objects(email="*****@*****.**").get() assert len(user.bot) == 2 config = Configs.objects( bot=bot['_id'].__str__()).get().to_mongo().to_dict() assert config['language'] assert config['pipeline'][6]['name'] == 'FallbackClassifier' assert config['pipeline'][6]['threshold'] == 0.7 assert config['policies'][2]['name'] == 'RulePolicy' assert config['policies'][2][ 'core_fallback_action_name'] == "action_default_fallback" assert config['policies'][2]['core_fallback_threshold'] == 0.3 assert Rules.objects(bot=bot['_id'].__str__()).get() assert Responses.objects(name='utter_default', bot=bot['_id'].__str__(), status=True).get()
def test_add_bot(self): bot_response = AccountProcessor.add_bot("test", pytest.account, "*****@*****.**", True) bot = Bot.objects(name="test").get().to_mongo().to_dict() assert bot['_id'].__str__() == bot_response['_id'].__str__() config = Configs.objects( bot=bot['_id'].__str__()).get().to_mongo().to_dict() assert config['language'] assert config['pipeline'][6]['name'] == 'FallbackClassifier' assert config['pipeline'][6]['threshold'] == 0.7 assert config['policies'][2]['name'] == 'RulePolicy' assert config['policies'][2][ 'core_fallback_action_name'] == "action_default_fallback" assert config['policies'][2]['core_fallback_threshold'] == 0.3 assert Rules.objects(bot=bot['_id'].__str__()).get() assert Responses.objects(name__iexact='utter_please_rephrase', bot=bot['_id'].__str__(), status=True).get() assert Responses.objects(name='utter_default', bot=bot['_id'].__str__(), status=True).get() pytest.bot = bot_response['_id'].__str__()