|
| 1 | +""" |
| 2 | +Comprehensive test suite for Android-Notify Tester (Laner.use_android_notify) |
| 3 | +Covers all notification styles, callbacks, and behaviors. |
| 4 | +""" |
| 5 | +import unittest |
| 6 | +import time |
| 7 | +import traceback |
| 8 | + |
| 9 | +from android_notify import Notification, NotificationStyles, NotificationHandler, send_notification |
| 10 | + |
| 11 | + |
| 12 | +class TestAndroidNotifyFull(unittest.TestCase): |
| 13 | + def tearDown(self): |
| 14 | + time.sleep(3) |
| 15 | + |
| 16 | + def setUp(self): |
| 17 | + max_int = 2_147_483_647 |
| 18 | + self.uid = int(time.time() * 1000) % max_int |
| 19 | + |
| 20 | + def test_simple(self): |
| 21 | + try: |
| 22 | + n = Notification( id=self.uid,title="Simple", message="Simple message test") |
| 23 | + n.send() |
| 24 | + except Exception as e: |
| 25 | + self.fail(f"Simple notification failed: {e}") |
| 26 | + |
| 27 | + def test_progress(self): |
| 28 | + try: |
| 29 | + n = Notification( id=self.uid,title="Downloading...", message="0% downloaded", progress_current_value=0, progress_max_value=100) |
| 30 | + n.send() |
| 31 | + for i in range(0, 101, 10): |
| 32 | + time.sleep(2) |
| 33 | + n.updateProgressBar(i, f"{i}% done") |
| 34 | + n.removeProgressBar(message="Done", title="Download Complete") |
| 35 | + except Exception as e: |
| 36 | + self.fail(f"Progress notification failed: {e}") |
| 37 | + |
| 38 | + def test_big_picture(self): |
| 39 | + try: |
| 40 | + n = Notification( id=self.uid,title="Big Picture", message="Testing big picture") |
| 41 | + n.setBigPicture("assets/icon.png") |
| 42 | + n.send() |
| 43 | + except Exception as e: |
| 44 | + self.fail(f"Big picture failed: {e}") |
| 45 | + |
| 46 | + def test_inbox(self): |
| 47 | + try: |
| 48 | + n = Notification( id=self.uid,title="Inbox", message="Inbox notification") |
| 49 | + n.setLines(["Line 1", "Line 2", "Line 3"]) |
| 50 | + n.send() |
| 51 | + except Exception as e: |
| 52 | + self.fail(f"Inbox notification failed: {e}") |
| 53 | + |
| 54 | + def test_inbox_from_file_message(self): |
| 55 | + try: |
| 56 | + lines = "Test1\nTest2\nTest3" |
| 57 | + n = Notification( id=self.uid,title="Inbox File", message="File Inbox Test", lines_txt=lines) |
| 58 | + n.send() |
| 59 | + except Exception as e: |
| 60 | + self.fail(f"Inbox from file failed: {e}") |
| 61 | + |
| 62 | + def test_inbox_add_line(self): |
| 63 | + try: |
| 64 | + n = Notification( id=self.uid,title="Inbox AddLine", message="Testing addLine()") |
| 65 | + n.addLine("First line") |
| 66 | + n.addLine("Second line") |
| 67 | + n.addLine("Third line") |
| 68 | + n.send() |
| 69 | + except Exception as e: |
| 70 | + self.fail(f"Inbox addLine failed: {e}") |
| 71 | + |
| 72 | + def test_large_icon(self): |
| 73 | + try: |
| 74 | + n = Notification( id=self.uid,title="Large Icon", message="Testing large icon") |
| 75 | + n.setLargeIcon("assets/icon.png") |
| 76 | + n.send() |
| 77 | + except Exception as e: |
| 78 | + self.fail(f"Large icon failed: {e}") |
| 79 | + |
| 80 | + def test_big_text(self): |
| 81 | + try: |
| 82 | + n = Notification( id=self.uid,title="Big Text", message="Testing big text") |
| 83 | + n.setBigText("Lorem Ipsum is dummy text for testing BigTextStyle display.") |
| 84 | + n.send() |
| 85 | + except Exception as e: |
| 86 | + self.fail(f"Big text failed: {e}") |
| 87 | + |
| 88 | + def test_buttons(self): |
| 89 | + try: |
| 90 | + n = Notification( id=self.uid,title="With Buttons", message="Testing action buttons") |
| 91 | + n.addButton(text="Play", on_release=lambda: print("Playing")) |
| 92 | + n.addButton(text="Pause", on_release=lambda: print("Paused")) |
| 93 | + n.addButton(text="Stop", on_release=lambda: print("Stopped")) |
| 94 | + n.send() |
| 95 | + except Exception as e: |
| 96 | + self.fail(f"Buttons failed: {e}") |
| 97 | + |
| 98 | + def test_both_imgs(self): |
| 99 | + try: |
| 100 | + n = Notification( id=self.uid,title="Both Images", message="Testing both large & big picture") |
| 101 | + n.setLargeIcon("assets/icon.png") |
| 102 | + n.setBigPicture("assets/icon.png") |
| 103 | + n.send() |
| 104 | + except Exception as e: |
| 105 | + self.fail(f"Both imgs failed: {e}") |
| 106 | + |
| 107 | + def test_custom_icon(self): |
| 108 | + try: |
| 109 | + n = Notification( id=self.uid,title="Custom Icon", message="Testing custom app icon") |
| 110 | + n.setSmallIcon("assets/icon.png") |
| 111 | + n.send() |
| 112 | + except Exception as e: |
| 113 | + self.fail(f"Custom icon failed: {e}") |
| 114 | + |
| 115 | + def test_title_message_update(self): |
| 116 | + try: |
| 117 | + n = Notification( id=self.uid,title="Old Title", message="Old Message") |
| 118 | + n.send() |
| 119 | + time.sleep(2) |
| 120 | + n.updateTitle("New Title") |
| 121 | + n.updateMessage("New Message") |
| 122 | + except Exception as e: |
| 123 | + self.fail(f"Update title/message failed: {e}") |
| 124 | + |
| 125 | + def test_download_channel(self): |
| 126 | + try: |
| 127 | + n = Notification( id=self.uid, |
| 128 | + title="Download Done", |
| 129 | + message="Your file finished downloading.", |
| 130 | + channel_name="Download Notifications", |
| 131 | + channel_id="downloads_notifications" |
| 132 | + ) |
| 133 | + n.send() |
| 134 | + except Exception as e: |
| 135 | + self.fail(f"Download channel failed: {e}") |
| 136 | + |
| 137 | + def test_channel_generate_id(self): |
| 138 | + try: |
| 139 | + n = Notification( id=self.uid, |
| 140 | + title="Generated Channel", |
| 141 | + message="Channel creation test", |
| 142 | + channel_name="Custom Channel" |
| 143 | + ) |
| 144 | + n.send() |
| 145 | + except Exception as e: |
| 146 | + self.fail(f"Channel generating ID failed: {e}") |
| 147 | + |
| 148 | + def test_custom_id(self): |
| 149 | + try: |
| 150 | + n = Notification( id=self.uid,title="Custom ID", message="Click to trigger handler", name="change_app_page") |
| 151 | + n.send() |
| 152 | + except Exception as e: |
| 153 | + self.fail(f"Custom ID failed: {e}") |
| 154 | + |
| 155 | + def test_callback(self): |
| 156 | + try: |
| 157 | + n = Notification( id=self.uid,title="With Callback", message="Tap to run callback", callback=lambda: print("Callback invoked")) |
| 158 | + n.send() |
| 159 | + except Exception as e: |
| 160 | + self.fail(f"Callback failed: {e}") |
| 161 | + |
| 162 | + def test_custom_channel_name(self): |
| 163 | + try: |
| 164 | + n = Notification( id=self.uid,title="Custom Channel", message="Testing custom name", channel_name="MyChannelName") |
| 165 | + n.send() |
| 166 | + except Exception as e: |
| 167 | + self.fail(f"Custom channel name failed: {e}") |
| 168 | + |
| 169 | + def test_cancel_all(self): |
| 170 | + try: |
| 171 | + Notification.cancelAll() |
| 172 | + except Exception as e: |
| 173 | + self.fail(f"Cancel all failed: {e}") |
| 174 | + |
| 175 | + def test_create_channel_lifespan(self): |
| 176 | + try: |
| 177 | + n = Notification( id=self.uid,title="Check ID Lifespan", message="Testing channel id reuse") |
| 178 | + cid = "test_channel_id" |
| 179 | + n.createChannel(id=cid, name="Test Channel", description="Lifespan check") |
| 180 | + n.send() |
| 181 | + except Exception as e: |
| 182 | + self.fail(f"Create channel lifespan failed: {e}") |
| 183 | + |
| 184 | + def test_persistent(self): |
| 185 | + try: |
| 186 | + n = Notification( id=self.uid,title="Persistent", message="This notification should persist") |
| 187 | + n.send(persistent=True) |
| 188 | + except Exception as e: |
| 189 | + self.fail(f"Persistent notification failed: {e}") |
| 190 | + |
| 191 | + # def test_get_active_notifications(self): |
| 192 | + # try: |
| 193 | + # Notification( id=self.uid,).get_active_notifications() |
| 194 | + # except Exception as e: |
| 195 | + # self.fail(f"Get active notifications failed: {e}") |
| 196 | + |
| 197 | + |
| 198 | +if __name__ == "__main__": |
| 199 | + unittest.main(verbosity=2) |
0 commit comments