def test__it_updates_the_juju_pod_spec(self, mock_build_am_config_func, mock_build_juju_pod_spec_func): # Setup mock_fw_adapter_cls = \ create_autospec(framework.FrameworkAdapter, spec_set=True) mock_fw = mock_fw_adapter_cls.return_value mock_fw.am_i_leader.return_value = True mock_event_cls = create_autospec(EventBase, spec_set=True) mock_event = mock_event_cls.return_value mock_juju_pod_spec = create_autospec(domain.AlertManagerJujuPodSpec) mock_build_juju_pod_spec_func.return_value = mock_juju_pod_spec # Exercise charm.on_start_handler(mock_event, mock_fw) # Assert assert mock_build_juju_pod_spec_func.call_count == 1 assert mock_build_juju_pod_spec_func.call_args == \ call(app_name=mock_fw.get_app_name.return_value, charm_config=mock_fw.get_config.return_value, image_meta=mock_fw.get_image_meta.return_value, alertmanager_config=mock_build_am_config_func.return_value) assert mock_fw.set_pod_spec.call_count == 1 assert mock_fw.set_pod_spec.call_args == \ call(mock_juju_pod_spec.to_dict()) assert mock_fw.set_unit_status.call_count == 1 args, kwargs = mock_fw.set_unit_status.call_args_list[0] assert type(args[0]) == MaintenanceStatus
def test__it_updates_the_juju_pod_spec(self, mock_build_juju_pod_spec_func): # Setup mock_fw_adapter_cls = \ create_autospec(framework.FrameworkAdapter, spec_set=True) mock_fw = mock_fw_adapter_cls.return_value mock_fw.unit_is_leader.return_value = True mock_event_cls = create_autospec(EventBase, spec_set=True) mock_event = mock_event_cls.return_value mock_prom_juju_pod_spec = create_autospec(domain.PrometheusJujuPodSpec) mock_build_juju_pod_spec_func.return_value = mock_prom_juju_pod_spec mock_state = create_autospec(charm.StoredState).return_value # Exercise charm.on_start_handler(mock_event, mock_fw, mock_state) # Assert assert mock_state.recently_started assert mock_state.config_propagated assert mock_build_juju_pod_spec_func.call_count == 1 assert mock_build_juju_pod_spec_func.call_args == \ call(app_name=mock_fw.get_app_name.return_value, charm_config=mock_fw.get_config.return_value, prom_image_meta=mock_fw.get_image_meta.return_value, nginx_image_meta=mock_fw.get_image_meta.return_value, alerting_config={}) assert mock_fw.set_pod_spec.call_count == 1 assert mock_fw.set_pod_spec.call_args == \ call(mock_prom_juju_pod_spec.to_dict()) assert mock_fw.set_unit_status.call_count == 1 args, kwargs = mock_fw.set_unit_status.call_args_list[0] assert type(args[0]) == MaintenanceStatus