Skip to content

Commit

Permalink
add reset_db method
Browse files Browse the repository at this point in the history
  • Loading branch information
DropD committed Sep 26, 2017
1 parent 46e5410 commit 7ab6e35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 0 additions & 2 deletions aiida/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,3 @@ def _get_column(colname, alias):
'\n'.join(alias._sa_class_manager.mapper.c.keys())
)
)


27 changes: 27 additions & 0 deletions aiida/utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class FixtureManager(object):
# ready for testing
# run test 1
fixtures.reset_db()
# database ready for independent test 2
# run test 2
fixtures.destroy_all()
# everything cleaned up
"""
Expand Down Expand Up @@ -109,6 +116,16 @@ def create_profile(self):
aiida_cfg.set_default_profile('daemon', profile_name)
self.__is_running_on_test_profile = True

def reset_db(self):
"""Cleans all data from the database between tests"""
if not self.__is_running_on_test_profile:
raise FixtureError(
'No test profile has been set up yet, can not reset the db')
if self.profile_info['backend'] == 'django':
self.__clean_db_django()
elif self.profile_info['backend'] == 'sqla':
self.__clean_db_sqla()

@property
def profile(self):
"""Profile parameters"""
Expand Down Expand Up @@ -257,6 +274,16 @@ def destroy_all(self):
if self.pg_cluster:
self.pg_cluster.close()

@staticmethod
def __clean_db_django():
from aiida.backends.djsite.db.testbase import DjangoTests
DjangoTests().clean_db()

@staticmethod
def __clean_db_sqla():
from aiida.backends.sqlalchemy.tests.testbase import SqlAlchemyTests
SqlAlchemyTests().clean_db()


@contextmanager
def plugin_fixture():
Expand Down

0 comments on commit 7ab6e35

Please sign in to comment.