]> git.cworth.org Git - turbot/blobdiff - turbot/util/blocks-test.py
Add some utility code
[turbot] / turbot / util / blocks-test.py
diff --git a/turbot/util/blocks-test.py b/turbot/util/blocks-test.py
new file mode 100755 (executable)
index 0000000..2e09c0e
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+from blocks import (
+    multi_select_block, accessory_block, section_block, text_block
+)
+
+def new_multi_select_block(label, name, placeholder, options, default=None):
+
+    multi_select = {
+        "action_id": name,
+        "type": "multi_static_select",
+        "placeholder": {
+            "type": "plain_text",
+            "text": placeholder
+        },
+        "options": [
+            {
+                "text": {
+                    "type": "plain_text",
+                    "text": option
+                },
+                "value": option
+            } for option in options
+        ]
+    }
+
+    return accessory_block(
+        section_block(text_block("*{}*".format(label))),
+        multi_select
+    )
+
+blocks = multi_select_block("Label", "Name", "Placeholder",
+                            ["Foo", "Bar", "Baz"])
+
+blocks_str = str(blocks)
+
+new_blocks = new_multi_select_block("Label", "Name", "Placeholder",
+                                    ["Foo", "Bar", "Baz"])
+
+new_blocks_str = str(new_blocks)
+
+print("In main, blocks is: {}".format(blocks_str))
+
+print("Also new_blocks is: {}".format(new_blocks_str))
+
+if blocks_str == new_blocks_str:
+    print("Perfect match!")
+else:
+    print("No match.")