|
10 | 10 | CallBlock, |
11 | 11 | CardBlock, |
12 | 12 | CarouselBlock, |
| 13 | + ContainerBlock, |
13 | 14 | ContextActionsBlock, |
14 | 15 | ContextBlock, |
15 | 16 | DividerBlock, |
@@ -1752,6 +1753,135 @@ def test_missing_text(self): |
1752 | 1753 | AlertBlock(text="").validate_json() |
1753 | 1754 |
|
1754 | 1755 |
|
| 1756 | +class ContainerBlockTests(unittest.TestCase): |
| 1757 | + def test_document(self): |
| 1758 | + input = { |
| 1759 | + "type": "container", |
| 1760 | + "title": {"type": "plain_text", "text": "My Container"}, |
| 1761 | + "child_blocks": [ |
| 1762 | + {"type": "section", "text": {"type": "mrkdwn", "text": "Hello"}}, |
| 1763 | + {"type": "divider"}, |
| 1764 | + ], |
| 1765 | + } |
| 1766 | + self.assertDictEqual(input, ContainerBlock(**input).to_dict()) |
| 1767 | + |
| 1768 | + def test_parse(self): |
| 1769 | + input = { |
| 1770 | + "type": "container", |
| 1771 | + "title": {"type": "plain_text", "text": "Parsed"}, |
| 1772 | + "child_blocks": [ |
| 1773 | + {"type": "header", "text": {"type": "plain_text", "text": "Header"}}, |
| 1774 | + ], |
| 1775 | + } |
| 1776 | + parsed = Block.parse(input) |
| 1777 | + self.assertIsNotNone(parsed) |
| 1778 | + self.assertDictEqual(input, parsed.to_dict()) |
| 1779 | + |
| 1780 | + def test_all_properties_collapsible(self): |
| 1781 | + input = { |
| 1782 | + "type": "container", |
| 1783 | + "title": {"type": "plain_text", "text": "Full Container"}, |
| 1784 | + "subtitle": {"type": "mrkdwn", "text": "A subtitle"}, |
| 1785 | + "child_blocks": [ |
| 1786 | + {"type": "section", "text": {"type": "mrkdwn", "text": "Content"}}, |
| 1787 | + ], |
| 1788 | + "width": "wide", |
| 1789 | + "icon": {"type": "image", "image_url": "https://example.com/img.png", "alt_text": "icon"}, |
| 1790 | + "is_collapsible": True, |
| 1791 | + "default_collapsed": True, |
| 1792 | + "block_id": "container-1", |
| 1793 | + } |
| 1794 | + self.assertDictEqual(input, ContainerBlock(**input).to_dict()) |
| 1795 | + |
| 1796 | + def test_all_properties_header_divider(self): |
| 1797 | + input = { |
| 1798 | + "type": "container", |
| 1799 | + "title": {"type": "plain_text", "text": "Full Container"}, |
| 1800 | + "subtitle": {"type": "mrkdwn", "text": "A subtitle"}, |
| 1801 | + "child_blocks": [ |
| 1802 | + {"type": "section", "text": {"type": "mrkdwn", "text": "Content"}}, |
| 1803 | + ], |
| 1804 | + "width": "wide", |
| 1805 | + "icon": {"type": "image", "image_url": "https://example.com/img.png", "alt_text": "icon"}, |
| 1806 | + "has_header_divider": True, |
| 1807 | + "block_id": "container-2", |
| 1808 | + } |
| 1809 | + self.assertDictEqual(input, ContainerBlock(**input).to_dict()) |
| 1810 | + |
| 1811 | + def test_rich_text_title(self): |
| 1812 | + input = { |
| 1813 | + "type": "container", |
| 1814 | + "rich_text_title": { |
| 1815 | + "type": "rich_text", |
| 1816 | + "elements": [ |
| 1817 | + { |
| 1818 | + "type": "rich_text_section", |
| 1819 | + "elements": [{"type": "text", "text": "Rich Title"}], |
| 1820 | + } |
| 1821 | + ], |
| 1822 | + }, |
| 1823 | + "child_blocks": [ |
| 1824 | + {"type": "divider"}, |
| 1825 | + ], |
| 1826 | + } |
| 1827 | + self.assertDictEqual(input, ContainerBlock(**input).to_dict()) |
| 1828 | + |
| 1829 | + def test_width_values(self): |
| 1830 | + for width in ["narrow", "standard", "wide", "full"]: |
| 1831 | + input = { |
| 1832 | + "type": "container", |
| 1833 | + "title": {"type": "plain_text", "text": "Test"}, |
| 1834 | + "child_blocks": [{"type": "divider"}], |
| 1835 | + "width": width, |
| 1836 | + } |
| 1837 | + ContainerBlock(**input).validate_json() |
| 1838 | + |
| 1839 | + def test_invalid_width(self): |
| 1840 | + with self.assertRaises(SlackObjectFormationError): |
| 1841 | + ContainerBlock( |
| 1842 | + title={"type": "plain_text", "text": "Test"}, |
| 1843 | + child_blocks=[{"type": "divider"}], |
| 1844 | + width="extra_wide", |
| 1845 | + ).validate_json() |
| 1846 | + |
| 1847 | + def test_title_length_validation(self): |
| 1848 | + with self.assertRaises(SlackObjectFormationError): |
| 1849 | + ContainerBlock( |
| 1850 | + title={"type": "plain_text", "text": "a" * 151}, |
| 1851 | + child_blocks=[{"type": "divider"}], |
| 1852 | + ).validate_json() |
| 1853 | + |
| 1854 | + def test_subtitle_length_validation(self): |
| 1855 | + with self.assertRaises(SlackObjectFormationError): |
| 1856 | + ContainerBlock( |
| 1857 | + title={"type": "plain_text", "text": "Title"}, |
| 1858 | + subtitle={"type": "mrkdwn", "text": "a" * 151}, |
| 1859 | + child_blocks=[{"type": "divider"}], |
| 1860 | + ).validate_json() |
| 1861 | + |
| 1862 | + def test_missing_title_and_rich_text_title(self): |
| 1863 | + with self.assertRaises(SlackObjectFormationError): |
| 1864 | + ContainerBlock( |
| 1865 | + child_blocks=[{"type": "divider"}], |
| 1866 | + ).validate_json() |
| 1867 | + |
| 1868 | + def test_empty_child_blocks(self): |
| 1869 | + with self.assertRaises(SlackObjectFormationError): |
| 1870 | + ContainerBlock( |
| 1871 | + title={"type": "plain_text", "text": "Test"}, |
| 1872 | + child_blocks=[], |
| 1873 | + ).validate_json() |
| 1874 | + |
| 1875 | + def test_collapsible_with_header_divider(self): |
| 1876 | + with self.assertRaises(SlackObjectFormationError): |
| 1877 | + ContainerBlock( |
| 1878 | + title={"type": "plain_text", "text": "Test"}, |
| 1879 | + child_blocks=[{"type": "divider"}], |
| 1880 | + is_collapsible=True, |
| 1881 | + has_header_divider=True, |
| 1882 | + ).validate_json() |
| 1883 | + |
| 1884 | + |
1755 | 1885 | class CarouselBlockTests(unittest.TestCase): |
1756 | 1886 | def test_document(self): |
1757 | 1887 | input = { |
|
0 commit comments