Skip to content
Snippets Groups Projects
Commit cf945c56 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-139: use setup/teardown magic for tmss test database

parent ba5fe98b
No related branches found
No related tags found
1 merge request!96Resolve TMSS-139
......@@ -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)
......
......@@ -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
......
......@@ -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
......
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment