Repository: slackapi/python-slackclient
Pull request #824 (2020-09-23 22:32:49)

Correct the text validation in header blocks
## Summary

`text` field validation in `header` blocks introduced by #768 has not been working. This pull request corrects the implementation to use the max length. 

In addition, this PR adjusts the upper limit. The max length in the document (3000) is incorrect (or outdated). The actual behavior is up to 150 characters. The API document team is going to update the page soon.

cc @mwbrooks (as the author of #768)

### Category (place an `x` in each of the `[ ]`)

- [ ] **slack.web.WebClient** (Web API client)
- [ ] **slack.webhook.WebhookClient** (Incoming Webhook, response_url sender)
- [x] **slack.web.classes** (UI component builders)
- [ ] **slack.rtm.RTMClient** (RTM client)

## Requirements (place an `x` in each `[ ]`)

- [x] I've read and understood the [Contributing Guidelines](https://github.com/slackapi/python-slackclient/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 `python setup.py validate` after making the changes.


codecov[bot]: # [Codecov](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=h1) Report
> Merging [#824](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=desc) into [main](https://codecov.io/gh/slackapi/python-slackclient/commit/01c4292c6b8159e620334c8cb313ec634c8021aa?el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/slackapi/python-slackclient/pull/824/graphs/tree.svg?width=650&height=150&src=pr&token=F0O7meYmtD)](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##             main     #824      +/-   ##
==========================================
+ Coverage   87.28%   87.29%   +0.01%     
==========================================
  Files          30       30              
  Lines        3758     3761       +3     
  Branches      337      337              
==========================================
+ Hits         3280     3283       +3     
  Misses        329      329              
  Partials      149      149              
```


| [Impacted Files](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [slack/web/classes/blocks.py](https://codecov.io/gh/slackapi/python-slackclient/pull/824/diff?src=pr&el=tree#diff-c2xhY2svd2ViL2NsYXNzZXMvYmxvY2tzLnB5) | `93.75% <100.00%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=footer). Last update [01c4292...3dfdb07](https://codecov.io/gh/slackapi/python-slackclient/pull/824?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs-src/_themes/slack/sidebar.html b/docs-src/_themes/slack/sidebar.html
index d92ca90..2ca9f37 100644
--- a/docs-src/_themes/slack/sidebar.html
+++ b/docs-src/_themes/slack/sidebar.html
@@ -3,9 +3,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs-src/metadata.rst b/docs-src/metadata.rst
index f58a197..1b4e67c 100644
--- a/docs-src/metadata.rst
+++ b/docs-src/metadata.rst
@@ -11,10 +11,10 @@
 .. _Issue Tracker: http://github.com/SlackAPI/python-slackclient/issues
 .. _pull request: http://github.com/SlackAPI/python-slackclient/pulls
 .. _Python RTMBot: https://slackapi.github.io/python-rtmbot
-.. _License: https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE
+.. _License: https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE
 .. _Code of Conduct: https://slackhq.github.io/code-of-conduct
-.. _Contributing: https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md
-.. _contributing guidelines: https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md
+.. _Contributing: https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md
+.. _contributing guidelines: https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md
 .. _Contributor License Agreement: https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform
 .. _Real Time Messaging (RTM) API: https://api.slack.com/rtm
 .. _Web API: https://api.slack.com/web
diff --git a/docs/about.html b/docs/about.html
index 4ef36e0..227e354 100644
--- a/docs/about.html
+++ b/docs/about.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
@@ -243,9 +243,9 @@
 <p>Access the Slack Platform from your Python app. Slack Developer Kit for Python lets you build on the Slack Web APIs pythonically.</p>
 <p>Slack Developer Kit for Python is proudly maintained with 💖 by the Slack Developer Tools team</p>
 <ul class="simple">
-<li><p><a class="reference external" href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></p></li>
+<li><p><a class="reference external" href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></p></li>
 <li><p><a class="reference external" href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></p></li>
-<li><p><a class="reference external" href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></p></li>
+<li><p><a class="reference external" href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></p></li>
 <li><p><a class="reference external" href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></p></li>
 </ul>
 </div>
diff --git a/docs/auth.html b/docs/auth.html
index 45e551b..181a0ae 100644
--- a/docs/auth.html
+++ b/docs/auth.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/basic_usage.html b/docs/basic_usage.html
index b3efdb3..7c4b114 100644
--- a/docs/basic_usage.html
+++ b/docs/basic_usage.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/changelog.html b/docs/changelog.html
index 67e65de..0f60671 100644
--- a/docs/changelog.html
+++ b/docs/changelog.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/conversations.html b/docs/conversations.html
index 7bc54d0..3810888 100644
--- a/docs/conversations.html
+++ b/docs/conversations.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/faq.html b/docs/faq.html
index 40b8022..9e65447 100644
--- a/docs/faq.html
+++ b/docs/faq.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
@@ -281,7 +281,7 @@ pip install <span class="s2">&quot;slackclient&gt;=2.0&quot;</span>
 </div>
 <div class="section" id="how-do-i-contribute">
 <h2>How do I contribute?<a class="headerlink" href="#how-do-i-contribute" title="Permalink to this headline">¶</a></h2>
-<p>What an excellent question. First of all, please have a look at our general <a class="reference external" href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">contributing guidelines</a>.</p>
+<p>What an excellent question. First of all, please have a look at our general <a class="reference external" href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">contributing guidelines</a>.</p>
 <p>All done? Great! While we’re super excited to incorporate your new feature, there are a couple of things we want to make sure you’ve given thought to.</p>
 <ul class="simple">
 <li><p>Please write unit tests for your new code. But don’t <strong>just</strong> aim to increase the test coverage, rather, we expect you
diff --git a/docs/genindex.html b/docs/genindex.html
index 8eec6e8..2df32f2 100644
--- a/docs/genindex.html
+++ b/docs/genindex.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/index.html b/docs/index.html
index ca1ed14..5e9de38 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/metadata.html b/docs/metadata.html
index 1f039b2..865ad7f 100644
--- a/docs/metadata.html
+++ b/docs/metadata.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/real_time_messaging.html b/docs/real_time_messaging.html
index f316ec0..8df9a5f 100644
--- a/docs/real_time_messaging.html
+++ b/docs/real_time_messaging.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/docs/search.html b/docs/search.html
index 6bed68a..68f740e 100644
--- a/docs/search.html
+++ b/docs/search.html
@@ -218,9 +218,9 @@
 <div id="footer">
 
     <ul id="footer_nav">
-        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li>
+        <li><a href="https://github.com/SlackAPI/python-slackclient/blob/main/LICENSE">License</a></li>
         <li><a href="https://slackhq.github.io/code-of-conduct">Code of Conduct</a></li>
-        <li><a href="https://github.com/slackapi/python-slackclient/blob/master/.github/contributing.md">Contributing</a></li>
+        <li><a href="https://github.com/slackapi/python-slackclient/blob/main/.github/contributing.md">Contributing</a></li>
         <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li>
     </ul>
 
diff --git a/slack/web/classes/blocks.py b/slack/web/classes/blocks.py
index f995e3c..1f412d8 100644
--- a/slack/web/classes/blocks.py
+++ b/slack/web/classes/blocks.py
@@ -387,7 +387,7 @@ class CallBlock(Block):
 
 class HeaderBlock(Block):
     type = "header"
-    text_max_length = 3000
+    text_max_length = 150
 
     @property
     def attributes(self) -> Set[str]:
@@ -411,3 +411,7 @@ class HeaderBlock(Block):
     @JsonValidator("text attribute must be specified")
     def _validate_text_populated(self):
         return self.text is not None
+
+    @JsonValidator(f"text attribute cannot exceed {text_max_length} characters")
+    def _validate_alt_text_length(self):
+        return self.text is None or len(self.text.text) <= self.text_max_length


Test patch:
diff --git a/tests/web/classes/test_blocks.py b/tests/web/classes/test_blocks.py
index a748943..547ac7e 100644
--- a/tests/web/classes/test_blocks.py
+++ b/tests/web/classes/test_blocks.py
@@ -713,3 +713,21 @@ class HeaderBlockTests(unittest.TestCase):
         }
         self.assertDictEqual(input, HeaderBlock(**input).to_dict())
         self.assertDictEqual(input, Block.parse(input).to_dict())
+
+    def test_text_length_150(self):
+        input = {
+            "type": "header",
+            "block_id": "budget-header",
+            "text": {"type": "plain_text", "text": "1234567890" * 15},
+        }
+        HeaderBlock(**input).validate_json()
+
+    def test_text_length_151(self):
+        input = {
+            "type": "header",
+            "block_id": "budget-header",
+            "text": {"type": "plain_text", "text": ("1234567890" * 15) + "1"},
+        }
+        with self.assertRaises(SlackObjectFormationError):
+            HeaderBlock(**input).validate_json()
+