Created
October 23, 2017 12:55
-
-
Save zrzka/2f8e2f4bcfb81964cd472dab6039a00a to your computer and use it in GitHub Desktop.
Sample test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
import unittest | |
import notification | |
# https://github.com/omz/Pythonista-Issues/issues/21 | |
class TestScheduledNotifications(unittest.TestCase): | |
delay = 300 # Keep it in the distant future, so, it won't fire during tests | |
count = 10 | |
def setUp(self): | |
notification.cancel_all() | |
def test_notifications_are_scheduled(self): | |
for i in range(self.count): | |
notification.schedule(f'{i}', delay=self.delay + i) | |
notes = sorted(notification.get_scheduled(), key=lambda x: x['fire_date']) | |
for i, note in enumerate(notes): | |
assert(note['message'] == f'{i}') | |
notification.cancel_all() | |
def test_notification_is_cancelable(self): | |
for i in range(self.count): | |
notification.schedule(f'{i}', delay=self.delay) | |
notes = notification.get_scheduled() | |
for i, note in enumerate(notes): | |
assert(len(notification.get_scheduled()) == self.count - i) | |
notification.cancel(note) | |
assert(not notification.get_scheduled()) | |
def tearDown(self): | |
notification.cancel_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment