mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
slack_incoming: Handle optional attachment fields aptly.
This commit checks for null values for keys within "attachment" in
the Slack integration's incoming payloads. These keys were expected
to exist optionally previously, and the existence of null values for
these wasn't anticipated. Due to an issue report for such null
values in the payload, their handling is updated appropriately.
The checks for these values are truthiness checks since the strategy
for these values being null or falsy ("", 0) is the same; we don't
process that key-value pair. This is consistent with how Slack handles
this scenario.
For the case where all the attachment fields have null values, Slack
displays this as an empty block with no content, and therefore our
strategy for this is a no-op.
Tests updated.
This commit is contained in:
committed by
Tim Abbott
parent
ef21f9107c
commit
fd0b013bcd
@@ -167,6 +167,8 @@ Build bla bla succeeded
|
||||
**Requested by**: Some user
|
||||
**Duration**: 00:02:03
|
||||
**Build pipeline**: ConsumerAddressModule
|
||||
**Title without value**
|
||||
Value without title
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
@@ -197,3 +199,148 @@ Build bla bla succeeded
|
||||
else:
|
||||
file_type = "json"
|
||||
return self.webhook_fixture_data("slack_incoming", fixture_name, file_type=file_type)
|
||||
|
||||
def test_attachment_pieces_title_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
Sample pretext.
|
||||
|
||||
Sample text.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
Sample footer.
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_title_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_image_url_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## [Sample title.](https://www.google.com)
|
||||
|
||||
Sample pretext.
|
||||
|
||||
Sample text.
|
||||
|
||||
Sample footer.
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_image_url_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_ts_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## [Sample title.](https://www.google.com)
|
||||
|
||||
Sample pretext.
|
||||
|
||||
Sample text.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
Sample footer.
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_ts_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_text_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## [Sample title.](https://www.google.com)
|
||||
|
||||
Sample pretext.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
Sample footer.
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_text_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_pretext_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## [Sample title.](https://www.google.com)
|
||||
|
||||
Sample text.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
Sample footer.
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_pretext_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_footer_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## [Sample title.](https://www.google.com)
|
||||
|
||||
Sample pretext.
|
||||
|
||||
Sample text.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_footer_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_title_link_null(self) -> None:
|
||||
expected_topic = "(no topic)"
|
||||
expected_message = """
|
||||
## Sample title.
|
||||
|
||||
Sample pretext.
|
||||
|
||||
Sample text.
|
||||
|
||||
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
|
||||
|
||||
Sample footer.
|
||||
|
||||
<time:1655945306>
|
||||
""".strip()
|
||||
|
||||
self.check_webhook(
|
||||
"attachment_pieces_title_link_null",
|
||||
expected_topic,
|
||||
expected_message,
|
||||
)
|
||||
|
||||
def test_attachment_pieces_all_null(self) -> None:
|
||||
self.check_webhook("attachment_pieces_all_null", expect_noop=True)
|
||||
|
||||
Reference in New Issue
Block a user