diff --git a/SAS/TMSS/test/CMakeLists.txt b/SAS/TMSS/test/CMakeLists.txt index e89812178a08794777e0d8d89290df8a4b6e2d51..d323c2d52bee09ff9f96cea7eae760aaa24a3980 100644 --- a/SAS/TMSS/test/CMakeLists.txt +++ b/SAS/TMSS/test/CMakeLists.txt @@ -12,6 +12,7 @@ if(BUILD_TESTING) include(PythonInstall) python_install(test_utils.py + tmss_database_unittest_setup.py t_tmssapp_specification_django.py t_tmssapp_scheduling_django.py DESTINATION lofar/sas/tmss/test) diff --git a/SAS/TMSS/test/t_tmssapp_scheduling_django.py b/SAS/TMSS/test/t_tmssapp_scheduling_django.py index b33f42acb8487ec0303a3ddf10c2cddbdcc7200b..9d01c50e5c81779e90773dd6a180914cb8b5a809 100755 --- a/SAS/TMSS/test/t_tmssapp_scheduling_django.py +++ b/SAS/TMSS/test/t_tmssapp_scheduling_django.py @@ -26,17 +26,8 @@ from datetime import datetime # todo: Tags? -> Decide how to deal with them first. # todo: Immutability of Blueprints on db level? - -# before we import any django modules the DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS need to be known/set. -# import and start an isolated TMSSTestDatabaseInstance (with fresh database) -# this automagically sets the required DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS envvars. -from lofar.sas.tmss.test.test_utils import TMSSTestDatabaseInstance -_tmss_test_db_instance = TMSSTestDatabaseInstance() -_tmss_test_db_instance.create() - -# tell unittest to stop (and automagically cleanup) the test database once all testing is done. -def tearDownModule(): - _tmss_test_db_instance.destroy() +# use setup/teardown magic for tmss test database +from lofar.sas.tmss.test.tmss_database_unittest_setup import * # now it's safe to import django modules from lofar.sas.tmss.tmss.tmssapp import models diff --git a/SAS/TMSS/test/t_tmssapp_specification_django.py b/SAS/TMSS/test/t_tmssapp_specification_django.py index 7221f426d5c3012332631e4c630785c0207f4552..caf1c591afdcf51d9dacf418c9afe2ed4b6dd718 100755 --- a/SAS/TMSS/test/t_tmssapp_specification_django.py +++ b/SAS/TMSS/test/t_tmssapp_specification_django.py @@ -26,17 +26,8 @@ import uuid # todo: Tags? -> Decide how to deal with them first. # todo: Immutability of Blueprints on db level? - -# before we import any django modules the DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS need to be known/set. -# import and start an isolated TMSSTestDjangoServerWithPostgresInstance (with fresh database and django server) -# this automagically sets the required DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS envvars. -from lofar.sas.tmss.test.test_utils import TMSSTestDjangoServerWithPostgresInstance -_tmss_test_server = TMSSTestDjangoServerWithPostgresInstance() -_tmss_test_server.start() - -# tell unittest to stop (and automagically cleanup) the test database and django server once all testing is done. -def tearDownModule(): - _tmss_test_server.stop() +# use setup/teardown magic for tmss test database +from lofar.sas.tmss.test.tmss_database_unittest_setup import * # now it's safe to import django modules from lofar.sas.tmss.tmss.tmssapp import models diff --git a/SAS/TMSS/test/tmss_database_unittest_setup.py b/SAS/TMSS/test/tmss_database_unittest_setup.py new file mode 100644 index 0000000000000000000000000000000000000000..1eddd590c1ccbac7e7f1c5d6a260dfc6570ac9eb --- /dev/null +++ b/SAS/TMSS/test/tmss_database_unittest_setup.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2018 ASTRON (Netherlands Institute for Radio Astronomy) +# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# The LOFAR software suite is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. + +''' +By importing this helper module in your unittest module you get a TMSSTestDatabaseInstance +which is automatically destroyed at the end of the unittest session. +''' + +# before we import any django modules the DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS need to be known/set. +# import and start an isolated TMSSTestDatabaseInstance (with fresh database) +# this automagically sets the required DJANGO_SETTINGS_MODULE and TMSS_DBCREDENTIALS envvars. +from lofar.sas.tmss.test.test_utils import TMSSTestDatabaseInstance +_tmss_test_db_instance = TMSSTestDatabaseInstance() +_tmss_test_db_instance.create() + +# tell unittest to stop (and automagically cleanup) the test database once all testing is done. +def tearDownModule(): + _tmss_test_db_instance.destroy()