Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issue with response objects using mongo storage adapter #96

Merged
merged 1 commit into from
Dec 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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