webhooks: Rename *topic local variables to *topic_name.

This is preparatory work towards adding a Topic model.
We plan to use the local variable name as 'topic' for
the Topic model objects.

Currently, we use *topic as the local variable name for
topic names.

We rename local variables of the form *topic to *topic_name
so that we don't need to think about type collisions in
individual code paths where we might want to talk about both
Topic objects and strings for the topic name.
This commit is contained in:
Prakhar Pratyush
2024-01-17 20:23:30 +05:30
committed by Tim Abbott
parent 030f899195
commit 3afc8ed7ae
163 changed files with 1725 additions and 1619 deletions

View File

@@ -12,18 +12,18 @@ class FrontHookTests(WebhookTestCase):
# Conversation automatically assigned to a teammate who started it.
def test_conversation_assigned_outbound(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "**Leela Turanga** assigned themselves."
self.check_webhook(
"conversation_assigned_outbound",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_outbound_message(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = (
"[Outbound message](https://app.frontapp.com/open/msg_1176ie2) "
"from **support@planet-express.com** "
@@ -33,68 +33,68 @@ class FrontHookTests(WebhookTestCase):
self.check_webhook(
"outbound_message",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_archived(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Archived by **Leela Turanga**."
self.check_webhook(
"conversation_archived",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_reopened(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Reopened by **Leela Turanga**."
self.check_webhook(
"conversation_reopened",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_deleted(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Deleted by **Leela Turanga**."
self.check_webhook(
"conversation_deleted",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_restored(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Restored by **Leela Turanga**."
self.check_webhook(
"conversation_restored",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_unassigned(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Unassigned by **Leela Turanga**."
self.check_webhook(
"conversation_unassigned",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_mention_all(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = (
"**Leela Turanga** left a comment:\n"
"```quote\n@all Could someone else take this?\n```"
@@ -102,7 +102,7 @@ class FrontHookTests(WebhookTestCase):
self.check_webhook(
"mention_all",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
@@ -110,7 +110,7 @@ class FrontHookTests(WebhookTestCase):
# Scenario 2: Conversation starts from an inbound message.
def test_inbound_message(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = (
"[Inbound message](https://app.frontapp.com/open/msg_1176r8y) "
"from **calculon@momsbot.com** "
@@ -120,36 +120,36 @@ class FrontHookTests(WebhookTestCase):
self.check_webhook(
"inbound_message",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_tagged(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**Leela Turanga** added tag **Urgent**."
self.check_webhook(
"conversation_tagged",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
# Conversation automatically assigned to a teammate who replied to it.
def test_conversation_assigned_reply(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**Leela Turanga** assigned themselves."
self.check_webhook(
"conversation_assigned_reply",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_outbound_reply(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = (
"[Outbound reply](https://app.frontapp.com/open/msg_1176ryy) "
"from **support@planet-express.com** "
@@ -158,24 +158,24 @@ class FrontHookTests(WebhookTestCase):
self.check_webhook(
"outbound_reply",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_untagged(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**Leela Turanga** removed tag **Urgent**."
self.check_webhook(
"conversation_untagged",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_mention(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = (
"**Leela Turanga** left a comment:\n"
"```quote\n@bender Could you take it from here?\n```"
@@ -183,52 +183,52 @@ class FrontHookTests(WebhookTestCase):
self.check_webhook(
"mention",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_comment(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**Bender Rodriguez** left a comment:\n```quote\nSure.\n```"
self.check_webhook(
"comment",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
# Conversation manually assigned to another teammate.
def test_conversation_assigned(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**Leela Turanga** assigned **Bender Rodriguez**."
self.check_webhook(
"conversation_assigned",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_assigned_by_rule(self) -> None:
expected_topic = "cnv_keocka"
expected_topic_name = "cnv_keocka"
expected_message = "**'Important deliveries' rule** assigned **Bender Rodriguez**."
self.check_webhook(
"rule",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_conversation_assigned_by_gmail(self) -> None:
expected_topic = "cnv_keo696"
expected_topic_name = "cnv_keo696"
expected_message = "Archived by **(gmail)**."
self.check_webhook(
"gmail",
expected_topic,
expected_topic_name,
expected_message,
content_type="application/x-www-form-urlencoded",
)

View File

@@ -147,8 +147,8 @@ def api_front_webhook(
if event not in EVENT_FUNCTION_MAPPER:
raise JsonableError(_("Unknown webhook request"))
topic = payload["conversation"]["id"].tame(check_string)
topic_name = payload["conversation"]["id"].tame(check_string)
body = get_body_based_on_event(event)(payload)
check_send_webhook_message(request, user_profile, topic, body, event)
check_send_webhook_message(request, user_profile, topic_name, body, event)
return json_success(request)