def test_comment(self): """ Adds a comment to a test issue and verifies the comment is added. TODO(LB): need to change the test setup so we're mocking the github stuff for this (or else the tests run as slow as Chris's Mom). """ class Comment(object): def __init__(self, dictionary): self.__dict__ = dictionary client = StubbedGithub(config=self.config, conn_class=FakeGithub) client.config["github"]["core_team"] = "test team 1" pull_request = client.pull_requests.values()[0] test_issue_id = 12345 comment_text = u"test comment text" # add the comment self.expect(utils.load(utils.testdata("comment.json"))) comment_result = pull_request.comment(comment_text) # now verify the comment was added self.expect([Comment(x) for x in utils.load(utils.testdata("comments.json"))["comments"]]) comments = self.client.github.issues.comments(self.config["github"]["repo"], test_issue_id) # filter the comments list by id comment = [x for x in comments if x.id == comment_result["id"]] # should only be one comment here self.assertTrue(len(comment) == 1) comment = comment[0] self.assertEqual(comment_text, comment.body)
def test_reject(self): class Issue(object): def __init__(self, dictionary): self.__dict__ = dictionary def _get_issue(issue_id): return self.client.github.issues.show(self.config["github"]["repo"], issue_id) test_pr_id = 1 reject_message = u"Merge failed" # TODO(LB): temporary -- repoen the pull request for this test # Remove this line once github mocking is in place self.expect(Issue(utils.load(utils.testdata("issue_open.json"))["issue"])) self.client.github.issues.reopen(self.config["github"]["repo"], test_pr_id) # verify the issue is open issue = _get_issue(test_pr_id) self.assertEqual(u"open", issue.state) # TODO(LB): need to mock up github here as well; see test_comment() client = StubbedGithub(config=self.config, conn_class=FakeGithub) client.config.github_core_team = "test team 1" pull_request = client.pull_requests.values()[0] self.expect(Issue(utils.load(utils.testdata("issue_closed.json"))["issue"])) rejected_issue = pull_request.close(reject_message) self.assertEqual(u"closed", rejected_issue.state)
def test_create_a_new_pull_request(self): pr_str = utils.load(utils.testdata('new_pull_request.json')) pr = pull_request.PullRequest(pr_str, self.pr_path) self.assertNothingRaised(pr.save,) self.assertTrue(os.path.exists(os.path.join(self.pr_path, "2", "pull.js"))) pr2 = pull_request.PullRequest.load(os.path.join(self.pr_path, "2")) self.assertEqual(pr._pull_request, pr2._pull_request)
def test_issue_137(self): """ GitHub sometimes returns `pull` as part of of the `html_url` for Issue requests. """ i = Issue(load('issue_137')) self.assertEqual(i.html_url, "https://github.com/sigmavirus24/github3.py/pull/1") self.assertEqual(i.repository, ("sigmavirus24", "github3.py"))
def test_delete_key(self): self.request.return_value = generate_response(None, 204) self.login() with patch.object(github3.github.GitHub, 'key') as key: key.return_value = github3.users.Key(load('key'), self.g) assert self.g.delete_key(10) is True assert self.request.called is True
def test_iter_issue_comments(self): pull = github3.pulls.PullRequest(load('pull19')) self.response('pull19_comment', _iter=True) self.get(pull.links['comments']) c = next(pull.iter_issue_comments()) assert isinstance(c, github3.issues.comment.IssueComment) self.mock_assertions() assert repr(c).startswith('<Issue Comment')
def test_issue_137(self): """ GitHub sometimes returns `pull` as part of of the `html_url` for Issue requests. """ i = Issue(load('issue_137')) self.assertEqual( i.html_url, "https://github.com/sigmavirus24/github3.py/pull/1") self.assertEqual(i.repository, ("sigmavirus24", "github3.py"))
def test_delete_key(self): self.response(None, 204) self.login() with patch.object(github3.github.GitHub, 'key') as key: key.return_value = github3.users.Key(load('key'), self.g) assert self.g.delete_key(10) is True key.return_value = None assert self.g.delete_key(10) is False assert self.request.called is True
def test_issue(self): self.response('issue', 200) self.get('https://api.github.com/repos/sigmavirus24/github3.py/' 'issues/1') assert self.g.issue(None, None, 0) is None with patch.object(github3.github.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository(load('repo')) i = self.g.issue('user', 'repo', 1) expect(i).isinstance(github3.issues.Issue) self.mock_assertions()
def test_iter_repo_issues(self): self.response('issue', _iter=True) self.get('https://api.github.com/repos/sigmavirus24/github3.py/' 'issues') with patch.object(github3.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository(load('repo'), self.g) i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py')) expect(i).isinstance(github3.issues.Issue) self.mock_assertions()
def test_update_user(self): self.login() args = ('Ian Cordasco', '*****@*****.**', 'www.blog.com', 'company', 'loc', True, 'bio') with patch.object(github3.github.GitHub, 'user') as user: with patch.object(github3.users.User, 'update') as upd: user.return_value = github3.users.User(load('user'), self.g) upd.return_value = True expect(self.g.update_user(*args)).is_True() expect(user.called).is_True() expect(upd.called).is_True() upd.assert_called_with(*args)
def test_pull_request(self): self.response('pull') self.get('https://api.github.com/repos/sigmavirus24/' 'github3.py/pulls/18') pr = None with patch.object(github3.github.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository(load('repo')) pr = self.g.pull_request('sigmavirus24', 'github3.py', 18) expect(pr).isinstance(github3.pulls.PullRequest) self.mock_assertions()
def test_iter_repo_issues(self): self.response('issue', _iter=True) self.get('https://api.github.com/repos/sigmavirus24/github3.py/' 'issues') with patch.object(github3.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository(load('repo'), self.g) i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py')) expect(i).isinstance(github3.issues.Issue) self.mock_assertions() with expect.raises(StopIteration): next(self.g.iter_repo_issues(None, None))
def test_iter_starred(self): self.response('repo', _iter=True) self.get('https://api.github.com/user/starred') self.conf.update(params={}) self.login() expect(next(self.g.iter_starred())).isinstance( github3.repos.Repository) self.mock_assertions() with patch.object(github3.github.GitHub, 'user') as user: user.return_value = github3.users.User(load('user')) self.get('https://api.github.com/users/sigmavirus24/starred') expect(next(self.g.iter_starred('sigmavirus24'))).isinstance( github3.repos.Repository) self.mock_assertions()
def test_iter_subscriptions(self): self.response('repo', _iter=True) self.get('https://api.github.com/user/subscriptions') self.conf.update(params={'per_page': 100}) self.login() assert isinstance(next(self.g.iter_subscriptions()), github3.repos.Repository) self.mock_assertions() with patch.object(github3.github.GitHub, 'user') as user: user.return_value = github3.users.User(load('user')) self.get('https://api.github.com/users/sigmavirus24/' 'subscriptions') assert isinstance(next(self.g.iter_subscriptions('sigmavirus24')), github3.repos.Repository) self.mock_assertions()
def test_create_issue(self): self.response('issue', 201) self.login() i = self.g.create_issue(None, None, None) assert i is None assert self.request.called is False i = self.g.create_issue('user', 'repo', '') assert i is None assert self.request.called is False with patch.object(github3.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository(load('repo'), self.g) i = self.g.create_issue('user', 'repo', 'Title') expect(i).isinstance(github3.issues.Issue) assert self.request.called is True
def test_iter_subscriptions(self): self.request.return_value = generate_response('repo', _iter=True) self.args = ('GET', 'https://api.github.com/user/subscriptions') self.conf.update(params=None) self.login() expect(next(self.g.iter_subscriptions())).isinstance( github3.repos.Repository) self.mock_assertions() with patch.object(github3.github.GitHub, 'user') as user: user.return_value = github3.users.User(load('user')) self.args = ('GET', 'https://api.github.com/users/sigmavirus24/' 'subscriptions' ) expect(next(self.g.iter_subscriptions('sigmavirus24'))).isinstance( github3.repos.Repository) self.mock_assertions()
def test_create_issue(self): self.response('issue', 201) self.login() i = self.g.create_issue(None, None, None) assert i is None assert self.request.called is False i = self.g.create_issue('user', 'repo', '') assert i is None assert self.request.called is False with patch.object(github3.GitHub, 'repository') as repo: repo.return_value = github3.repos.Repository( load('repo'), self.g) i = self.g.create_issue('user', 'repo', 'Title') expect(i).isinstance(github3.issues.Issue) assert self.request.called is True
def test_update_label(self): self.response('label') self.patch(self.api + 'labels/Bug') self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}} self.assertRaises(github3.GitHubError, self.repo.update_label, 'foo', 'bar') self.not_called() self.login() with patch.object(repos.Repository, 'label') as l: l.return_value = None assert self.repo.update_label('foo', 'bar') is False self.not_called() with patch.object(repos.Repository, 'label') as l: l.return_value = github3.issues.label.Label(load('label'), self.g) assert self.repo.update_label('big_bug', 'fafafa') self.mock_assertions()
def test_iter_following(self): self.response('user', _iter=True) self.get('https://api.github.com/users/sigmavirus24/following') self.conf.update(params={'per_page': 100}) self.assertRaises(github3.GitHubError, self.g.iter_following) assert self.request.called is False with patch.object(github3.github.GitHub, 'user') as ghuser: ghuser.return_value = github3.users.User(load('user')) u = next(self.g.iter_following('sigmavirus24')) assert isinstance(u, github3.users.User) self.mock_assertions() self.login() v = next(self.g.iter_following()) assert isinstance(v, github3.users.User) self.get('https://api.github.com/user/following') self.mock_assertions()
def test_update_label(self): self.response('label', 200) self.patch(self.api + 'labels/bug') self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}} with expect.githuberror(): self.repo.update_label('foo', 'bar') self.not_called() self.login() with patch.object(github3.repos.Repository, 'label') as l: l.return_value = None expect(self.repo.update_label('foo', 'bar')).is_False() self.not_called() with patch.object(github3.repos.Repository, 'label') as l: l.return_value = github3.issues.Label(load('label'), self.g) expect(self.repo.update_label('big_bug', 'fafafa')).is_True() self.mock_assertions()
def test_iter_following(self): self.response('user', _iter=True) self.get('https://api.github.com/users/sigmavirus24/following') self.conf.update(params=None) with expect.githuberror(): next(self.g.iter_following()) assert self.request.called is False with patch.object(github3.github.GitHub, 'user') as ghuser: ghuser.return_value = github3.users.User(load('user')) u = next(self.g.iter_following('sigmavirus24')) expect(u).isinstance(github3.users.User) self.mock_assertions() self.login() v = next(self.g.iter_following()) expect(v).isinstance(github3.users.User) self.get('https://api.github.com/user/following') self.mock_assertions()
def test_update_label(self): self.response('label') self.patch(self.api + 'labels/bug') self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}} with expect.githuberror(): self.repo.update_label('foo', 'bar') self.not_called() self.login() with patch.object(repos.Repository, 'label') as l: l.return_value = None expect(self.repo.update_label('foo', 'bar')).is_False() self.not_called() with patch.object(repos.Repository, 'label') as l: l.return_value = github3.issues.label.Label(load('label'), self.g) expect(self.repo.update_label('big_bug', 'fafafa')).is_True() self.mock_assertions()
def test_update_label(self): self.response('label') self.patch(self.api + 'labels/Bug') self.conf = {'data': {'name': 'big_bug', 'color': 'fafafa'}} self.assertRaises(github3.GitHubError, self.repo.update_label, 'foo', 'bar') self.not_called() self.login() with mock.patch.object(repos.Repository, 'label') as l: l.return_value = None assert self.repo.update_label('foo', 'bar') is False self.not_called() with mock.patch.object(repos.Repository, 'label') as l: l.return_value = github3.issues.label.Label(load('label'), self.g) assert self.repo.update_label('big_bug', 'fafafa') self.mock_assertions()
def __init__(self, methodName='runTest'): super(TestGist, self).__init__(methodName) self.gist = gists.Gist(load('gist')) self.api = 'https://api.github.com/gists/3813862'
def test_enterprise(self): Issue(load('issue_enterprise'))
def test_pull_request_issues(self): pr = github3.pulls.PullRequest(load('pull_request')) self.assertEqual( pr.issue_url, 'https://github.com/sigmavirus24/github3.py/pull/135')
def __init__(self, methodName='runTest'): super(TestTeam, self).__init__(methodName) self.team = github3.orgs.Team(load('team')) self.api = "https://api.github.com/teams/190009"
def test_equality(self): t = github3.orgs.Team(load('team')) assert self.team == t t.id = 'foo' assert self.team != t
def __init__(self, methodName='runTest'): super(TestLabel, self).__init__(methodName) self.l = github3.issues.Label(load('label')) self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" "labels/bug")
def test_equality(self): a = github3.auths.Authorization(load('authorization')) expect(self.auth) == a a.id = 1 expect(self.auth) != a
def __init__(self, methodName='runTest'): super(TestMilestone, self).__init__(methodName) self.m = Milestone(load('milestone')) self.api = ("https://api.github.com/repos/kennethreitz/requests/" "milestones/18")
def test_equality(self): e = IssueEvent(load('issue_event')) assert self.ev == e e._uniq = 'fake' assert self.ev != e
def setUp(self): super(TestIssueEvent, self).setUp() self.ev = IssueEvent(load('issue_event'))
def __init__(self, methodName='runTest'): super(TestPullRequest, self).__init__(methodName) self.pull = github3.pulls.PullRequest(load('pull')) self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" "pulls/18")
def __init__(self, methodName='runTest'): super(TestIssue, self).__init__(methodName) self.i = github3.issues.Issue(load('issue')) self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" "issues/1")
def __init__(self, methodName='runTest'): super(TestMilestone, self).__init__(methodName) self.m = github3.issues.Milestone(load('milestone')) self.api = ("https://api.github.com/repos/kennethreitz/requests/" "milestones/18")
def __init__(self, methodName='runTest'): super(TestUser, self).__init__(methodName) self.user = github3.users.User(load('user')) self.api = "https://api.github.com/users/sigmavirus24"
def __init__(self, methodName='runTest'): super(TestOrganization, self).__init__(methodName) self.org = github3.orgs.Organization(load('org')) self.api = "https://api.github.com/orgs/github3py"
def test_hashing(self): p = github3.pulls.PullRequest(load('pull')) s = set() s.add(p) s.add(p) assert len(s) == 1
def test_equality(self): assert self.org == github3.orgs.Organization(load('org'))
def test_equality(self): p = github3.pulls.PullRequest(load('pull')) assert self.pull == p p._uniq = 'foo' assert self.pull != p
def __init__(self, methodName='runTest'): super(TestRepository, self).__init__(methodName) self.repo = github3.repos.Repository(load('repo'))
def __init__(self, methodName='runTest'): super(TestLabel, self).__init__(methodName) self.l = Label(load('label')) self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" "labels/Bug")
def test_equality(self): i = Issue(load('issue')) assert self.i == i i._uniq = 1 assert self.i != i
def test_equality(self): h = gists.history.GistHistory(load('gist_history')) expect(self.hist) == h h.version = 'foo' expect(self.hist) != h
def __init__(self, methodName='runTest'): super(TestIssue, self).__init__(methodName) self.i = Issue(load('issue')) self.api = ("https://api.github.com/repos/sigmavirus24/github3.py/" "issues/1")
def test_equality(self): l = Label(load('label')) assert self.l == l l._uniq = ("https://api.github.com/repos/sigmavirus24/github3.py/" "labels/wontfix") assert self.l != l
def __init__(self, methodName='runTest'): super(TestKey, self).__init__(methodName) self.key = github3.users.Key(load('key')) self.api = "https://api.github.com/user/keys/10"
def test_enterprise(self): github3.pulls.PullRequest(load('pull_enterprise'))
def __init__(self, methodName='runTest'): super(TestAuthorization, self).__init__(methodName) self.auth = github3.auths.Authorization(load('authorization')) self.api = "https://api.github.com/authorizations/10"
def test_equality(self): u = github3.users.User(load('user')) assert self.user == u u._uniq += 1 assert self.user != u