8000 Fix up migrated unit tests for Matt Chung · christhompson/github3.py@b17c5c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit b17c5c2

Browse files
committed
Fix up migrated unit tests for Matt Chung
1 parent 1aa6189 commit b17c5c2

File tree

5 files changed

+96
-125
lines changed

5 files changed

+96
-125
lines changed

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: 41 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,43 @@
11
{
2-
"id": "6169361",
3-
"last_read_at": null,
4-
"reason": "subscribed",
5-
"repository": {
6-
"archive_url": "https://api.github.com/repos/kennethreitz/requests/{archive_format}{/ref}",
7-
"assignees_url": "https://api.github.com/repos/kennethreitz/requests/assignees{/user}",
8-
"blobs_url": "https://api.github.com/repos/kennethreitz/requests/git/blobs{/sha}",
9-
"branches_url": "https://api.github.com/repos/kennethreitz/requests/branches{/branch}",
10-
"collaborators_url": "https://api.github.com/repos/kennethreitz/requests/collaborators{/collaborator}",
11-
"comments_url": "https://api.github.com/repos/kennethreitz/requests/comments{/number}",
12-
"commits_url": "https://api.github.com/repos/kennethreitz/requests/commits{/sha}",
13-
"compare_url": "https://api.github.com/repos/kennethreitz/requests/compare/{base}...{head}",
14-
"contents_url": "https://api.github.com/repos/kennethreitz/requests/contents/{+path}",
15-
"contributors_url": "https://api.github.com/repos/kennethreitz/requests/contributors",
16-
"description": "Python HTTP Requests for Humans\u2122.",
17-
"downloads_url": "https://api.github.com/repos/kennethreitz/requests/downloads",
18-
"events_url": "https://api.github.com/repos/kennethreitz/requests/events",
19-
"fork": false,
20-
"forks_url": "https://api.github.com/repos/kennethreitz/requests/forks",
21-
"full_name": "kennethreitz/requests",
22-
"git_commits_url": "https://api.github.com/repos/kennethreitz/requests/git/commits{/sha}",
23-
"git_refs_url": "https://api.github.com/repos/kennethreitz/requests/git/refs{/sha}",
24-
"git_tags_url": "https://api.github.com/repos/kennethreitz/requests/git/tags{/sha}",
25-
"hooks_url": "https://api.github.com/repos/kennethreitz/requests/hooks",
26-
"html_url": "https://github.com/kennethreitz/requests",
27-
"id": 1362490,
28-
"issue_comment_url": "https://api.github.com/repos/kennethreitz/requests/issues/comments/{number}",
29-
"issue_events_url": "https://api.github.com/repos/kennethreitz/requests/issues/events{/number}",
30-
"issues_url": "https://api.github.com/repos/kennethreitz/requests/issues{/number}",
31-
"keys_url": "https://api.github.com/repos/kennethreitz/requests/keys{/key_id}",
32-
"labels_url": "https://api.github.com/repos/kennethreitz/requests/labels{/name}",
33-
"languages_url": "https://api.github.com/repos/kennethreitz/requests/languages",
34-
"merges_url": "https://api.github.com/repos/kennethreitz/requests/merges",
35-
"milestones_url": "https://api.github.com/repos/kennethreitz/requests/milestones{/number}",
36-
"name": "requests",
37-
"notifications_url": "https://api.github.com/repos/kennethreitz/requests/notifications{?since,all,participating}",
38-
"owner": {
39-
"avatar_url": "https://secure.gravatar.com/avatar/2eccc4005572c1e2b12a9c00580bc86f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
40-
"events_url&q A3E2 uot;: "https://api.github.com/users/kennethreitz/events{/privacy}",
41-
"followers_url": "https://api.github.com/users/kennethreitz/followers",
42-
"following_url": "https://api.github.com/users/kennethreitz/following{/other_user}",
43-
"gists_url": "https://api.github.com/users/kennethreitz/gists{/gist_id}",
44-
"gravatar_id": "2eccc4005572c1e2b12a9c00580bc86f",
45-
"html_url": "https://github.com/kennethreitz",
46-
"id": 119893,
47-
"login": "kennethreitz",
48-
"organizations_url": "https://api.github.com/users/kennethreitz/orgs",
49-
"received_events_url": "https://api.github.com/users/kennethreitz/received_events",
50-
"repos_url": "https://api.github.com/users/kennethreitz/repos",
51-
"starred_url": "https://api.github.com/users/kennethreitz/starred{/owner}{/repo}",
52-
"subscriptions_url": "https://api.github.com/users/kennethreitz/subscriptions",
53-
"type": "User",
54-
"url": "https://api.github.com/users/kennethreitz"
55-
},
56-
"private": false,
57-
"pulls_url": "https://api.github.com/repos/kennethreitz/requests/pulls{/number}",
58-
"stargazers_url": "https://api.github.com/repos/kennethreitz/requests/stargazers",
59-
"statuses_url": "https://api.github.com/repos/kennethreitz/requests/statuses/{sha}",
60-
"subscribers_url": "https://api.github.com/repos/kennethreitz/requests/subscribers",
61-
"subscription_url": "https://api.github.com/repos/kennethreitz/requests/subscription",
62-
"tags_url": "https://api.github.com/repos/kennethreitz/requests/tags",
63-
"teams_url": "https://api.github.com/repos/kennethreitz/requests/teams",
64-
"trees_url": "https://api.github.com/repos/kennethreitz/requests/git/trees{/sha}",
65-
"url": "https://api.github.com/repos/kennethreitz/requests"
66-
},
67-
"subject": {
68-
"latest_comment_url": "https://api.github.com/repos/kennethreitz/requests/issues/1106",
69-
"title": "Result of 'response' hook is stored in session.response and not returned",
70-
"type": "Issue",
71-
"url": "https://api.github.com/repos/kennethreitz/requests/issues/1106"
72-
},
73-
"subscription_url": "https://api.github.com/notifications/threads/6169361/subscription",
74-
"unread": null,
75-
"updated_at": "2013-01-17T15:27:54Z",
76-
"url": "https://api.github.com/notifications/threads/6169361"
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"
7743
}

