From 342a9d774c93730ab79f5000a87bd9ddd4a2fa37 Mon Sep 17 00:00:00 2001 From: bmccandless Date: Mon, 14 Sep 2020 13:15:47 -0700 Subject: [PATCH] app config bug fix: (#1833) * app config bug fix: When reading a config file that included per_dataset_config, the dataroot specializations were applied, but not the default config. This PR fixes that and also includes a test for this case. --- server/common/app_config.py | 5 ++- server/test/unit/common/test_app_config.py | 42 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/server/common/app_config.py b/server/common/app_config.py index 3caccec5..e0a49e46 100644 --- a/server/common/app_config.py +++ b/server/common/app_config.py @@ -100,7 +100,10 @@ class AppConfig(object): per_dataset_config = config.get("per_dataset_config", {}) for key, dataroot_config in per_dataset_config.items(): - self.add_dataroot_config(key, **dataroot_config) + # first create and initialize the dataroot with the default config + self.add_dataroot_config(key, **config["dataset"]) + # then apply the per dataset configuration + self.dataroot_config[key].update_from_config(dataroot_config, f"per_dataset_config__{key}") self.is_complete = False diff --git a/server/test/unit/common/test_app_config.py b/server/test/unit/common/test_app_config.py index 543fe6da..f8a20093 100644 --- a/server/test/unit/common/test_app_config.py +++ b/server/test/unit/common/test_app_config.py @@ -2,6 +2,7 @@ import os import unittest from unittest import mock from unittest.mock import patch +import tempfile import requests @@ -154,3 +155,44 @@ class AppConfigTest(unittest.TestCase): self.assertEqual(response.status_code, 200) data_config = response.json() self.assertEqual(data_config["config"]["displayNames"]["dataset"], "pbmc3k") + + def test_configfile_with_specialization(self): + # test that per_dataset_config config load the default config, then the specialized config + + with tempfile.TemporaryDirectory() as tempdir: + configfile = os.path.join(tempdir, "config.yaml") + with open(configfile, "w") as fconfig: + config = """ + server: + multi_dataset: + dataroot: + test: + base_url: test + dataroot: fake_dataroot + + dataset: + user_annotations: + enable: false + type: hosted_tiledb_array + hosted_tiledb_array: + db_uri: fake_db_uri + hosted_file_directory: fake_dir + + per_dataset_config: + test: + user_annotations: + enable: true + """ + fconfig.write(config) + + app_config = AppConfig() + app_config.update_from_config_file(configfile) + + test_config = app_config.dataroot_config["test"] + + # test config from default + self.assertEqual(test_config.user_annotations__type, "hosted_tiledb_array") + self.assertEqual(test_config.user_annotations__hosted_tiledb_array__db_uri, "fake_db_uri") + + # test config from specialization + self.assertTrue(test_config.user_annotations__enable)