def test_new_instance(self, plugin, ez_client, bg_system, bg_instance): existing_system = System( id="id", name="test_system", version="0.0.1", instances=[bg_instance], max_instances=2, metadata={"foo": "bar"}, template=None, ) ez_client.find_unique_system.return_value = existing_system new_name = "foo_instance" plugin._config.instance_name = new_name plugin._initialize_system() assert ez_client.create_system.called is False ez_client.update_system.assert_called_once_with( existing_system.id, new_commands=bg_system.commands, metadata=bg_system.metadata, description=bg_system.description, icon_name=bg_system.icon_name, display_name=bg_system.display_name, template="<html>template</html>", add_instance=ANY, ) assert ez_client.update_system.call_args[1][ "add_instance"].name == new_name
def test_system_exists(self, plugin, ez_client, bg_system, bg_instance, current_commands): existing_system = System( id="id", name="test_system", version="0.0.1", instances=[bg_instance], commands=current_commands, metadata={"foo": "bar"}, template=None, ) ez_client.find_unique_system.return_value = existing_system bg_system.commands = [Command("test")] ez_client.update_system.return_value = bg_system plugin._initialize_system() assert ez_client.create_system.called is False ez_client.update_system.assert_called_once_with( existing_system.id, new_commands=bg_system.commands, metadata=bg_system.metadata, description=bg_system.description, icon_name=bg_system.icon_name, display_name=bg_system.display_name, template="<html>template</html>", )
def test_new_system(self, plugin, ez_client, bg_system, bg_instance): ez_client.find_unique_system.return_value = None plugin._initialize_system() ez_client.create_system.assert_called_once_with(bg_system) assert ez_client.find_unique_system.call_count == 1 assert ez_client.update_system.called is False
def test_new_system_conflict_succeed(self, plugin, ez_client, bg_system): ez_client.find_unique_system.side_effect = [None, bg_system] ez_client.create_system.side_effect = ConflictError() plugin._initialize_system() ez_client.create_system.assert_called_once_with(bg_system) assert ez_client.find_unique_system.call_count == 2 assert ez_client.update_system.called is True
def test_new_system_conflict_fail(self, plugin, ez_client, bg_system): ez_client.find_unique_system.return_value = None ez_client.create_system.side_effect = ConflictError() with pytest.raises(PluginValidationError): plugin._initialize_system() ez_client.create_system.assert_called_once_with(bg_system) assert ez_client.find_unique_system.call_count == 2 assert ez_client.update_system.called is False