Skip to content

Commit

Permalink
Stop numerous sqlite databases from being created
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gunthercox committed May 4, 2017
1 parent 5f556a5 commit dc6db9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chatterbot/storage/sqlalchemy_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 11 additions & 8 deletions tests/storage_adapter_tests/test_sqlalchemy_adapter.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dc6db9f

Please sign in to comment.