actions: Refactor do_update_outgoing_webhook_service.

This updates `do_update_outgoing_webhook_service` to use
`BotServicesOutgoing` as the schema for the updated service data we send
back to client because it's the schema `bot_data.update` expects.

The function is also refactored to allow updating specific fields of the
Service row instead of requiring all value for the Service fields to be
passed.

This is a prep commit for #34524, it adds another field to the Service
field.
This commit is contained in:
PieterCK
2025-05-26 11:22:25 +07:00
committed by Tim Abbott
parent 25cebcd119
commit fb229a013e
3 changed files with 66 additions and 13 deletions

View File

@@ -297,6 +297,7 @@ from zerver.models import (
UserStatus,
UserTopic,
)
from zerver.models.bots import get_bot_services
from zerver.models.clients import get_client
from zerver.models.groups import SystemGroups
from zerver.models.realm_audit_logs import AuditLogEventType
@@ -3517,9 +3518,33 @@ class NormalActionsTest(BaseAction):
interface_type=Service.GENERIC,
)
with self.verify_action() as events:
do_update_outgoing_webhook_service(bot, 2, "http://hostname.domain2.com")
do_update_outgoing_webhook_service(
bot, interface=2, base_url="http://hostname.domain2.com"
)
check_realm_bot_update("events[0]", events[0], "services")
# Check the updated Service data we send as event on commit.
bot_service = get_bot_services(bot.id)[0]
event_data_service = events[0]["bot"]["services"][0]
self.assertEqual(
{
"base_url": bot_service.base_url,
"interface": bot_service.interface,
"token": bot_service.token,
},
event_data_service,
)
with self.verify_action(num_events=0, state_change_expected=False) as events:
do_update_outgoing_webhook_service(bot)
# Trying to update with the same value as existing value results in no op.
with self.verify_action(num_events=0, state_change_expected=False) as events:
do_update_outgoing_webhook_service(
bot, interface=2, base_url="http://hostname.domain2.com"
)
def test_do_deactivate_bot(self) -> None:
bot = self.create_bot("test")
with self.verify_action(num_events=2) as events: