def test_leadership_mock(self): self.leadership_data["foo"] = "bar" self.assertEqual(client._get_pgsql_leader_data(), self.leadership_data) self.assertIsNot(client._get_pgsql_leader_data(), self.leadership_data) client._set_pgsql_leader_data({"one": "two"}) self.assertEqual(client._get_pgsql_leader_data(), { "foo": "bar", "one": "two" }) client._set_pgsql_leader_data({"foo": "baz"}) self.assertEqual(client._get_pgsql_leader_data(), { "foo": "baz", "one": "two" }) self.assertEqual(self.leadership_data, {"foo": "baz", "one": "two"})
def test_non_leader_mirrors_leader_data(self): # On upgrade-charm, non-leaders defer the event until they are # leader or the leader has shared the relation settings. When # the non-leader sees the shared relation settings, it mirrors # them to its local unit relation data for backwards # compatibility with older PostgreSQL charm deployments. self.charm.on.upgrade_charm.emit() self.assertNotIn("database", self.relation.data[self.local_unit]) client._set_pgsql_leader_data({ self.relation_id: { "database": "mydb", "extensions": "citext,debversion", "roles": "myrole" } }) self.harness.framework.reemit() self.assertEqual(self.relation.data[self.local_unit]["database"], "mydb") self.assertEqual(self.relation.data[self.local_unit]["extensions"], "citext,debversion") self.assertEqual(self.relation.data[self.local_unit]["roles"], "myrole")
def test_set_pgsql_leader_data(self, leader_set): data = {2: {"extensions": ["citext"], "database": "testus"}} client._set_pgsql_leader_data(data) encoded_data = yaml.safe_dump(data) leader_set.assert_called_once_with({client.LEADER_KEY: encoded_data})