|
| 1 | +import github3 |
| 2 | +import datetime |
| 3 | +from tests.utils import BaseCase, load, expect |
| 4 | + |
| 5 | + |
| 6 | +class TestThread(BaseCase): |
| 7 | + def __init__(self, methodName='runTest'): |
| 8 | + super(TestThread, self).__init__(methodName) |
| 9 | + self.thread = github3.notifications.Thread(load('notification')) |
| 10 | + self.api = ("https://api.github.com/notifications/threads/6169361") |
| 11 | + |
| 12 | + def test_last_read_at(self): |
| 13 | + json = self.thread.to_json().copy() |
| 14 | + json['last_read_at'] = '2013-12-31T23:59:59Z' |
| 15 | + t = github3.notifications.Thread(json) |
| 16 | + expect(t.last_read_at).isinstance(datetime.datetime) |
| 17 | + |
| 18 | + def test_repr(self): |
| 19 | + expect(repr(self.thread)) == '<Thread [{0}]>'.format( |
| 20 | + self.thread.subject.get('title')) |
| 21 | + |
| 22 | + def test_delete_subscription(self): |
| 23 | + self.response('', 204) |
| 24 | + self.delete(self.api + '/subscription') |
| 25 | + |
| 26 | + expect(self.thread.delete_subscription()).is_True() |
| 27 | + self.mock_assertions() |
| 28 | + |
| 29 | + def test_is_unread(self): |
| 30 | + expect(self.thread.is_unread()) == self.thread.unread |
| 31 | + |
| 32 | + def test_mark(self): |
| 33 | + self.response('', 205) |
| 34 | + self.patch(self.api) |
| 35 | + self.conf = {'data': {'read': True}} |
| 36 | + |
| 37 | + expect(self.thread.mark()).is_True() |
| 38 | + self.mock_assertions() |
| 39 | + |
| 40 | + def test_set_subscription(self): |
| 41 | + self.response('subscription') |
| 42 | + self.put(self.api + '/subscription') |
| 43 | + self.conf = {'data': {'subscribed': True, 'ignored': False}} |
| 44 | + |
| 45 | + expect(self.thread.set_subscription(True, False)).isinstance( |
| 46 | + github3.notifications.Subscription) |
| 47 | + self.mock_assertions() |
| 48 | + |
| 49 | + def test_subscription(self): |
| 50 | + self.response('subscription') |
| 51 | + self.get(self.api + '/subscription') |
| 52 | + |
| 53 | + expect(self.thread.subscription()).isinstance( |
| 54 | + github3.notifications.Subscription) |
| 55 | + self.mock_assertions() |
| 56 | + |
| 57 | + |
| 58 | +class TestSubscription(BaseCase): |
| 59 | + def __init__(self, methodName='runTest'): |
| 60 | + super(TestSubscription, self).__init__(methodName) |
| 61 | + self.subscription = github3.notifications.Subscription( |
| 62 | + load('subscription')) |
| 63 | + self.api = ("https://api.github.com/notifications/threads/5864188/" |
| 64 | + "subscription") |
| 65 | + |
| 66 | + def test_repr(self): |
| 67 | + expect(repr(self.subscription)) == '<Subscription [True]>' |
| 68 | + |
| 69 | + def test_delete(self): |
| 70 | + self.response('', 204) |
| 71 | + self.delete(self.api) |
| 72 | + |
| 73 | + expect(self.subscription.delete()).is_True() |
| 74 | + self.mock_assertions() |
| 75 | + |
| 76 | + def test_is_ignored(self): |
| 77 | + expect(self.subscription.is_ignored()) == self.subscription.ignored |
| 78 | + |
| 79 | + def test_is_subscription(self): |
| 80 | + subbed = self.subscription.is_subscribed() |
| 81 | + expect(subbed) == self.subscription.subscribed |
| 82 | + |
| 83 | + def test_set(self): |
| 84 | + self.response('subscription') |
| 85 | + self.put(self.api) |
| 86 | + self.conf = {'data': {'subscribed': True, 'ignored': False}} |
| 87 | + |
| 88 | + expect(self.subscription.set(True, False)).is_None() |
| 89 | + self.mock_assertions() |
0 commit comments