def setUp(self): super(DjangoAdapterFilterTestCase, self).setUp() self.statement1 = StatementModel( text="Testing...", in_response_to="Why are you counting?") self.statement2 = StatementModel(text="Testing one, two, three.", in_response_to=self.statement1.text)
def test_update_saves_statement_with_multiple_responses(self): statement = StatementModel.objects.create(text="You are welcome.") statement.add_response(StatementModel(text="Thanks.")) statement.add_response(StatementModel(text="Thank you.")) self.adapter.update(statement) response = self.adapter.find(statement.text) self.assertEqual(response.in_response_to.count(), 2)
def test_find_returns_nested_responses(self): statement = StatementModel.objects.create(text="Do you like this?") statement.add_response(StatementModel(text="Yes")) statement.add_response(StatementModel(text="No")) self.adapter.update(statement) result = self.adapter.find(statement.text) self.assertTrue(result.in_response_to.filter(response__text="Yes").exists()) self.assertTrue(result.in_response_to.filter(response__text="No").exists())
def test_getting_and_updating_statement(self): statement = StatementModel.objects.create(text="Hi") statement.add_response(StatementModel(text="Hello")) statement.add_response(StatementModel(text="Hello")) self.adapter.update(statement) response = self.adapter.find(statement.text) self.assertEqual(response.responses.count(), 1) self.assertEqual(response.responses.first().occurrence, 2)
def test_multiple_responses_added_on_update(self): statement = StatementModel.objects.create(text="You are welcome.") statement.add_response(StatementModel(text="Thank you.")) statement.add_response(StatementModel(text="Thanks.")) self.adapter.update(statement) result = self.adapter.find(statement.text) self.assertEqual(result.in_response_to.count(), 2) self.assertTrue(result.in_response_to.filter(response__text="Thank you.").exists()) self.assertTrue(result.in_response_to.filter(response__text="Thanks.").exists())
def test_filter_equal_results(self): statement1 = StatementModel(text="Testing...") statement2 = StatementModel(text="Testing one, two, three.") self.adapter.update(statement1) self.adapter.update(statement2) results = self.adapter.filter(in_response_to=[]) self.assertEqual(results.count(), 2) self.assertTrue(results.filter(text=statement1.text).exists()) self.assertTrue(results.filter(text=statement2.text).exists())
def test_filter_no_parameters(self): """ If no parameters are passed to the filter, then all statements should be returned. """ statement1 = StatementModel(text="Testing...") statement2 = StatementModel(text="Testing one, two, three.") self.adapter.update(statement1) self.adapter.update(statement2) results = self.adapter.filter() self.assertEqual(len(results), 2)
def test_filter_returns_statement_with_multiple_responses(self): statement = StatementModel.objects.create(text="You are welcome.") statement.add_response(StatementModel(text="Thanks.")) statement.add_response(StatementModel(text="Thank you.")) self.adapter.update(statement) response = self.adapter.filter(in_response_to__contains="Thanks.") # Get the first response response = response.first() self.assertEqual(response.responses.count(), 2)
def test_update_adds_new_statement(self): statement = StatementModel(text="New statement") self.adapter.update(statement) results = self.adapter.filter(text="New statement") self.assertEqual(results.count(), 1) self.assertEqual(results.first().text, statement.text)
def test_count_returns_value(self): """ The count method should return a value of 1 when one item has been saved to the database. """ statement = StatementModel(text="Test statement") self.adapter.update(statement) self.assertEqual(self.adapter.count(), 1)
def test_update_does_not_add_new_statement(self): self.adapter.read_only = True statement = StatementModel(text="New statement") self.adapter.update(statement) statement_found = self.adapter.find("New statement") self.assertEqual(statement_found, None)
def test_remove_response(self): text = "Sometimes you have to run before you can walk." statement = StatementModel.objects.create( text="A test flight is not recommended at this design phase.") statement.add_response(StatementModel(text=text)) self.adapter.remove(statement.text) results = self.adapter.filter(in_response_to__contains=text) self.assertEqual(results.count(), 0)
def setUp(self): super(StatementIntegrationTestCase, self).setUp() from datetime import datetime from pytz import UTC now = datetime(2020, 2, 15, 3, 14, 10, 0, UTC) self.object = StatementObject(text='_', created_at=now) self.model = StatementModel(text='_', created_at=now)
def test_update_does_not_modify_existing_statement(self): statement = StatementModel.objects.create(text="New statement") self.adapter.read_only = True statement.add_response(StatementModel(text="New response")) self.adapter.update(statement) statement_found = self.adapter.find("New statement") self.assertEqual(statement_found.text, statement.text) self.assertEqual(len(statement_found.in_response_to), 0)
def test_get_response_statements(self): """ Test that we are able to get a list of only statements that are known to be in response to another statement. """ s1 = StatementModel(text="What... is your quest?") s2 = StatementModel(text="This is a phone.") s3 = StatementModel(text="A what?") s4 = StatementModel(text="A phone.") s3.add_response(s2) s4.add_response(s3) for statement in [s1, s2, s3, s4]: self.adapter.update(statement) responses = self.adapter.get_response_statements() self.assertEqual(len(responses), 2) self.assertTrue(responses.filter(in_response__response__text="This is a phone.").exists()) self.assertTrue(responses.filter(in_response__response__text="A what?").exists())
def test_get_response_count(self): self.object.add_response(ResponseObject('Hello', occurrence=2)) model_response_statement = StatementModel.objects.create(text='Hello') self.model.save() self.model.in_response.create( statement=self.model, response=model_response_statement, occurrence=2 ) object_count = self.object.get_response_count(StatementObject(text='Hello')) model_count = self.model.get_response_count(StatementModel(text='Hello')) self.assertEqual(object_count, 2) self.assertEqual(model_count, 2)
def setUp(self): super().setUp() from datetime import datetime from pytz import UTC now = datetime(2020, 2, 15, 3, 14, 10, 0, UTC) self.object = StatementObject(text='_', created_at=now) self.model = StatementModel(text='_', created_at=now) # Simulate both statements being saved self.model.save() self.object.id = self.model.id
def test_confidence(self): """ Test that the confidence value is not saved to the database. The confidence attribute on statements is intended to just hold the confidence of the statement when it returned as a response to some input. Because of that, the value of the confidence score should never be stored in the database with the statement. """ statement = StatementModel(text='Test statement') statement.confidence = 0.5 statement.save() statement_updated = StatementModel.objects.get(pk=statement.id) self.assertEqual(statement_updated.confidence, 0)
def test_response_list_in_results(self): """ If a statement with response values is found using the filter method, they should be returned as response objects. """ statement = StatementModel.objects.create( text="The first is to help yourself, the second is to help others.", ) statement.add_response(StatementModel(text="Why do people have two hands?")) self.adapter.update(statement) found = self.adapter.filter(text=statement.text) self.assertEqual(len(found[0].in_response_to), 1) self.assertEqual(type(found[0].in_response_to[0]), ResponseModel)
def setUp(self): super(StatementIntegrationTestCase, self).setUp() date_created = timezone.now() self.object = StatementObject(text='_', created_at=date_created) self.model = StatementModel(text='_', created_at=date_created)
def setUp(self): super(StatementIntegrationTestCase, self).setUp() self.object = StatementObject(text='_') self.model = StatementModel(text='_')