Repository: slackapi/python-slack-sdk
Pull request #1536 (2024-08-01 19:42:46)

Support all possible fields for RichTextElementParts.Date
## Summary

This PR resolves [issue 1533](https://github.com/slackapi/python-slack-sdk/issues/1533
)
### Testing

No coresponding test were found, but confirmed properties with [reference](https://api.slack.com/reference/block-kit/blocks#rich_text:~:text=date-,The%20following%20are%20the%20properties%20of%20the,object%20type,-in%20the)

### Category <!-- place an `x` in each of the `[ ]`  -->

- [ ] **slack_sdk.web.WebClient (sync/async)** (Web API client)
- [ ] **slack_sdk.webhook.WebhookClient (sync/async)** (Incoming Webhook, response_url sender)
- [ ] **slack_sdk.socket_mode** (Socket Mode client)
- [ ] **slack_sdk.signature** (Request Signature Verifier)
- [ ] **slack_sdk.oauth** (OAuth Flow Utilities)
- [x] **slack_sdk.models** (UI component builders)
- [ ] **slack_sdk.scim** (SCIM API client)
- [ ] **slack_sdk.audit_logs** (Audit Logs API client)
- [ ] **slack_sdk.rtm_v2** (RTM client)
- [ ] `/docs-src` (Documents, have you run `./scripts/docs.sh`?)
- [ ] `/tutorial` (PythOnBoardingBot tutorial)
- [ ] `tests`/`integration_tests` (Automated tests for this library)

## Requirements <!-- place an `x` in each `[ ]` -->

- [x] I've read and understood the [Contributing Guidelines](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) and have done my best effort to follow them.
- [x] I've read and agree to the [Code of Conduct](https://slackhq.github.io/code-of-conduct).
- [x] I've run `python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh` after making the changes.

srtaalej: running validate script, will post result
srtaalej: > running validate script, will post result

passed! 
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/slackapi/python-slack-sdk/pull/1536?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi) Report
Attention: Patch coverage is `0%` with `4 lines` in your changes missing coverage. Please review.
> Project coverage is 84.95%. Comparing base [(`417fc5b`)](https://app.codecov.io/gh/slackapi/python-slack-sdk/commit/417fc5b269dba776b0ddb60223a756130815292d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi) to head [(`47a09a1`)](https://app.codecov.io/gh/slackapi/python-slack-sdk/commit/47a09a16b005ed5c4be0bbc2e8de08f1752d415d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi).

| [Files](https://app.codecov.io/gh/slackapi/python-slack-sdk/pull/1536?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi) | Patch % | Lines |
|---|---|---|
| [slack\_sdk/models/blocks/block\_elements.py](https://app.codecov.io/gh/slackapi/python-slack-sdk/pull/1536?src=pr&el=tree&filepath=slack_sdk%2Fmodels%2Fblocks%2Fblock_elements.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi#diff-c2xhY2tfc2RrL21vZGVscy9ibG9ja3MvYmxvY2tfZWxlbWVudHMucHk=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/slackapi/python-slack-sdk/pull/1536?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1536      +/-   ##
==========================================
+ Coverage   84.94%   84.95%   +0.01%     
==========================================
  Files         113      113              
  Lines       12498    12501       +3     
==========================================
+ Hits        10616    10620       +4     
+ Misses       1882     1881       -1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/slackapi/python-slack-sdk/pull/1536?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=slackapi).


Patch:
diff --git a/slack_sdk/models/blocks/block_elements.py b/slack_sdk/models/blocks/block_elements.py
index 46ab75d..5853c80 100644
--- a/slack_sdk/models/blocks/block_elements.py
+++ b/slack_sdk/models/blocks/block_elements.py
@@ -2099,17 +2099,23 @@ class RichTextElementParts:
 
         @property
         def attributes(self) -> Set[str]:
-            return super().attributes.union({"timestamp"})
+            return super().attributes.union({"timestamp", "format", "url", "fallback"})
 
         def __init__(
             self,
             *,
             timestamp: str,
+            format: str,
+            url: Optional[str] = None,
+            fallback: Optional[str] = None,
             **others: dict,
         ):
             super().__init__(type=self.type)
             show_unknown_key_warning(self, others)
             self.timestamp = timestamp
+            self.format = format
+            self.url = url
+            self.fallback = fallback
 
     class Broadcast(RichTextElement):
         type = "broadcast"


Test patch:
diff --git a/tests/slack_sdk/models/test_blocks.py b/tests/slack_sdk/models/test_blocks.py
index 66b17d2..65f0baf 100644
--- a/tests/slack_sdk/models/test_blocks.py
+++ b/tests/slack_sdk/models/test_blocks.py
@@ -1003,6 +1003,25 @@ class RichTextBlockTests(unittest.TestCase):
                         {"type": "usergroup", "usergroup_id": "S01BL602YLU"},
                         {"type": "text", "text": " "},
                         {"type": "channel", "channel_id": "C02GD0YEHDJ"},
+                        {
+                            "type": "date",
+                            "timestamp": "1628633089",
+                            "format": "{date_long}",
+                            "url": "https://slack.com",
+                            "fallback": "August 10, 2021",
+                        },
+                        {"type": "date", "timestamp": "1720710212", "format": "{date_num} at {time}", "fallback": "timey"},
+                        {
+                            "type": "date",
+                            "timestamp": "1628633089",
+                            "format": "{date_short_pretty}",
+                            "url": "https://slack.com",
+                        },
+                        {
+                            "type": "date",
+                            "timestamp": "1628633089",
+                            "format": "{ago}",
+                        },
                     ],
                 },
             ],
@@ -1078,6 +1097,12 @@ class RichTextBlockTests(unittest.TestCase):
                         _.UserGroup(usergroup_id="S01BL602YLU"),
                         _.Text(text=" "),
                         _.Channel(channel_id="C02GD0YEHDJ"),
+                        _.Date(
+                            timestamp="1628633089", format="{date_long}", url="https://slack.com", fallback="August 10, 2021"
+                        ),
+                        _.Date(timestamp="1720710212", format="{date_num} at {time}", fallback="timey"),
+                        _.Date(timestamp="1628633089", format="{date_short_pretty}", url="https://slack.com"),
+                        _.Date(timestamp="1628633089", format="{ago}"),
                     ]
                 ),
             ],