Skip to content

Commit

Permalink
Unittests adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Apr 25, 2024
1 parent 53e7443 commit 9364a5e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_restart_restarts_with_sleep(harness):
assert patched_sleep.call_count >= 1


def test_init_server_calls_necessary_methods(harness):
def test_init_server_calls_necessary_methods_non_leader(harness):
with harness.hooks_disabled():
peer_rel_id = harness.add_relation(PEER, CHARM_KEY)
harness.add_relation_unit(peer_rel_id, f"{CHARM_KEY}/0")
Expand All @@ -269,6 +269,27 @@ def test_init_server_calls_necessary_methods(harness):
assert isinstance(harness.charm.unit.status, ActiveStatus)


def test_init_server_calls_necessary_methods_leader(harness):
with harness.hooks_disabled():
peer_rel_id = harness.add_relation(PEER, CHARM_KEY)
harness.set_leader(True)
harness.add_relation_unit(peer_rel_id, f"{CHARM_KEY}/0")
harness.update_relation_data(peer_rel_id, f"{CHARM_KEY}", {"monitor-password": "bla"})

with (
patch("managers.config.ConfigManager.set_dashboard_properties") as dashboard_properties,
patch("workload.ODWorkload.start") as start,
):
harness.charm.init_server()

dashboard_properties.assert_called_once()
start.assert_called_once()

assert harness.charm.state.unit_server.started
assert isinstance(harness.charm.app.status, BlockedStatus)
assert isinstance(harness.charm.unit.status, ActiveStatus)


def test_config_changed_applies_relation_data(harness):
with harness.hooks_disabled():
_ = harness.add_relation(PEER, CHARM_KEY)
Expand Down

0 comments on commit 9364a5e

Please sign in to comment.