Exemplo n.º 1
0
 def test_get_training_examples_with_entities(self):
     processor = MongoProcessor()
     processor.add_training_example(
         "Make [TKT456](ticketID) a [critical issue](priority)",
         "get_priority",
         "tests",
         "testUser",
     )
     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)
Exemplo n.º 2
0
 def test_add_empty_training_example(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         results = list(processor.add_training_example([""], None, "tests", "testUser"))
         assert results[0]['_id'] is None
         assert results[0]['text'] == "Hi! How are you"
         assert results[0]['message'] == "Training Example name and text cannot be empty or blank spaces"
Exemplo n.º 3
0
 def test_add_training_example_with_entity(self):
     processor = MongoProcessor()
     processor.add_training_example("Log a [critical issue](priority)",
                                    "get_priority", "tests", "testUser")
     new_intent = Intents.objects(bot="tests").get(name="get_priority")
     new_entity = Entities.objects(bot="tests").get(name="priority")
     new_training_example = TrainingExamples.objects(bot="tests").get(
         text="Log a critical issue")
     slots = Slots.objects(bot="tests")
     new_slot = slots.get(name="priority")
     assert new_intent.name == "get_priority"
     assert new_entity.name == "priority"
     assert slots.__len__() == 1
     assert new_slot.name == "priority"
     assert new_slot.type == "text"
     assert new_training_example.text == "Log a critical issue"
Exemplo n.º 4
0
 def test_add_same_training_example(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example(["Hi"], "greeting", "tests",
                                        "testUser"))
     assert results[0]['_id'] is None
     assert results[0]['text'] == "Hi"
     assert results[0]['message'] == "Training Example already exists!"
Exemplo n.º 5
0
 def test_add_training_example(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example(["Hi"], "greeting", "tests",
                                        "testUser"))
     assert results[0]['_id']
     assert results[0]['text'] == "Hi"
     assert results[0]['message'] == "Training Example added successfully!"
Exemplo n.º 6
0
 def test_add_training_example(self):
     processor = MongoProcessor()
     assert processor.add_training_example("Hi", "greeting", "tests",
                                           "testUser")
     training_example = TrainingExamples.objects(bot="tests").get(
         intent="greeting", text="Hi")
     assert training_example.intent == "greeting"
     assert training_example.text == "Hi"
Exemplo n.º 7
0
 def test_add_training_example_duplicate_case_insensitive(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example(["hi"], "greeting", "tests",
                                        "testUser"))
     assert results[0]["_id"] is None
     assert results[0]["text"] == "hi"
     assert results[0]["message"] == "Training Example already exists!"
Exemplo n.º 8
0
 def test_add_training_example_blank_text(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example(["  "], "greeting", "tests",
                                        "testUser"))
     assert results[0]['_id'] is None
     assert results[0]['text'] == "  "
     assert results[0][
         'message'] == "Training Example name and text cannot be empty or blank spaces"
Exemplo n.º 9
0
 def test_add_training_example(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example(["Hi, How are you?"], "greeting",
                                        "tests", "testUser"))
     print(results)
     assert results[0]["_id"]
     assert results[0]["text"] == "Hi, How are you?"
     assert results[0]["message"] == "Training Example added successfully!"
Exemplo n.º 10
0
 def test_add_training_example_none_text(self):
     processor = MongoProcessor()
     results = list(
         processor.add_training_example([None], "greeting", "tests",
                                        "testUser"))
     assert results[0]["_id"] is None
     assert results[0]["text"] is None
     assert (
         results[0]["message"] ==
         "Training Example name and text cannot be empty or blank spaces")
Exemplo n.º 11
0
 def test_add_training_example_blank_intent(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         results = list(
             processor.add_training_example(["Hi! How are you"], "  ",
                                            "tests", "testUser"))
         assert results[0]["_id"] is None
         assert results[0]["text"] == "Hi! How are you"
         assert (
             results[0]["message"] ==
             "Training Example name and text cannot be empty or blank spaces"
         )
Exemplo n.º 12
0
 def test_add_training_example_with_entity(self):
     processor = MongoProcessor()
     results = list(processor.add_training_example(
         ["Log a [critical issue](priority)"], "get_priority", "tests", "testUser"
     ))
     assert results[0]['_id']
     assert results[0]['text'] == "Log a [critical issue](priority)"
     assert results[0]['message'] == "Training Example added successfully!"
     intents = processor.get_intents("tests")
     assert any("get_priority" == intent['name'] for intent in intents)
     entities = processor.get_entities("tests")
     assert any("priority" == entity['name'] for entity in entities)
     new_training_example = TrainingExamples.objects(bot="tests").get(
         text="Log a critical issue"
     )
     slots = Slots.objects(bot="tests")
     new_slot = slots.get(name="priority")
     assert slots.__len__() == 1
     assert new_slot.name == "priority"
     assert new_slot.type == "text"
     assert new_training_example.text == "Log a critical issue"
Exemplo n.º 13
0
 def test_add_empty_training_example(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("", None, "tests", "testUser")
Exemplo n.º 14
0
 def test_add_training_example_blank_intent(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("Hi! How are you", "  ", "tests",
                                        "testUser")
Exemplo n.º 15
0
 def test_add_training_example_blank_text(self):
     processor = MongoProcessor()
     with pytest.raises(ValidationError):
         processor.add_training_example("  ", "greeting", "tests",
                                        "testUser")
Exemplo n.º 16
0
 def test_add_same_training_example(self):
     processor = MongoProcessor()
     with pytest.raises(Exception):
         processor.add_training_example("Hi", "greeting", "tests",
                                        "testUser")