8000 events are now at 100% coverag · tpetr/github3.py@e9fd507 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9fd507

Browse files
committed
events are now at 100% coverag
1 parent be98b3d commit e9fd507

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ History/Changelog
4545
was overridden in the Gist object and would cause otherwise unexpected
4646
results.
4747

48+
- ``github3.events.Event.is_public()`` and ``github3.events.Event.public`` now
49+
return the same information. In the next version, the former will be
50+
removed.
51+
4852
- Now we won't get spurious GitHubErrors on 404s, only on other expected
4953
errors whilst accessing the json in a response. All methods that return an
5054
object can now *actually* return None if it gets a 404 instead of just

github3/events.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def __init__(self, event):
3838
self.repo = event.get('repo')
3939
if self.repo is not None:
4040
self.repo = tuple(self.repo['name'].split('/'))
41-
self._public = event.get('public')
41+
#: Indicates whether the Event is public or not.
42+
self.public = event.get('public')
4243

4344
def __repr__(self):
4445
return '<Event [{0}]>'.format(self.type[:-5])
@@ -51,9 +52,11 @@ def list_types():
5152
def is_public(self):
5253
"""Indicates whether the Event is public or not.
5354
55+
.. warning:: This will be deprecated in 0.6
56+
5457
:returns: bool -- True if event is pubic, False otherwise
5558
"""
56-
return self._public
59+
return self.public
5760

5861

5962
def _commitcomment(payload):

tests/json/issue_comment

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"body": "The single dyno Heroku App would work fine. I just need to see if I can implement a server with pyKerberos.", "body_text": "The single dyno Heroku App would work fine. I just need to see if I can implement a server with pyKerberos.", "url": "https://api.github.com/repos/requests/requests-kerberos/issues/comments/10426578", "created_at": "2012-11-15T21:36:58Z", "updated_at": "2012-11-15T21:36:58Z", "body_html": "<p>The single dyno Heroku App would work fine. I just need to see if I can implement a server with pyKerberos.</p>", "user": {"following_url": "https://api.github.com/users/sigmavirus24/following", "events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}", "organizations_url": "https://api.github.com/users/sigmavirus24/orgs", "url": "https://api.github.com/users/sigmavirus24", "gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/c148356d89f925e692178bee1d93acf7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/sigmavirus24/repos", "received_events_url": "https://api.github.com/users/sigmavirus24/received_events", "gravatar_id": "c148356d89f925e692178bee1d93acf7", "starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}", "login": "sigmavirus24", "type": "User", "id": 240830, "followers_url": "https://api.github.com/users/sigmavirus24/followers"}, "id": 10426578, "issue_url": "https://api.github.com/repos/requests/requests-kerberos/issues/8399700"}

tests/json/review_comment

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"body": "is the 31 chars limit in the PEP 8 recommendations?", "original_position": 191, "url": "https://api.github.com/repos/jcrocholl/pep8/pulls/comments/2504908", "created_at": "2012-12-26T19:16:17Z", "updated_at": "2012-12-26T19:16:17Z", "_links": {"self": {"href": "https://api.github.com/repos/jcrocholl/pep8/pulls/comments/2504908"}, "html": {"href": "https://github.com/jcrocholl/pep8/pull/121#discussion_r2504908"}, "pull_request": {"href": "https://api.github.com/repos/jcrocholl/pep8/pulls/121"}}, "commit_id": "0fd8a5b37b52cd8c499baa786e95a6609a200130", "user": {"following_url": "https://api.github.com/users/florentx/following", "events_url": "https://api.github.com/users/florentx/events{/privacy}", "organizations_url": "https://api.github.com/users/florentx/orgs", "url": "https://api.github.com/users/florentx", "gists_url": "https://api.github.com/users/florentx/gists{/gist_id}", "subscriptions_url": "https://api.github.com/users/florentx/subscriptions", "avatar_url": "https://secure.gravatar.com/avatar/df4a6858794ecf84eae5afb37bf276ba?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", "repos_url": "https://api.github.com/users/florentx/repos", "received_events_url": "https://api.github.com/users/florentx/received_events", "gravatar_id": "df4a6858794ecf84eae5afb37bf276ba", "starred_url": "https://api.github.com/users/florentx/starred{/owner}{/repo}", "login": "florentx", "type": "User", "id": 142113, "followers_url": "https://api.github.com/users/florentx/followers"}, "path": "pep8.py", "position": 191, "original_commit_id": "0fd8a5b37b52cd8c499baa786e95a6609a200130", "id": 2504908}

