Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Feb 26, 2025
1 parent 39034e3 commit fb53fe1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/unit/test_data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _on_index_requested(self, _) -> None:


class DataProvidesBaseTests(ABC):
SECRET_FIELDS = ["username", "password", "tls", "tls-ca", "uris"]
SECRET_FIELDS = ["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]
DATABASE_FIELD = "database"

@pytest.fixture
Expand Down Expand Up @@ -804,7 +804,7 @@ def test_provider_interface_functions_secrets(self):
rel_data = interface.fetch_relation_data()
assert rel_data == {
0: {
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
self.DATABASE_FIELD: DATABASE,
}
}
Expand All @@ -813,7 +813,7 @@ def test_provider_interface_functions_secrets(self):
0: {
"data": json.dumps(
{
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
self.DATABASE_FIELD: DATABASE,
}
)
Expand Down Expand Up @@ -852,11 +852,11 @@ def test_provider_interface_dict_secrets(self):
assert datadict == {
"data": json.dumps(
{
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
self.DATABASE_FIELD: DATABASE,
}
),
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
self.DATABASE_FIELD: DATABASE,
}

Expand All @@ -865,7 +865,7 @@ def test_provider_interface_dict_secrets(self):
with self._caplog.at_level(logging.ERROR):
assert (
datadict["requested-secrets"]
== '["username", "password", "tls", "tls-ca", "uris"]'
== '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]'
)
assert (
"This operation (fetch_my_relation_field()) can only be performed by the leader unit"
Expand Down Expand Up @@ -946,6 +946,7 @@ def test_set_additional_fields(self):
self.harness.charm.provider.set_tls(self.rel_id, "True")
self.harness.charm.provider.set_tls_ca(self.rel_id, "Canonical")
self.harness.charm.provider.set_uris(self.rel_id, "host1:port,host2:port")
self.harness.charm.provider.set_read_only_uris(self.rel_id, "host2:port")
self.harness.charm.provider.set_version(self.rel_id, "1.0")

# Check that the additional fields are present in the relation.
Expand All @@ -957,6 +958,7 @@ def test_set_additional_fields(self):
"tls": "True",
"tls-ca": "Canonical",
"uris": "host1:port,host2:port",
"read-only-uris": "host2:port",
"version": "1.0",
}

Expand Down Expand Up @@ -1963,7 +1965,7 @@ def test_requires_interface_functions_secrets(self):
"alias": "cluster1",
"database": "data_platform",
"extra-user-roles": "CREATEDB,CREATEROLE",
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
}
}

Expand Down Expand Up @@ -1991,7 +1993,7 @@ def test_requires_interface_dict_secrets(self):
"alias": "cluster1",
"database": "data_platform",
"extra-user-roles": "CREATEDB,CREATEROLE",
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris"]',
"requested-secrets": '["username", "password", "tls", "tls-ca", "uris", "read-only-uris"]',
}

# Non-leader can try to fetch data (won't have anything thought, as only app data is there...
Expand Down

0 comments on commit fb53fe1

Please sign in to comment.