Skip to content

Commit 0ce9a93

Browse files
committed
Merge branch 'mattchung-pr449' into develop
2 parents ccdf55d + b17c5c2 commit 0ce9a93

File tree

7 files changed

+171
-65
lines changed

7 files changed

+171
-65
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ Contributors
104104
- Noel Lee (@noellee)
105105

106106
- Sourav Singh(@souravsingh)
107+
108+
- Matt Chung (@itsmemattchung)

tests/test_notifications.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import github3
2-
import datetime
32
from tests.utils import BaseCase, load
43

54

@@ -9,49 +8,6 @@ def __init__(self, methodName='runTest'):
98
self.thread = github3.notifications.Thread(load('notification'))
109
self.api = ("https://api.github.com/notifications/threads/6169361")
1110

12-
def test_equality(self):
13-
t = github3.notifications.Thread(load('notification'))
14-
assert self.thread == t
15-
t._uniq = 1
16-
assert self.thread != t
17-
18-
def test_last_read_at(self):
19-
json = self.thread.as_dict().copy()
20-
json['last_read_at'] = '2013-12-31T23:59:59Z'
21-
t = github3.notifications.Thread(json)
22-
assert isinstance(t.last_read_at, datetime.datetime)
23-
24-
def test_repr(self):
25-
assert repr(self.thread) == '<Thread [{0}]>'.format(
26-
self.thread.subject.get('title'))
27-
28-
def test_delete_subscription(self):
29-
self.response('', 204)
30-
self.delete(self.api + '/subscription')
31-
32-
assert self.thread.delete_subscription()
33-
self.mock_assertions()
34-
35-
def test_is_unread(self):
36-
assert self.thread.is_unread() == self.thread.unread
37-
38-
def test_mark(self):
39-
self.response('', 205)
40-
self.patch(self.api)
41-
self.conf = {}
42-
43-
assert self.thread.mark()
44-
self.mock_assertions()
45-
46-
def test_set_subscription(self):
47-
self.response('subscription')
48-
self.put(self.api + '/subscription')
49-
self.conf = {'data': {'subscribed': True, 'ignored': False}}
50-
51-
assert isinstance(self.thread.set_subscription(True, False),
52-
github3.notifications.Subscription)
53-
self.mock_assertions()
54-
5511
def test_subscription(self):
5612
self.response('subscription')
5713
self.get(self.api + '/subscription')
@@ -69,23 +25,6 @@ def __init__(self, methodName='runTest'):
6925
self.api = ("https://api.github.com/notifications/threads/5864188/"
7026
"subscription")
7127

72-
def test_repr(self):
73-
assert isinstance(repr(self.subscription), str)
74-
75-
def test_delete(self):
76-
self.response('', 204)
77-
self.delete(self.api)
78-
79-
assert self.subscription.delete()
80-
self.mock_assertions()
81-
82-
def test_is_ignored(self):
83-
assert self.subscription.is_ignored() == self.subscription.ignored
84-
85-
def test_is_subscription(self):
86-
subbed = self.subscription.is_subscribed()
87-
assert subbed == self.subscription.subscribed
88-
8928
def test_set(self):
9029
self.response('subscription')
9130
self.put(self.api)

tests/unit/helper.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ def create_instance_of_described_class(self):
8787

8888
return instance
8989

90-
def patch_called_with(self, *args, **kwargs):
91-
"""Use to assert patch was called with JSON."""
92-
assert self.session.patch.called is True
93-
call_args, call_kwargs = self.session.patch.call_args
90+
def method_called_with(self, method_name, args, kwargs):
91+
"""Assert that a method was called on a session with JSON."""
92+
mock_method = getattr(self.session, method_name)
93+
assert mock_method.called is True
94+
call_args, call_kwargs = mock_method.call_args
9495

9596
# Data passed to assertion
9697
data = kwargs.pop('data', None)
@@ -108,6 +109,10 @@ def patch_called_with(self, *args, **kwargs):
108109
assert data == call_data
109110
assert kwargs == call_kwargs
110111

112+
def patch_called_with(self, *args, **kwargs):
113+
"""Use to assert patch was called with JSON."""
114+
self.method_called_with('patch', args, kwargs)
115+
111116
def post_called_with(self, *args, **kwargs):
112117
"""Use to assert post was called with JSON."""
113118
assert self.session.post.called is True
@@ -126,6 +131,10 @@ def post_called_with(self, *args, **kwargs):
126131
assert data == call_data
127132
assert kwargs == call_kwargs
128133

134+
def put_called_with(self, *args, **kwargs):
135+
"""Use to assert put was called with JSON."""
136+
self.method_called_with('put', args, kwargs)
137+
129138
def setUp(self):
130139
"""Use to set up attributes on self before each test."""
131140
self.session = self.create_session_mock()