tests/unit/subscription_example

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"created_at": "2013-02-12T04:43:09Z",
3-
"ignored": true,
4-
"reason": "",
5-
"subscribed": false,
6-
"thread_url": "https://api.github.com/notifications/threads/5864188",
7-
"url": "https://api.github.com/notifications/threads/5864188/subscription"
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"
88
}

tests/unit/test_notifications.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,60 @@
11
import github3
2-
import datetime
32

43
from .helper import (UnitHelper, create_example_data_helper, create_url_helper)
54

6-
get_notification_example_data = create_example_data_helper('notification_example')
5+
get_example_data = create_example_data_helper('notification_example')
76
url_for = create_url_helper(
8-
'https://api.github.com/notifications/threads/6169361'
7+
'https://api.github.com/notifications/threads/1'
98
)
109

1110

1211
class TestThread(UnitHelper):
1312
"""Notification unit tests."""
1413

1514
described_class = github3.notifications.Thread
16-
example_data = get_notification_example_data()
15+
example_data = get_example_data()
1716

1817
def test_equality(self):
19-
"""Test equality/inequality between two instances"""
20-
thread = github3.notifications.Thread(get_notification_example_data())
18+
"""Test equality/inequality between two instances."""
19+
thread = github3.notifications.Thread(get_example_data())
2120
assert self.instance == thread
2221
thread._uniq = 1
2322
assert self.instance != thread
2423

2524
def test_is_unread(self):
26-
"""Show that is_unread() equals unread property"""
25+
"""Show that is_unread() equals unread property."""
2726
assert self.instance.is_unread() == self.instance.unread
2827

29-
def test_last_read_at(self):
30-
"""Show that last_read_at attribute is a datetime type"""
31-
json = self.instance.as_dict().copy()
32-
json['last_read_at'] = '2013-12-31T23:59:59Z'
33-
thread = github3.notifications.Thread(json)
34-
assert isinstance(thread.last_read_at, datetime.datetime)
35-
3628
def test_repr(self):
37-
"""Show instance string is formatted correctly"""
29+
"""Show instance string is formatted correctly."""
3830
assert repr(self.instance) == '<Thread [{0}]>'.format(
3931
self.instance.subject.get('title'))
4032

4133
def test_delete_description(self):
42-
"""Show that a user can delete a subscription"""
34+
"""Show that a user can delete a subscription."""
4335
self.instance.delete_subscription()
4436

4537
self.session.delete.assert_called_once_with(url_for('subscription'))
4638

4739
def test_mark(self):
48-
"""Show that a user can mark the subscription"""
40+
"""Show that a user can mark the subscription."""
4941
self.instance.mark()
5042

51-
assert self.session.patch.called
43+
self.session.patch.assert_called_once_with(url_for())
5244

5345
def test_set_subscription(self):
54-
"""Show that a user can subscribe to nofication"""
55-
46+
"""Show that a user can subscribe to notification."""
5 F440 647
self.instance.set_subscription(True, False)
5748

58-
self.session.put.assert_called_once_with(
49+
self.put_called_with(
5950
url_for('subscription'),
60-
data='{"ignored": false, "subscribed": true}'
51+
data={"ignored": False, "subscribed": True},
6152
)
6253

6354
def test_subscription(self):
64-
pass
65-
# subscription = self.instance.subscription()
66-
# Need to figure out why this fails
67-
# assert isinstance(subscription, github3.notifications.Subscription)
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: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,44 @@
22

33
from .helper import (UnitHelper, create_url_helper, create_example_data_helper)
44

5-
get_subscription_example_data = create_example_data_helper('subscription_example')
5+
get_example_data = create_example_data_helper('subscription_example')
66
url_for = create_url_helper(
7-
'https://api.github.com/notifications/threads/5864188/subscription'
7+
'https://api.github.com/notifications/threads/1/subscription'
88
)
99

1010

1111
class TestSubscription(UnitHelper):
12+
"""Subscription unit tests."""
13+
1214
described_class = github3.notifications.Subscription
13-
example_data = get_subscription_example_data()
15+
example_data = get_example_data()
1416

1517
def test_repr(self):
16-
"""Show that instance is formatted as a string when printed"""
18+
"""Show that instance is formatted as a string when printed."""
1719
assert isinstance(repr(self.instance), str)
1820

1921
def test_delete(self):
20-
"""Show that a user can delete a subscription"""
22+
"""Show that a user can delete a subscription."""
2123
self.instance.delete()
2224

2325
self.session.delete.assert_called_once_with(
2426
url_for()
2527
)
2628

2729
def test_is_ignored(self):
28-
"""Show that subscription is ignored"""
30+
"""Show that subscription is ignored."""
2931
self.instance.is_ignored() == self.instance.ignored
3032

3133
def test_is_subscription(self):
32-
"""Show that subscription is subscribed"""
34+
"""Show that subscription is subscribed."""
3335
self.instance.is_subscribed() == self.instance.subscribed
3436

3537
def test_set(self):
36-
"""Show that a user can set a subscription"""
37-
pass
38-
# Test is currently failing due to session._put returns None
39-
# self.instance.set(True, False)
40-
# self.session.put.assert_called_once_with(
41-
# url_for()
42-
# )
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)
0