From 2595afe83c0513e4e55978c17a35fe1ef8a4a2e8 Mon Sep 17 00:00:00 2001 From: Jim Madge Date: Mon, 30 Oct 2023 11:37:26 +0000 Subject: [PATCH] WIP: Add invalid add test --- data_safe_haven/config/backend_settings.py | 2 +- tests_/config/test_backend_settings.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/data_safe_haven/config/backend_settings.py b/data_safe_haven/config/backend_settings.py index a4f92105c9..5488d3f8dc 100644 --- a/data_safe_haven/config/backend_settings.py +++ b/data_safe_haven/config/backend_settings.py @@ -136,7 +136,7 @@ def add( ) -> None: # Ensure context is not already present if key in self.settings["contexts"].keys(): - msg = f"A context with key '{key}' is already defined" + msg = f"A context with key '{key}' is already defined." raise DataSafeHavenParameterError(msg) self.settings["contexts"][key] = { diff --git a/tests_/config/test_backend_settings.py b/tests_/config/test_backend_settings.py index e358c2922c..0e44465564 100644 --- a/tests_/config/test_backend_settings.py +++ b/tests_/config/test_backend_settings.py @@ -120,6 +120,18 @@ def test_add(self): assert settings.context.name == "Example" assert settings.context.subscription_name == "Data Safe Haven (Example)" + def test_invalid_add(self): + settings = ContextSettings(yaml.safe_load(self.context_settings)) + with pytest.raises(DataSafeHavenParameterError) as exc: + settings.add( + key="acme", + name="Acme Deployment", + subscription_name="Data Safe Haven (Acme)", + admin_group_id="d5c5c439-1115-4cb6-ab50-b8e547b6c8dd", + location="uksouth", + ) + assert "A context with key 'acme' is already defined." in exc + def test_from_file(self, tmp_path): config_file_path = tmp_path / "config.yaml" with open(config_file_path, "w") as f: