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_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 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() self.object = StatementObject(text='_') self.model = StatementModel(text='_')
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)