-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update get_committer_data for latest PyGithub
v1.55 of PyGithub changed `get_emails` to return a named tuple (#1890) rather than a dict directly from the decoded API response. Update the code to access the fields as a property rather than by index & bump the pin so 1.55 is the minimum version. Also update the existing tests for the now required `headers` parameter on exception classes.
- Loading branch information
1 parent
17c2384
commit f5ed496
Showing
3 changed files
with
20 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
from collections import namedtuple | ||
from unittest import TestCase | ||
from pyup.providers.github import Provider | ||
from pyup.requirements import RequirementsBundle | ||
|
@@ -70,7 +72,7 @@ def test_get_default_branch(self): | |
"foo" | ||
) | ||
|
||
p = PropertyMock(side_effect=UnknownObjectException(data="", status=1)) | ||
p = PropertyMock(side_effect=UnknownObjectException(data="", status=1, headers={})) | ||
type(self.repo).default_branch = p | ||
with self.assertRaises(errors.RepoDoesNotExistError): | ||
self.provider.get_default_branch(self.repo) | ||
|
@@ -81,7 +83,7 @@ def test_get_pull_request_permissions(self): | |
self.provider.get_pull_request_permissions(user, self.repo) | ||
self.repo.add_to_collaborators.assert_called_once_with("some-dude") | ||
|
||
self.repo.add_to_collaborators.side_effect = GithubException(data="", status=1) | ||
self.repo.add_to_collaborators.side_effect = GithubException(data="", status=1, headers={}) | ||
with self.assertRaises(errors.NoPermissionError): | ||
self.provider.get_pull_request_permissions(user, self.repo) | ||
|
||
|
@@ -91,7 +93,7 @@ def test_iter_git_tree(self): | |
items = list(self.provider.iter_git_tree(self.repo, "some branch")) | ||
self.assertEqual(items, [("type", "path")]) | ||
|
||
self.repo.get_git_tree.side_effect = GithubException(data="", status=999) | ||
self.repo.get_git_tree.side_effect = GithubException(data="", status=999, headers={}) | ||
with self.assertRaises(GithubException): | ||
list(self.provider.iter_git_tree(self.repo, "some branch")) | ||
|
||
|
@@ -101,7 +103,7 @@ def test_get_file(self): | |
self.assertIsNotNone(obj) | ||
self.repo.get_contents.assert_called_with("path", ref="branch") | ||
|
||
self.repo.get_contents.side_effect = GithubException(data="", status=1) | ||
self.repo.get_contents.side_effect = GithubException(data="", status=1, headers={}) | ||
content, obj = self.provider.get_file(self.repo, "path", "branch") | ||
self.assertIsNone(content) | ||
self.assertIsNone(obj) | ||
|
@@ -127,7 +129,7 @@ def test_create_branch(self): | |
self.provider.create_branch(self.repo, "base branch", "new branch") | ||
self.repo.get_git_ref.assert_called_once_with("heads/base branch") | ||
|
||
self.repo.get_git_ref.side_effect = GithubException(data="", status=1) | ||
self.repo.get_git_ref.side_effect = GithubException(data="", status=1, headers={}) | ||
with self.assertRaises(errors.BranchExistsError): | ||
self.provider.create_branch(self.repo, "base branch", "new branch") | ||
|
||
|
@@ -167,7 +169,7 @@ def test_create_commit(self, time): | |
self.provider.create_commit("path", "branch", "commit", "content", "sha", self.repo, "com") | ||
self.assertEqual(self.repo.update_file.call_count, 1) | ||
|
||
self.repo.update_file.side_effect = GithubException(data="", status=1) | ||
self.repo.update_file.side_effect = GithubException(data="", status=1, headers={}) | ||
with self.assertRaises(GithubException): | ||
self.provider.create_commit("path", "branch", "commit", "content", "sha", self.repo, | ||
"com") | ||
|
@@ -211,7 +213,7 @@ def test_get_committer_data(self): | |
committer = Mock() | ||
committer.email = None | ||
committer.login = "foo" | ||
committer.get_emails.return_value = [{"primary": True, "email": "[email protected]"},] | ||
committer.get_emails.return_value = [namedtuple("EmailData", ["primary", "email"])(True, "[email protected]")] | ||
data = self.provider.get_committer_data(committer)._identity | ||
self.assertEqual(data["name"], "foo") | ||
self.assertEqual(data["email"], "[email protected]") | ||
|
@@ -231,7 +233,7 @@ def test_get_pull_request_committer(self): | |
data = self.provider.get_pull_request_committer(self.repo, pr) | ||
self.assertEqual(data, ["foo"]) | ||
|
||
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1) | ||
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1, headers={}) | ||
data = self.provider.get_pull_request_committer(self.repo, pr) | ||
self.assertEqual(data, []) | ||
|
||
|
@@ -247,7 +249,7 @@ def test_close_pull_request(self): | |
self.provider.close_pull_request(self.repo, self.repo, pr, "comment", prefix="pyup-") | ||
self.assertEqual(self.repo.get_git_ref().delete.call_count, 1) | ||
|
||
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1) | ||
self.repo.get_pull.side_effect = UnknownObjectException(data="", status=1, headers={}) | ||
data = self.provider.close_pull_request(self.repo, self.repo, Mock(), "comment", | ||
prefix="pyup-") | ||
self.assertEqual(data, False) | ||
|
@@ -263,7 +265,7 @@ def test_create_pull_request(self): | |
self.assertEqual(self.provider.bundle.get_pull_request_class.call_count, 1) | ||
self.assertEqual(self.provider.bundle.get_pull_request_class().call_count, 1) | ||
|
||
self.repo.create_pull.side_effect = GithubException(data="", status=1) | ||
self.repo.create_pull.side_effect = GithubException(data="", status=1, headers={}) | ||
with self.assertRaises(errors.NoPermissionError): | ||
self.provider.create_pull_request(self.repo, "title", "body", "master", "new", False, []) | ||
|
||
|
@@ -283,10 +285,10 @@ def test_create_pull_request_with_assignees(self): | |
def test_create_issue(self): | ||
self.assertIsNot(self.provider.create_issue(self.repo, "title", "body"), False) | ||
|
||
self.repo.create_issue.side_effect = GithubException(data="", status=404) | ||
self.repo.create_issue.side_effect = GithubException(data="", status=404, headers={}) | ||
self.assertEqual(self.provider.create_issue(self.repo, "title", "body"), False) | ||
|
||
self.repo.create_issue.side_effect = GithubException(data="", status=999) | ||
self.repo.create_issue.side_effect = GithubException(data="", status=999, headers={}) | ||
with self.assertRaises(GithubException): | ||
self.assertEqual(self.provider.create_issue(self.repo, "title", "body"), False) | ||
|
||
|
@@ -302,15 +304,15 @@ def test_get_or_create_label(self): | |
|
||
def test_create_label(self): | ||
# label does not exist, need to create it | ||
self.repo.get_label.side_effect = UnknownObjectException(None, None) | ||
self.repo.get_label.side_effect = UnknownObjectException(None, None, headers={}) | ||
self.provider.get_or_create_label(self.repo, "another-label") | ||
self.repo.get_label.assert_called_once_with(name="another-label") | ||
self.repo.create_label.assert_called_once_with(name="another-label", color="1BB0CE") | ||
|
||
def test_create_label_fails(self): | ||
# label does not exist, need to create it | ||
self.repo.get_label.side_effect = UnknownObjectException(None, None) | ||
self.repo.create_label.side_effect = GithubException(None, None) | ||
self.repo.get_label.side_effect = UnknownObjectException(None, None, headers={}) | ||
self.repo.create_label.side_effect = GithubException(None, None, headers={}) | ||
label = self.provider.get_or_create_label(self.repo, "another-label") | ||
self.assertIsNone(label) | ||
self.repo.get_label.assert_called_once_with(name="another-label") | ||
|