def test_pubsubhubbub(self): self.response('', 204) self.post('https://api.github.com/hub') body = [('hub.mode', 'subscribe'), ('hub.topic', 'https://github.com/foo/bar/events/push'), ('hub.callback', 'https://localhost/post')] self.conf = {} with expect.githuberror(): self.g.pubsubhubbub('', '', '') self.login() expect(self.g.pubsubhubbub('', '', '')).is_False() self.not_called() expect(self.g.pubsubhubbub('foo', 'https://example.com', 'foo')).is_False() self.not_called() d = dict([(k[4:], v) for k, v in body]) expect(self.g.pubsubhubbub(**d)).is_True() _, kwargs = self.request.call_args expect('data').is_in(kwargs) expect(body) == kwargs['data'] self.mock_assertions() d['secret'] = 'secret' body.append(('hub.secret', 'secret')) expect(self.g.pubsubhubbub(**d)).is_True() _, kwargs = self.request.call_args expect('data').is_in(kwargs) expect(body) == kwargs['data'] self.mock_assertions()
def test_iter_user_issues(self): self.response('issue', _iter=True) self.get('https://api.github.com/user/issues') self.conf.update(params={}) with expect.githuberror(): self.g.iter_user_issues() self.login() expect(next(self.g.iter_user_issues())).isinstance( github3.issues.Issue) self.mock_assertions() params = { 'filter': 'assigned', 'state': 'closed', 'labels': 'bug', 'sort': 'created', 'direction': 'asc', 'since': '2012-05-20T23:10:27Z' } self.conf.update(params=params) expect(next(self.g.iter_user_issues(**params))).isinstance( github3.issues.Issue) self.mock_assertions()
def test_edit(self): self.response('hook', 200) self.patch(self.api) data = { 'name': 'hookname', 'config': {'push': 'http://example.com'}, 'events': ['push'], 'add_events': ['fake_ev'], 'rm_events': ['fake_ev'], 'active': True, } self.conf = {'data': data.copy()} self.conf['data']['remove_events'] = data['rm_events'] del(self.conf['data']['rm_events']) with expect.githuberror(): self.hook.edit(**data) self.login() expect(self.hook.edit(None, None, None)).is_False() expect(self.hook.edit('True', None, None)).is_False() expect(self.hook.edit(None, 'True', None)).is_False() expect(self.hook.edit(None, None, {})).is_False() self.not_called() expect(self.hook.edit(**data)).is_True() self.mock_assertions()
def test_boolean(self): r = requests.Response() r.status_code = 512 r.raw = RequestsBytesIO('{}'.encode() if is_py3 else '{}') with expect.githuberror(): self.g._boolean(r, 200, 404)
def test_update(self): self.response('repo_comment', 200) self.post(self.api) data = { 'body': 'This is a comment body', 'sha': 'fakesha', 'line': 1, 'position': 1, 'path': 'github3/repos.py', } self.conf = {'data': data.copy()} self.conf['data']['commit_id'] = self.conf['data']['sha'] del(self.conf['data']['sha']) with expect.githuberror(): self.comment.update('foo', 'bar', 'bogus', 'jargon', 'files') self.login() expect(self.comment.update(None, 'f', 'o', 1, 1)).is_False() expect(self.comment.update('f', None, 'o', 1, 1)).is_False() expect(self.comment.update('f', 'o', 1, None, 1)).is_False() expect(self.comment.update('f', 'o', 0, 'o', 1)).is_False() expect(self.comment.update('f', 'o', 1, 'o', 0)).is_False() self.not_called() expect(self.comment.update(**data)).is_True() self.mock_assertions()
def test_boolean(self): r = requests.Response() r.status_code = 512 r.raw = BytesIO('{}'.encode() if is_py3 else '{}') with expect.githuberror(): self.g._boolean(r, 200, 404)
def test_create_tag(self): self.response('tag', 201) self.post(self.api + 'git/tags') data = { 'tag': '0.3', 'message': 'Fake message', 'object': 'fakesha', 'type': 'commit', 'tagger': { 'name': 'Ian Cordasco', 'date': 'Not a UTC date', 'email': '*****@*****.**' } } self.conf = {'data': data.copy()} data['obj_type'] = data['type'] data['sha'] = data['object'] del(data['type'], data['object']) with expect.githuberror(): self.repo.create_tag(None, None, None, None, None) self.login() with patch.object(github3.repos.Repository, 'create_ref'): expect(self.repo.create_tag(None, None, None, None, None)).is_None() tag = self.repo.create_tag(**data) expect(tag).isinstance(github3.git.Tag) expect(repr(tag).startswith('<Tag')).is_True() self.mock_assertions() with patch.object(github3.repos.Repository, 'create_ref') as cr: self.repo.create_tag('tag', '', 'fakesha', '', '', lightweight=True) cr.assert_called_once_with('refs/tags/tag', 'fakesha')
def test_create_issue(self): self.request.return_value = generate_response('issue', 201) title = 'Construct _api attribute on our own' self.args = ('POST', self.api + 'issues') self.conf = {'data': {'title': title}} with expect.githuberror(): self.repo.create_issue(title) self.login() expect(self.repo.create_issue(None)).is_None() expect(self.repo.create_issue(title)).isinstance(github3.issues.Issue) self.mock_assertions() body = 'Fake body' #self.conf['data'].update(body=body) expect(self.repo.create_issue(title, body) ).isinstance(github3.issues.Issue) self.mock_assertions() assignee, mile, labels = 'sigmavirus24', 1, ['bug', 'enhancement'] #self.conf['data'].update({'assignee': assignee, 'milestone': mile, # 'labels': labels}) expect(self.repo.create_issue(title, body, assignee, mile, labels) ).isinstance(github3.issues.Issue) self.mock_assertions()
def test_create_repo(self): self.response('repo', 201) self.post(self.api + '/repos') self.conf = { 'data': { 'name': 'repo', 'description': 'desc', 'homepage': '', 'private': False, 'has_issues': True, 'has_wiki': True, 'has_downloads': True, 'auto_init': False, 'team_id': 1, 'gitignore_template': '', } } with expect.githuberror(): self.org.create_repo(None) self.not_called() self.login() expect(self.org.create_repo('repo', 'desc', team_id=1)).isinstance( github3.repos.Repository) self.mock_assertions()
def test_pubsubhubbub(self): self.response('', 204) self.post('https://api.github.com/hub') body = [('hub.mode', 'subscribe'), ('hub.topic', 'https://github.com/foo/bar/events/push'), ('hub.callback', 'https://localhost/post')] self.conf = {} with expect.githuberror(): self.g.pubsubhubbub('', '', '') self.login() expect(self.g.pubsubhubbub('', '', '')).is_False() self.not_called() expect(self.g.pubsubhubbub('foo', 'https://example.com', 'foo') ).is_False() self.not_called() d = dict([(k[4:], v) for k, v in body]) expect(self.g.pubsubhubbub(**d)).is_True() _, kwargs = self.request.call_args expect('data').is_in(kwargs) expect(body) == kwargs['data'] self.mock_assertions() d['secret'] = 'secret' body.append(('hub.secret', 'secret')) expect(self.g.pubsubhubbub(**d)).is_True() _, kwargs = self.request.call_args expect('data').is_in(kwargs) expect(body) == kwargs['data'] self.mock_assertions()
def test_create_issue(self): self.response('issue', 201) title = 'Construct _api attribute on our own' self.post(self.api + 'issues') self.conf = {'data': {'title': title}} with expect.githuberror(): self.repo.create_issue(title) self.login() expect(self.repo.create_issue(None)).is_None() expect(self.repo.create_issue(title)).isinstance(github3.issues.Issue) self.mock_assertions() body = 'Fake body' #self.conf['data'].update(body=body) expect(self.repo.create_issue(title, body)).isinstance(github3.issues.Issue) self.mock_assertions() assignee, mile, labels = 'sigmavirus24', 1, ['bug', 'enhancement'] #self.conf['data'].update({'assignee': assignee, 'milestone': mile, # 'labels': labels}) expect(self.repo.create_issue(title, body, assignee, mile, labels)).isinstance(github3.issues.Issue) self.mock_assertions()
def test_update(self): self.response('authorization', 200) self.post(self.api) data = { 'scopes': ['user'] } self.conf = {'data': data} with expect.githuberror(): self.auth.update() def sub_test(): expect(self.auth.update(**data)).is_True() self.mock_assertions() self.login() expect(self.auth.update()).is_False() self.not_called() sub_test() del(data['scopes']) data['add_scopes'] = ['repo'] sub_test() del(data['add_scopes']) data['rm_scopes'] = ['user'] self.conf['data'] = {'remove_scopes': ['user']} sub_test() self.conf['data'] = data del(data['rm_scopes']) data['note'] = 'GitHub API' data['note_url'] = 'http://example.com' sub_test()
def test_reopen(self): with expect.githuberror(): self.pull.reopen() self.login() with patch.object(github3.pulls.PullRequest, 'update') as up: self.pull.reopen() up.assert_called_once_with(self.pull.title, self.pull.body, 'open')
def test_delete_email_address(self): with expect.githuberror(): self.user.delete_email_address('foo') self.not_called() self.login() with patch.object(github3.users.User, 'delete_email_addresses') as p: self.user.delete_email_address('foo') p.assert_called_once_with(['foo'])
def test_reopen(self): with expect.githuberror(): self.pull.reopen() self.login() with patch.object(github3.pulls.PullRequest, 'update') as up: self.pull.reopen() up.assert_called_once_with( self.pull.title, self.pull.body, 'open')
def test_star(self): self.response('', 204) self.put(self.api) with expect.githuberror(): self.gist.star() self.not_called() self.login() expect(self.gist.star()).is_True()
def test_delete(self): self.response('', 204) self.delete(self.api) with expect.githuberror(): self.l.delete() self.not_called() self.login() expect(self.l.delete()).is_True()
def test_remove_all_labels(self): with expect.githuberror(): self.i.remove_all_labels() self.login() with patch.object(github3.issues.Issue, 'replace_labels') as rl: rl.return_value = [] expect(self.i.remove_all_labels()) == [] rl.assert_called_once_with([])
def test_delete(self): self.response('', 204) self.delete(self.api[:-1]) self.conf = {} with expect.githuberror(): self.repo.delete() self.login() expect(self.repo.delete()).is_True() self.mock_assertions()
def test_delete_subscription(self): self.response('', 204) self.delete(self.api + '/subscription') with expect.githuberror(): self.hook.delete_subscription() self.not_called() self.login() expect(self.hook.delete_subscription()).is_True() self.mock_assertions()
def test_authorization(self): self.response('authorization') self.get('https://api.github.com/authorizations/10') with expect.githuberror(): self.g.authorization(10) assert self.request.called is False self.login() a = self.g.authorization(10) expect(a).isinstance(github3.auths.Authorization) self.mock_assertions()
def test_is_starred(self): self.response('', 204) self.get(self.api + '/star') with expect.githuberror(): self.gist.is_starred() self.not_called() self.login() expect(self.gist.is_starred()).is_True() self.mock_assertions()
def test_iter_keys(self): self.response('key', _iter=True) self.get(self.api + 'keys') with expect.githuberror(): self.repo.iter_keys() self.login() k = next(self.repo.iter_keys()) expect(k).isinstance(github3.users.Key) self.mock_assertions()
def test_admin_stats(self): self.response('user') self.get('https://github.example.com/api/v3/enterprise/stats/all') with expect.githuberror(): self.g.admin_stats(None) self.not_called() self.login() expect(self.g.admin_stats('all')).isinstance(dict) self.mock_assertions()
def test_remove_repo(self): self.response('', 204) self.delete(self.api + '/repos/repo') with expect.githuberror(): self.team.remove_repo(None) self.not_called() self.login() expect(self.team.remove_repo('repo')).is_True() self.mock_assertions()
def test_remove_label(self): self.response('', 204) self.delete(self.api + '/labels/name') with expect.githuberror(): self.i.remove_label('name') self.not_called() self.login() expect(self.i.remove_label('name')).is_True() self.mock_assertions()
def test_conceal_member(self): self.response('', 204) self.delete(self.api + '/public_members/user') with expect.githuberror(): self.org.conceal_member(None) self.not_called() self.login() expect(self.org.conceal_member('user')).is_True() self.mock_assertions()
def test_iter_teams(self): self.response('team', _iter=True) self.get(self.api + '/teams') with expect.githuberror(): self.org.iter_teams() self.not_called() self.login() expect(next(self.org.iter_teams())).isinstance(github3.orgs.Team) self.mock_assertions()
def test_delete(self): self.response('', 204) self.delete(self.api) with expect.githuberror(): self.dl.delete() self.not_called() self.login() expect(self.dl.delete()).is_True() self.mock_assertions()
def test_close(self): with expect.githuberror(): self.pull.close() self.login() with patch.object(github3.pulls.PullRequest, 'update') as up: up.return_value = True expect(self.pull.close()).is_True() up.assert_called_once_with( self.pull.title, self.pull.body, 'closed')
def test_remove_member(self): self.response('', 404) self.delete(self.api + '/members/user') with expect.githuberror(): self.org.remove_member(None) self.not_called() self.login() expect(self.org.remove_member('user')).is_False() self.mock_assertions()
def test_iter_keys(self): self.response('key', _iter=True) self.get('https://api.github.com/user/keys') self.conf.update(params=None) with expect.githuberror(): self.g.iter_keys() self.login() expect(next(self.g.iter_keys())).isinstance(github3.users.Key) self.mock_assertions()
def test_close(self): with expect.githuberror(): self.pull.close() self.login() with patch.object(github3.pulls.PullRequest, 'update') as up: up.return_value = True expect(self.pull.close()).is_True() up.assert_called_once_with(self.pull.title, self.pull.body, 'closed')
def test_add_collaborator(self): self.response('', 204) self.put(self.api + 'collaborators/sigmavirus24') self.conf = {'data': None} with expect.githuberror(): self.repo.add_collaborator('foo') self.login() expect(self.repo.add_collaborator(None)).is_False() expect(self.repo.add_collaborator('sigmavirus24')).is_True() self.mock_assertions()
def test_follow(self): self.response(None, 204) self.put('https://api.github.com/user/following/sigmavirus24') self.conf = {'data': None} with expect.githuberror(): self.g.follow('sigmavirus24') self.login() assert self.g.follow(None) is False assert self.g.follow('sigmavirus24') is True self.mock_assertions()
def test_unfollow(self): self.response('', 204) self.delete('https://api.github.com/user/following/' 'sigmavirus24') self.conf = {} with expect.githuberror(): self.g.unfollow('foo') self.login() expect(self.g.unfollow(None)).is_False() expect(self.g.unfollow('sigmavirus24')).is_True() self.mock_assertions()
def test_fork(self): self.response('gist', 201) self.post(self.api + '/forks') self.conf = {} with expect.githuberror(): self.gist.fork() self.not_called() self.login() expect(self.gist.fork()).isinstance(gists.Gist) self.mock_assertions()
def test_add_collaborator(self): self.request.return_value = generate_response('', 204) self.args = ('put', self.api + 'collaborators/sigmavirus24') self.conf = {'headers': {'Content-Length': '0'}, 'data': None} with expect.githuberror(): self.repo.add_collaborator('foo') self.login() expect(self.repo.add_collaborator(None)).is_False() expect(self.repo.add_collaborator('sigmavirus24')).is_True() self.mock_assertions()
def test_subscription(self): self.response('subscription') self.get(self.api + 'subscription') with expect.githuberror(): self.repo.subscription() self.not_called() self.login() s = self.repo.subscription() expect(s).isinstance(github3.notifications.Subscription) self.mock_assertions()
def test_create_key(self): self.response('key', 201) with expect.githuberror(): k = self.g.create_key(None, None) assert k is None assert self.request.called is False self.login() k = self.g.create_key('Name', 'Key') expect(k).isinstance(github3.users.Key) assert self.request.called is True
def test_key(self): self.response('key') self.get(self.api + 'keys/2') with expect.githuberror(): self.repo.key(2) self.login() expect(self.repo.key(-2)).is_None() self.not_called() expect(self.repo.key(2)).isinstance(github3.users.Key) self.mock_assertions()
def test_unstar(self): self.response('', 204) self.delete(self.api + '/star') self.conf = {} with expect.githuberror(): self.gist.unstar() self.not_called() self.login() expect(self.gist.unstar()).is_True() self.mock_assertions()
def test_star(self): self.response('', 204) self.put('https://api.github.com/user/starred/sigmavirus24/github3.py') self.conf = {'data': None} with expect.githuberror(): self.g.star('foo', 'bar') self.login() expect(self.g.star(None, None)).is_False() expect(self.g.star('sigmavirus24', 'github3.py')).is_True() self.mock_assertions()
def test_iter_hooks(self): self.response('hook', _iter=True) self.get(self.api + 'hooks') self.conf = {'params': None} with expect.githuberror(): self.repo.iter_hooks() self.login() h = next(self.repo.iter_hooks()) expect(h).isinstance(repos.hook.Hook) self.mock_assertions()
def test_iter_notifications(self): self.response('notification', _iter=True) self.get(self.api + 'notifications') self.conf.update(params={}) with expect.githuberror(): self.repo.iter_notifications() self.login() n = next(self.repo.iter_notifications()) expect(n).isinstance(github3.notifications.Thread) self.mock_assertions()
def test_hook(self): self.response('hook') self.get(self.api + 'hooks/2') with expect.githuberror(): self.repo.hook(2) self.login() expect(self.repo.hook(-2)).is_None() self.not_called() expect(self.repo.hook(2)).isinstance(repos.hook.Hook) self.mock_assertions()