From e629865a5b23d6505310b225ac6cdeb0c728091f Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 4 Aug 2020 15:40:44 +0200 Subject: [PATCH] TMSS-287: more elegant solution for populating test data --- SAS/TMSS/src/remakemigrations.py | 3 +-- SAS/TMSS/src/tmss/tmssapp/populate.py | 4 ++-- SAS/TMSS/test/test_utils.py | 4 ++++ SAS/TMSS/test/tmss_database_unittest_setup.py | 4 ---- SAS/TMSS/test/tmss_test_environment_unittest_setup.py | 4 ---- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/SAS/TMSS/src/remakemigrations.py b/SAS/TMSS/src/remakemigrations.py index 397b52ac237..ed3475278af 100755 --- a/SAS/TMSS/src/remakemigrations.py +++ b/SAS/TMSS/src/remakemigrations.py @@ -81,8 +81,7 @@ class Migration(migrations.Migration): migrations.RunPython(populate_lofar_json_schemas), migrations.RunPython(populate_resources), migrations.RunPython(populate_cycles), - migrations.RunPython(populate_projects), - migrations.RunPython(populate_test_scheduling_set) ] + migrations.RunPython(populate_projects) ] """ diff --git a/SAS/TMSS/src/tmss/tmssapp/populate.py b/SAS/TMSS/src/tmss/tmssapp/populate.py index 65d405c019b..c2ebe1653ce 100644 --- a/SAS/TMSS/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/src/tmss/tmssapp/populate.py @@ -63,7 +63,7 @@ def populate_lofar_json_schemas(apps, schema_editor): _populate_qa_plots_subtask_template() -def populate_test_scheduling_set(apps, schema_editor): +def populate_test_data(): """ Create a Test Schedule Set to be able to refer to when Scheduling Unit Draft is created from a scheduling unit json @@ -71,7 +71,7 @@ def populate_test_scheduling_set(apps, schema_editor): """ try: # only add (with expensive setup time) example data when developing/testing and we're not unittesting - if (isTestEnvironment() or isDevelopmentEnvironment()) and not os.environ.get('TMSS_UNIT_TESTING')==str(True): + if isTestEnvironment() or isDevelopmentEnvironment(): from lofar.sas.tmss.tmss.exceptions import TMSSException from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, SchedulingUnitDraft_test_data from lofar.sas.tmss.tmss.tmssapp.tasks import create_task_blueprints_and_subtasks_from_scheduling_unit_draft, create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_unit_draft diff --git a/SAS/TMSS/test/test_utils.py b/SAS/TMSS/test/test_utils.py index 09464d4701a..5f515a7c97a 100644 --- a/SAS/TMSS/test/test_utils.py +++ b/SAS/TMSS/test/test_utils.py @@ -352,6 +352,10 @@ def main_test_environment(): with RATestEnvironment(exchange=options.exchange, broker=options.broker): with TMSSTestEnvironment(host=options.host, preferred_django_port=options.port, exchange=options.exchange, broker=options.broker) as instance: + + from lofar.sas.tmss.tmss.tmssapp.populate import populate_test_data + populate_test_data() + # print some nice info for the user to use the test servers... # use print instead of log for clean lines. for h in logging.root.handlers: diff --git a/SAS/TMSS/test/tmss_database_unittest_setup.py b/SAS/TMSS/test/tmss_database_unittest_setup.py index 812464c3e91..adc9193ff72 100644 --- a/SAS/TMSS/test/tmss_database_unittest_setup.py +++ b/SAS/TMSS/test/tmss_database_unittest_setup.py @@ -22,10 +22,6 @@ By importing this helper module in your unittest module you get a TMSSTestDataba which is automatically destroyed at the end of the unittest session. ''' -# indicate that we're unittesting. -import os -os.environ['TMSS_UNIT_TESTING'] = str(True) - # 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. diff --git a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py index a8c658c962f..98375bb80e3 100644 --- a/SAS/TMSS/test/tmss_test_environment_unittest_setup.py +++ b/SAS/TMSS/test/tmss_test_environment_unittest_setup.py @@ -22,10 +22,6 @@ By importing this helper module in your unittest module you get a TMSSTestDataba which is automatically destroyed at the end of the unittest session. ''' -# indicate that we're unittesting. -import os -os.environ['TMSS_UNIT_TESTING'] = str(True) - import logging logger = logging.getLogger(__name__) -- GitLab