From dc6db9fdf73986df47ab8cfbced8a946ce3d4466 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Wed, 3 May 2017 21:51:24 -0400 Subject: [PATCH] Stop numerous sqlite databases from being created This makes a change so that a new sqlite database isn't created for every test case. There are currently issues with disconnecting from sessions in the beta version of the SQL adapter and these are preventing the test database file from being able to be deleted after the tests have completed. --- chatterbot/storage/sqlalchemy_storage.py | 2 +- .../test_sqlalchemy_adapter.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/chatterbot/storage/sqlalchemy_storage.py b/chatterbot/storage/sqlalchemy_storage.py index df213f2de..a6dfdc6a8 100644 --- a/chatterbot/storage/sqlalchemy_storage.py +++ b/chatterbot/storage/sqlalchemy_storage.py @@ -43,7 +43,7 @@ class ResponseTable(_base): def get_reponse_serialized(context): params = context.current_parameters - del (params['text_search']) + del params['text_search'] return json.dumps(params) id = Column(Integer) diff --git a/tests/storage_adapter_tests/test_sqlalchemy_adapter.py b/tests/storage_adapter_tests/test_sqlalchemy_adapter.py index 3cd781726..825be346f 100644 --- a/tests/storage_adapter_tests/test_sqlalchemy_adapter.py +++ b/tests/storage_adapter_tests/test_sqlalchemy_adapter.py @@ -1,26 +1,28 @@ from unittest import TestCase - from chatterbot.conversation import Statement, Response from chatterbot.storage.sqlalchemy_storage import SQLAlchemyDatabaseAdapter class SQLAlchemyAdapterTestCase(TestCase): + def setUp(self): """ - Instantiate the adapter. + Instantiate the adapter before any tests in the test case run. """ - from random import randint - - # Generate a random name for the database - database_name = str(randint(0, 9000)) - self.adapter = SQLAlchemyDatabaseAdapter( - database='sqlite_' + database_name, + database='testdb', drop_create=True ) + def tearDown(self): + """ + Remove the test database. + """ + self.adapter.drop() + class SQLAlchemyDatabaseAdapterTestCase(SQLAlchemyAdapterTestCase): + def test_count_returns_zero(self): """ The count method should return a value of 0 @@ -334,6 +336,7 @@ def test_response_list_in_results(self): class ReadOnlySQLAlchemyDatabaseAdapterTestCase(SQLAlchemyAdapterTestCase): + def test_update_does_not_add_new_statement(self): self.adapter.read_only = True