diff --git a/SAS/TMSS/test/t_subtask_validation.py b/SAS/TMSS/test/t_subtask_validation.py index be11f874b934fbe8fab89c8928e3835fe98c24ce..0481e80e22b1493e273dc0ebfb3a4202b5c7068f 100755 --- a/SAS/TMSS/test/t_subtask_validation.py +++ b/SAS/TMSS/test/t_subtask_validation.py @@ -27,16 +27,23 @@ import logging logger = logging.getLogger(__name__) logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) -# Do Mandatory setup: -# use setup/teardown magic for tmss test database -# (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_database_unittest_setup module) -from lofar.sas.tmss.test.tmss_database_unittest_setup import * +# Do Mandatory setup step: +# use setup/teardown magic for tmss test database, ldap server and django server +# (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module) +from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import * + from lofar.sas.tmss.test.tmss_test_data_django_models import * +# import and setup rest test data creator +from lofar.sas.tmss.test.tmss_test_data_rest import TMSSRESTTestDataCreator +rest_data_creator = TMSSRESTTestDataCreator(BASE_URL, AUTH) + from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.exceptions import SpecificationException +import requests + class SubtaskValidationTest(unittest.TestCase): @staticmethod def create_subtask_template(schema): diff --git a/SAS/TMSS/test/test_utils.py b/SAS/TMSS/test/test_utils.py index d64d416d2582f599099658dfbbf659ab1820d7f8..6b866ad89eb965aa867bab0efc72b62ec30ee960 100644 --- a/SAS/TMSS/test/test_utils.py +++ b/SAS/TMSS/test/test_utils.py @@ -22,6 +22,7 @@ import os import time from multiprocessing import Process, Event +import django import logging logger = logging.getLogger(__name__) @@ -143,6 +144,14 @@ class TMSSDjangoServerInstance(): ''':returns the temporary LDAP Credentials''' return DBCredentials().get(self._ldap_dbcreds_id) + def setup_django(self): + # (tmss)django is initialized via many environment variables. + # set these here, run django setup, and start the server + os.environ["TMSS_LDAPCREDENTIALS"] = self.ldap_dbcreds_id + os.environ["TMSS_DBCREDENTIALS"] = self.database_dbcreds_id + os.environ["DJANGO_SETTINGS_MODULE"] = "lofar.sas.tmss.tmss.settings" + django.setup() + def start(self): ''' Start the Django server with a test-LDAP server in the background. @@ -152,14 +161,7 @@ class TMSSDjangoServerInstance(): logger.info("Starting Django server at port=%d with database: %s and LDAP: %s", self.port, self.database_dbcreds, self.ldap_dbcreds) - # (tmss)django is initialized via many environment variables. - # set these here, run django setup, and start the server - os.environ["TMSS_LDAPCREDENTIALS"] = self.ldap_dbcreds_id - os.environ["TMSS_DBCREDENTIALS"] = self.database_dbcreds_id - os.environ["DJANGO_SETTINGS_MODULE"] = "lofar.sas.tmss.tmss.settings" - - import django - django.setup() + self.setup_django() django.core.management.call_command('runserver', use_reloader=False, addrport=self.address) @@ -240,6 +242,11 @@ class TMSSTestEnvironment: self.database.create() self.django_server.start() + # apart from the running django server with a REST API, + # it is also convenient to provide a working django setup for the 'normal' django API (via models.objects) + # so: do setup_django + self.django_server.setup_django() + def stop(self): self.django_server.stop() self.ldap_server.stop() @@ -257,6 +264,7 @@ class TMSSTestEnvironment: def __exit__(self, exc_type, exc_val, exc_tb): self.stop() + def main_test_database(): """instantiate, run and destroy a test postgress django database""" os.environ['TZ'] = 'UTC'