|
| 1 | +from matterhook.attachments import Attachment |
| 2 | + |
| 3 | + |
| 4 | +class TestAttachmentInit: |
| 5 | + def test_minimal(self): |
| 6 | + att = Attachment(fallback="fallback text") |
| 7 | + assert att.fallback == "fallback text" |
| 8 | + assert att.color is None |
| 9 | + assert att.pretext is None |
| 10 | + assert att.text is None |
| 11 | + assert att.author_name is None |
| 12 | + assert att.author_link is None |
| 13 | + assert att.author_icon is None |
| 14 | + assert att.title is None |
| 15 | + assert att.title_link is None |
| 16 | + assert att.fields is None |
| 17 | + assert att.image_url is None |
| 18 | + assert att.thumb_url is None |
| 19 | + |
| 20 | + def test_all_params(self): |
| 21 | + fields = [{"short": True, "title": "F", "value": "V"}] |
| 22 | + att = Attachment( |
| 23 | + fallback="fb", |
| 24 | + color="#FF0000", |
| 25 | + pretext="pre", |
| 26 | + text="body", |
| 27 | + author_name="author", |
| 28 | + author_link="https://author.com", |
| 29 | + author_icon="https://author.com/icon.png", |
| 30 | + title="Title", |
| 31 | + title_link="https://title.com", |
| 32 | + fields=fields, |
| 33 | + image_url="https://image.png", |
| 34 | + thumb_url="https://thumb.png", |
| 35 | + ) |
| 36 | + assert att.fallback == "fb" |
| 37 | + assert att.color == "#FF0000" |
| 38 | + assert att.pretext == "pre" |
| 39 | + assert att.text == "body" |
| 40 | + assert att.author_name == "author" |
| 41 | + assert att.author_link == "https://author.com" |
| 42 | + assert att.author_icon == "https://author.com/icon.png" |
| 43 | + assert att.title == "Title" |
| 44 | + assert att.title_link == "https://title.com" |
| 45 | + assert att.fields == fields |
| 46 | + assert att.image_url == "https://image.png" |
| 47 | + assert att.thumb_url == "https://thumb.png" |
| 48 | + |
| 49 | + |
| 50 | +class TestAttachmentPayload: |
| 51 | + def test_minimal_payload(self): |
| 52 | + att = Attachment(fallback="fb") |
| 53 | + assert att.payload == {"fallback": "fb"} |
| 54 | + |
| 55 | + def test_full_payload(self): |
| 56 | + fields = [{"short": True, "title": "F", "value": "V"}] |
| 57 | + att = Attachment( |
| 58 | + fallback="fb", |
| 59 | + color="#FF0000", |
| 60 | + pretext="pre", |
| 61 | + text="body", |
| 62 | + author_name="author", |
| 63 | + author_link="https://author.com", |
| 64 | + author_icon="https://author.com/icon.png", |
| 65 | + title="Title", |
| 66 | + title_link="https://title.com", |
| 67 | + fields=fields, |
| 68 | + image_url="https://image.png", |
| 69 | + thumb_url="https://thumb.png", |
| 70 | + ) |
| 71 | + assert att.payload == { |
| 72 | + "fallback": "fb", |
| 73 | + "color": "#FF0000", |
| 74 | + "pretext": "pre", |
| 75 | + "text": "body", |
| 76 | + "author_name": "author", |
| 77 | + "author_link": "https://author.com", |
| 78 | + "author_icon": "https://author.com/icon.png", |
| 79 | + "title": "Title", |
| 80 | + "title_link": "https://title.com", |
| 81 | + "fields": fields, |
| 82 | + "image_url": "https://image.png", |
| 83 | + "thumb_url": "https://thumb.png", |
| 84 | + } |
| 85 | + |
| 86 | + def test_partial_payload_only_color(self): |
| 87 | + att = Attachment(fallback="fb", color="#00FF00") |
| 88 | + assert att.payload == {"fallback": "fb", "color": "#00FF00"} |
| 89 | + |
| 90 | + def test_partial_payload_only_text(self): |
| 91 | + att = Attachment(fallback="fb", text="hello") |
| 92 | + assert att.payload == {"fallback": "fb", "text": "hello"} |
| 93 | + |
| 94 | + def test_partial_payload_author_fields(self): |
| 95 | + att = Attachment( |
| 96 | + fallback="fb", |
| 97 | + author_name="a", |
| 98 | + author_link="https://a.com", |
| 99 | + author_icon="https://a.com/i.png", |
| 100 | + ) |
| 101 | + assert att.payload == { |
| 102 | + "fallback": "fb", |
| 103 | + "author_name": "a", |
| 104 | + "author_link": "https://a.com", |
| 105 | + "author_icon": "https://a.com/i.png", |
| 106 | + } |
| 107 | + |
| 108 | + def test_partial_payload_title_fields(self): |
| 109 | + att = Attachment( |
| 110 | + fallback="fb", title="T", title_link="https://t.com" |
| 111 | + ) |
| 112 | + assert att.payload == { |
| 113 | + "fallback": "fb", |
| 114 | + "title": "T", |
| 115 | + "title_link": "https://t.com", |
| 116 | + } |
| 117 | + |
| 118 | + def test_partial_payload_image_fields(self): |
| 119 | + att = Attachment( |
| 120 | + fallback="fb", |
| 121 | + image_url="https://img.png", |
| 122 | + thumb_url="https://thumb.png", |
| 123 | + ) |
| 124 | + assert att.payload == { |
| 125 | + "fallback": "fb", |
| 126 | + "image_url": "https://img.png", |
| 127 | + "thumb_url": "https://thumb.png", |
| 128 | + } |
| 129 | + |
| 130 | + def test_partial_payload_pretext(self): |
| 131 | + att = Attachment(fallback="fb", pretext="before") |
| 132 | + assert att.payload == {"fallback": "fb", "pretext": "before"} |
| 133 | + |
| 134 | + def test_partial_payload_fields(self): |
| 135 | + fields = [{"short": False, "title": "X", "value": "Y"}] |
| 136 | + att = Attachment(fallback="fb", fields=fields) |
| 137 | + assert att.payload == {"fallback": "fb", "fields": fields} |
0 commit comments