tests/unit/notification_example

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"id": "1",
3+
"repository": {
4+
"id": 1296269,
5+
"owner": {
6+
"login": "octocat",
7+
"id": 1,
8+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/octocat",
11+
"html_url": "https://github.com/octocat",
12+
"followers_url": "https://api.github.com/users/octocat/followers",
13+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
17+
"organizations_url": "https://api.github.com/users/octocat/orgs",
18+
"repos_url": "https://api.github.com/users/octocat/repos",
19+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/octocat/received_events",
21+
"type": "User",
22+
"site_admin": false
23+
},
24+
"name": "Hello-World",
25+
"full_name": "octocat/Hello-World",
26+
"description": "This your first repo!",
27+
"private": false,
28+
"fork": false,
29+
"url": "https://api.github.com/repos/octocat/Hello-World",
30+
"html_url": "https://github.com/octocat/Hello-World"
31+
},
32+
"subject": {
33+
"title": "Greetings",
34+
"url": "https://api.github.com/repos/octokit/octokit.rb/issues/123",
35+
"latest_comment_url": "https://api.github.com/repos/octokit/octokit.rb/issues/comments/123",
36+
"type": "Issue"
37+
},
38+
"reason": "subscribed",
39+
"unread": true,
40+
"updated_at": "2014-11-07T22:01:45Z",
41+
"last_read_at": "2014-11-07T22:01:45Z",
42+
"url": "https://api.github.com/notifications/threads/1"
43+
}

tests/unit/subscription_example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"subscribed": true,
3+
"ignored": false,
4+
"reason": null,
5+
"created_at": "2012-10-06T21:34:12Z",
6+
"url": "https://api.github.com/notifications/threads/1/subscription",
7+
"thread_url": "https://api.github.com/notifications/threads/1"
8+
}

tests/unit/test_notifications.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import github3
2+
3+
from .helper import (UnitHelper, create_example_data_helper, create_url_helper)
4+
5+
get_example_data = create_example_data_helper('notification_example')
6+
url_for = create_url_helper(
7+
'https://api.github.com/notifications/threads/1'
8+
)
9+
10+
11+
class TestThread(UnitHelper):
12+
"""Notification unit tests."""
13+
14+
described_class = github3.notifications.Thread
15+
example_data = get_example_data()
16+
17+
def test_equality(self):
18+
"""Test equality/inequality between two instances."""
19+
thread = github3.notifications.Thread(get_example_data())
20+
assert self.instance == thread
21+
thread._uniq = 1
22+
assert self.instance != thread
23+
24+
def test_is_unread(self):
25+
"""Show that is_unread() equals unread property."""
26+
assert self.instance.is_unread() == self.instance.unread
27+
28+
def test_repr(self):
29+
"""Show instance string is formatted correctly."""
30+
assert repr(self.instance) == '<Thread [{0}]>'.format(
31+
self.instance.subject.get('title'))
32+
33+
def test_delete_description(self):
34+
"""Show that a user can delete a subscription."""
35+
self.instance.delete_subscription()
36+
37+
self.session.delete.assert_called_once_with(url_for('subscription'))
38+
39+
def test_mark(self):
40+
"""Show that a user can mark the subscription."""
41+
self.instance.mark()
42+
43+
self.session.patch.assert_called_once_with(url_for())
44+
45+
def test_set_subscription(self):
46+
"""Show that a user can subscribe to notification."""
47+
self.instance.set_subscription(True, False)
48+
49+
self.put_called_with(
50+
url_for('subscription'),
51+
data={"ignored": False, "subscribed": True},
52+
)
53+
54+
def test_subscription(self):
55+
"""Show that a user can retrieve a subscription."""
56+
self.instance.subscription()
57+
58+
self.session.get.assert_called_once_with(
59+
url_for('subscription'),
60+
)

tests/unit/test_subscription.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import github3
2+
3+
from .helper import (UnitHelper, create_url_helper, create_example_data_helper)
4+
5+
get_example_data = create_example_data_helper('subscription_example')
6+
url_for = create_url_helper(
7+
'https://api.github.com/notifications/threads/1/subscription'
8+
)
9+
10+
11+
class TestSubscription(UnitHelper):
12+
"""Subscription unit tests."""
13+
14+
described_class = github3.notifications.Subscription
15+
example_data = get_example_data()
16+
17+
def test_repr(self):
18+
"""Show that instance is formatted as a string when printed."""
19+
assert isinstance(repr(self.instance), str)
20+
21+
def test_delete(self):
22+
"""Show that a user can delete a subscription."""
23+
self.instance.delete()
24+
25+
self.session.delete.assert_called_once_with(
26+
url_for()
27+
)
28+
29+
def test_is_ignored(self):
30+
"""Show that subscription is ignored."""
31+
self.instance.is_ignored() == self.instance.ignored
32+
33+
def test_is_subscription(self):
34+
"""Show that subscription is subscribed."""
35+
self.instance.is_subscribed() == self.instance.subscribed
36+
37+
def test_set(self):
38+
"""Show that a user can set a subscription."""
39+
self.instance._update_attributes = lambda *args: None
40+
self.instance.set(True, False)
41+
42+
self.put_called_with(
43+
url_for(),
44+
data={"ignored": False, "subscribed": True},
45+
)

0 commit comments

Comments
 (0)