Skip to content

Commit

Permalink
Merge pull request #96 from gunthercox/fix_mongo
Browse files Browse the repository at this point in the history
Correct issue with response objects using mongo storage adapter
  • Loading branch information
gunthercox committed Dec 13, 2015
2 parents 1578cf9 + 9b348cc commit 7f3232d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions chatterbot/adapters/storage/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def filter(self, **kwargs):
for match in matches:
statement_text = match['text']
del(match['text'])

response_list = self.deserialize_responses(match["in_response_to"])
match["in_response_to"] = response_list

results.append(Statement(statement_text, **match))

return results
Expand Down
2 changes: 1 addition & 1 deletion tests/storage_adapter_tests/test_jsondb_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_get_random_returns_statement(self):
random_statement = self.adapter.get_random()
self.assertEqual(random_statement.text, statement.text)

def test_find_returns_nested_responces(self):
def test_find_returns_nested_responses(self):
response_list = [
Response("Yes"),
Response("No")
Expand Down
22 changes: 19 additions & 3 deletions tests/storage_adapter_tests/test_mongo_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def tearDown(self):
"""
self.adapter.drop()

class JsonDatabaseAdapterTestCase(BaseMongoDatabaseAdapterTestCase):
class MongoDatabaseAdapterTestCase(BaseMongoDatabaseAdapterTestCase):

def test_count_returns_zero(self):
"""
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_get_random_returns_statement(self):
random_statement = self.adapter.get_random()
self.assertEqual(random_statement.text, statement.text)

def test_find_returns_nested_responces(self):
def test_find_returns_nested_responses(self):
response_list = [
Response("Yes"),
Response("No")
Expand All @@ -123,7 +123,6 @@ def test_find_returns_nested_responces(self):
self.assertIn("Yes", result.in_response_to)
self.assertIn("No", result.in_response_to)


def test_filter_no_results(self):
statement1 = Statement("Testing...")
self.adapter.update(statement1)
Expand Down Expand Up @@ -245,6 +244,23 @@ def test_filter_no_parameters(self):

self.assertEqual(len(results), 2)

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 = Statement(
"The first is to help yourself, the second is to help others.",
in_response_to=[
Response("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]), Response)


class ReadOnlyMongoDatabaseAdapterTestCase(BaseMongoDatabaseAdapterTestCase):

Expand Down

0 comments on commit 7f3232d

Please sign in to comment.