diff --git a/lib/charms/data_platform_libs/v0/data_secrets.py b/lib/charms/data_platform_libs/v0/data_secrets.py index 254b9af3..4b1dc0df 100644 --- a/lib/charms/data_platform_libs/v0/data_secrets.py +++ b/lib/charms/data_platform_libs/v0/data_secrets.py @@ -97,7 +97,7 @@ def get_content(self) -> Dict[str, str]: """Getting cached secret content.""" if not self._secret_content: if self.meta: - self._secret_content = self.meta.get_content() + self._secret_content = self.meta.peek_content() return self._secret_content def set_content(self, content: Dict[str, str]) -> None: diff --git a/tests/unit/test_data_interfaces.py b/tests/unit/test_data_interfaces.py index 5fbdea06..3be5d25f 100644 --- a/tests/unit/test_data_interfaces.py +++ b/tests/unit/test_data_interfaces.py @@ -332,7 +332,7 @@ def test_set_additional_fields_secrets(self): } secret = self.harness.charm.model.get_secret(id=secret_id) - assert secret.get_content() == { + assert secret.peek_content() == { "tls": "True", "tls-ca": "Canonical", } @@ -661,7 +661,7 @@ def test_set_additional_fields_secrets(self): } secret = self.harness.charm.model.get_secret(id=secret_id) - assert secret.get_content() == { + assert secret.peek_content() == { "tls": "True", "tls-ca": "Canonical", } diff --git a/tests/unit/test_data_secrets.py b/tests/unit/test_data_secrets.py index 2596bb14..ac219618 100644 --- a/tests/unit/test_data_secrets.py +++ b/tests/unit/test_data_secrets.py @@ -53,6 +53,36 @@ def test_cached_secret_is_cached(harness, mocker): assert patched_get_content.called_once() +@pytest.mark.usefixtures("only_with_juju_secrets") +def test_add_multiple_secrets(harness): + """Test that more than one secret key:value can be set.""" + cache = SecretCache(harness.charm) + + secret = cache.get("label1") + assert not secret + cache.add("label1", {"best-2020-picture": "Nomadland"}, scope="app") + + secret = cache.get("label1") + assert secret + content = secret.get_content() + content["best-2021-picture"] = "CODA" + secret.set_content(content) + + secret = cache.get("label1") + assert secret + content = secret.get_content() + content["best-2022-picture"] = "Everything Everywhere All at Once" + secret.set_content(content) + + # Verify that it made it to Juju, not just to the cache. + secret = harness.model.get_secret(label="label1") + assert secret.get_content() == { + "best-2020-picture": "Nomadland", + "best-2021-picture": "CODA", + "best-2022-picture": "Everything Everywhere All at Once", + } + + @pytest.mark.usefixtures("only_with_juju_secrets") def test_secret_cache(harness): """Testing the SecretCache class."""