tests/test_events.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import github3
2+
from tests.utils import BaseCase, expect, load
3+
from unittest import TestCase
4+
5+
6+
class TestEvent(BaseCase):
7+
def __init__(self, methodName='runTest'):
8+
super(TestEvent, self).__init__(methodName)
9+
self.ev = github3.events.Event(load('event'))
10+
self.o = load('org')
11+
12+
def setUp(self):
13+
super(TestEvent, self).setUp()
14+
self.ev = github3.events.Event(self.ev.to_json())
15+
16+
def test_org(self):
17+
json = self.ev.to_json().copy()
18+
json['org'] = self.o
19+
ev = github3.events.Event(json)
20+
expect(ev.org).isinstance(github3.orgs.Organization)
21+
22+
def test_repr(self):
23+
expect(repr(self.ev).startswith('<Event')).is_True()
24+
25+
def test_list_types(self):
26+
Event, handlers = (github3.events.Event,
27+
github3.events._payload_handlers)
28+
expect(Event.list_types()) == sorted(handlers.keys())
29+
30+
def test_is_public(self):
31+
expect(self.ev.is_public()) == self.ev.public
32+
33+
34+
class TestPayloadHandlers(TestCase):
35+
def test_commitcomment(self):
36+
comment = {'comment': load('repo_comment')}
37+
comment = github3.events._commitcomment(comment)
38+
expect(comment['comment']).isinstance(github3.repos.RepoComment)
39+
40+
def test_download(self):
41+
dl = {'download': load('download')}
42+
dl = github3.events._download(dl)
43+
expect(dl['download']).isinstance(github3.repos.Download)
44+
45+
def test_follow(self):
46+
f = {'target': load('user')}
47+
github3.events._follow(f)
48+
expect(f['target']).isinstance(github3.users.User)
49+
50+
def test_forkev(self):
51+
f = {'forkee': load('repo')}
52+
github3.events._forkev(f)
53+
expect(f['forkee']).isinstance(github3.repos.Repository)
54+
55+
def test_gist(self):
56+
g = {'gist': load('gist')}
57+
github3.events._gist(g)
58+
expect(g['gist']).isinstance(github3.gists.Gist)
59+
60+
def test_issuecomm(self):
61+
c E7AA = {'issue': load('issue'), 'comment': load('issue_comment')}
62+
github3.events._issuecomm(c)
63+
expect(c['issue']).isinstance(github3.issues.Issue)
64+
expect(c['comment']).isinstance(github3.issues.IssueComment)
65+
66+
def test_issueevent(self):
67+
c = {'issue': load('issue')}
68+
github3.events._issueevent(c)
69+
expect(c['issue']).isinstance(github3.issues.Issue)
70+
71+
def test_member(self):
72+
m = {'member': load('user')}
73+
github3.events._member(m)
74+
expect(m['member']).isinstance(github3.users.User)
75+
76+
def test_pullreqev(self):
77+
p = {'pull_request': load('pull')}
78+
github3.events._pullreqev(p)
79+
expect(p['pull_request']).isinstance(github3.pulls.PullRequest)
80+
81+
def test_pullreqcomm(self):
82+
p = {'comment': load('review_comment')}
83+
github3.events._pullreqcomm(p)
84+
expect(p['comment']).isinstance(github3.pulls.ReviewComment)
85+
86+
def test_team(payload):
87+
t = {'team': load('team'), 'repo': load('repo'), 'user': load('user')}
88+
github3.events._team(t)
89+
expect(t['team']).isinstance(github3.orgs.Team)
90+
expect(t['repo']).isinstance(github3.repos.Repository)
91+
expect(t['user']).isinstance(github3.users.User)

0 commit comments

Comments
 (0)
0