Skip to content

Fixes #27 -- Allow the use of REUSE_DB=1. #28

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions django_cassandra_engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,26 @@ def __init__(self, *args, **kwargs):
self.connected = False
self.autocommit = True

self.original_db_name = self.settings_dict['NAME']
self.updated_keyspace = False

del self.connection

def connect(self):
if not self.connected or self.connection is None:
settings = self.settings_dict
self.connection = CassandraConnection(**settings)

# Support django-nose's REUSE_DB flag.
if (self.original_db_name != settings['NAME']
and not self.updated_keyspace):
self.connection.keyspace = self.original_db_name
for models in self.introspection.cql_models.values():
for model in models:
model.__keyspace__ = settings['NAME']
self.connection.keyspace = settings['NAME']
self.updated_keyspace = True

connection_created.send(sender=self.__class__, connection=self)
self.connected = True

Expand Down
2 changes: 2 additions & 0 deletions django_cassandra_engine/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def create_test_db(self, verbosity=1, autoclobber=False, **kwargs):
# Set all models keyspace to the test keyspace
self.set_models_keyspace(test_database_name)

self.connection.connection.keyspace = test_database_name

if verbosity >= 1:
test_db_repr = ''
if verbosity >= 2:
Expand Down