|
| 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