def test_get_training_examples_with_entities(self): processor = MongoProcessor() results = list(processor.add_training_example( ["Make [TKT456](ticketID) a [critical issue](priority)"], "get_priority", "tests", "testUser", )) assert results[0]['_id'] assert results[0]['text'] == "Make [TKT456](ticketID) a [critical issue](priority)" assert results[0]['message'] == "Training Example added successfully!" actual = list(processor.get_training_examples("get_priority", "tests")) slots = Slots.objects(bot="tests") new_slot = slots.get(name="ticketID") assert any( [value["text"] == "Log a [critical issue](priority)" for value in actual] ) assert any( [ value["text"] == "Make [TKT456](ticketID) a [critical issue](priority)" for value in actual ] ) assert slots.__len__() == 2 assert new_slot.name == "ticketID" assert new_slot.type == "text" expected = ["hey", "hello", "hi", "good morning", "good evening", "hey there"] actual = list(processor.get_training_examples("greet", "tests")) assert actual.__len__() == expected.__len__() assert all(a_val["text"] in expected for a_val in actual)
def test_delete_training_example(self): processor = MongoProcessor() training_examples = list( processor.get_training_examples(intent="get_priority", bot="tests")) expected_length = training_examples.__len__() - 1 training_example = training_examples[0] expected_text = training_example['text'] processor.remove_document(TrainingExamples, training_example['_id'], "tests", "testUser") new_training_examples = list( processor.get_training_examples(intent="get_priority", bot="tests")) assert new_training_examples.__len__() == expected_length assert any(expected_text != example["text"] for example in new_training_examples)
def test_get_training_examples(self): processor = MongoProcessor() expected = [ "hey", "hello", "hi", "good morning", "good evening", "hey there" ] actual = list(processor.get_training_examples("greet", "tests")) assert actual.__len__() == expected.__len__() assert all(a_val["text"] in expected for a_val in actual)
def test_get_training_examples_empty(self): processor = MongoProcessor() actual = list(processor.get_training_examples("greets", "tests")) assert actual.__len__() == 0