Skip to content

Commit

Permalink
WIP: Add invalid add test
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMadge committed Oct 30, 2023
1 parent f6071f5 commit 2595afe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data_safe_haven/config/backend_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
12 changes: 12 additions & 0 deletions tests_/config/test_backend_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2595afe

Please sign in to comment.