From 4d4a49175403b488e530ec2d92f581a5b34b2f96 Mon Sep 17 00:00:00 2001 From: Afshin Darian Date: Thu, 26 Jul 2018 17:47:09 +0100 Subject: [PATCH] Update settings tests to include overrides. --- .../tests/app-settings/overrides.json | 5 +++++ .../tests/test_settings_api.py | 20 ++++++++++++++++--- .../tests/test_workspaces_api.py | 5 +++-- jupyterlab_launcher/tests/utils.py | 2 ++ .../tests/workspaces/foo.jupyterlab-workspace | 2 +- 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 jupyterlab_launcher/tests/app-settings/overrides.json diff --git a/jupyterlab_launcher/tests/app-settings/overrides.json b/jupyterlab_launcher/tests/app-settings/overrides.json new file mode 100644 index 00000000..3d39e80e --- /dev/null +++ b/jupyterlab_launcher/tests/app-settings/overrides.json @@ -0,0 +1,5 @@ +{ + "@jupyterlab/apputils-extension:themes": { + "theme": "JupyterLab Dark" + } +} diff --git a/jupyterlab_launcher/tests/test_settings_api.py b/jupyterlab_launcher/tests/test_settings_api.py index 55d9b581..faa7f511 100644 --- a/jupyterlab_launcher/tests/test_settings_api.py +++ b/jupyterlab_launcher/tests/test_settings_api.py @@ -23,21 +23,35 @@ class SettingsAPITest(LabTestBase): """Test the settings web service API""" def setUp(self): + # Copy the schema files. src = os.path.join( os.path.abspath(os.path.dirname(__file__)), 'schemas', '@jupyterlab') dst = os.path.join(self.lab_config.schemas_dir, '@jupyterlab') - if not os.path.exists(dst): - shutil.copytree(src, dst) + if os.path.exists(dst): + shutil.rmtree(dst) + shutil.copytree(src, dst) + + # Copy the overrides file. + src = os.path.join( + os.path.abspath(os.path.dirname(__file__)), + 'app-settings', + 'overrides.json') + dst = os.path.join(self.lab_config.app_settings_dir, 'overrides.json') + if os.path.exists(dst): + os.remove(dst) + shutil.copyfile(src, dst) self.settings_api = SettingsAPI(self.request) def test_get(self): id = '@jupyterlab/apputils-extension:themes' data = self.settings_api.get(id).json() + schema = data['schema'] assert data['id'] == id - assert len(data['schema']) + # Check that overrides.json file is respected. + assert schema['properties']['theme']['default'] == 'JupyterLab Dark' assert 'raw' in data def test_get_bad(self): diff --git a/jupyterlab_launcher/tests/test_workspaces_api.py b/jupyterlab_launcher/tests/test_workspaces_api.py index b663cdce..bf1cf817 100644 --- a/jupyterlab_launcher/tests/test_workspaces_api.py +++ b/jupyterlab_launcher/tests/test_workspaces_api.py @@ -31,8 +31,9 @@ def setUp(self): for item in os.listdir(data): src = os.path.join(data, item) dst = os.path.join(self.lab_config.workspaces_dir, item) - if not os.path.exists(dst): - shutil.copy(src, self.lab_config.workspaces_dir) + if os.path.exists(dst): + os.remove(dst) + shutil.copy(src, self.lab_config.workspaces_dir) self.workspaces_api = WorkspacesAPI(self.request) def test_delete(self): diff --git a/jupyterlab_launcher/tests/utils.py b/jupyterlab_launcher/tests/utils.py index 38aacad2..290a32be 100644 --- a/jupyterlab_launcher/tests/utils.py +++ b/jupyterlab_launcher/tests/utils.py @@ -44,6 +44,7 @@ def tmp(*parts): cls.config_dir = tmp('config') cls.runtime_dir = tmp('runtime') cls.lab_dir = tmp('lab') + cls.app_settings_dir = tmp('appsettings') cls.lab_schemas = tmp('labschemas') cls.lab_settings = tmp('labsettings') cls.lab_workspaces = tmp('labworkspaces') @@ -60,6 +61,7 @@ def tmp(*parts): }) cls.env_patch.start() cls.lab_config = LabConfig( + app_settings_dir=cls.app_settings_dir, schemas_dir=cls.lab_schemas, user_settings_dir=cls.lab_settings, workspaces_dir=cls.lab_workspaces) diff --git a/jupyterlab_launcher/tests/workspaces/foo.jupyterlab-workspace b/jupyterlab_launcher/tests/workspaces/foo.jupyterlab-workspace index 02bdc619..1a0de541 100644 --- a/jupyterlab_launcher/tests/workspaces/foo.jupyterlab-workspace +++ b/jupyterlab_launcher/tests/workspaces/foo.jupyterlab-workspace @@ -1 +1 @@ -{"data": {}, "metadata": {"id": "foo"}} \ No newline at end of file +{"data": {}, "metadata": {"id": "foo"}}