|
1 | 1 | # Copyright 2022 Canonical Ltd.
|
2 | 2 | # See LICENSE file for licensing details.
|
3 | 3 |
|
4 |
| -from unittest.mock import Mock, PropertyMock, patch |
| 4 | +from unittest.mock import Mock, PropertyMock, patch, sentinel |
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 | from charms.postgresql_k8s.v0.postgresql import (
|
@@ -216,3 +216,27 @@ def test_on_relation_broken(harness):
|
216 | 216 | )
|
217 | 217 | harness.charm.postgresql_client_relation._on_relation_broken(event)
|
218 | 218 | postgresql_mock.delete_user.assert_not_called()
|
| 219 | + |
| 220 | + |
| 221 | +def test_update_tls_flag(harness): |
| 222 | + with ( |
| 223 | + patch("charm.PostgreSQLTLS.get_tls_files", return_value=(None, sentinel.ca, None)), |
| 224 | + patch( |
| 225 | + "relations.postgresql_provider.new_password", return_value="test-password" |
| 226 | + ) as _new_password, |
| 227 | + patch( |
| 228 | + "relations.postgresql_provider.DatabaseProvides.fetch_relation_field", |
| 229 | + side_effect=[None, "db"], |
| 230 | + ), |
| 231 | + patch( |
| 232 | + "relations.postgresql_provider.DatabaseProvides.set_tls", |
| 233 | + ) as _set_tls, |
| 234 | + patch( |
| 235 | + "relations.postgresql_provider.DatabaseProvides.set_tls_ca", |
| 236 | + ) as _set_tls_ca, |
| 237 | + ): |
| 238 | + with harness.hooks_disabled(): |
| 239 | + second_rel = harness.add_relation(RELATION_NAME, "second_app") |
| 240 | + harness.charm.postgresql_client_relation.update_tls_flag("True") |
| 241 | + _set_tls.assert_called_once_with(second_rel, "True") |
| 242 | + _set_tls_ca.assert_called_once_with(second_rel, sentinel.ca) |
0 commit comments