From b5104c102f4d690a204216934ccf91c7d9a11716 Mon Sep 17 00:00:00 2001 From: Tatsuya Matoba Date: Fri, 30 Nov 2018 08:18:08 +0000 Subject: [PATCH 1/5] add test case reproduce #797 bug --- tests/unit/test_github.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index 82a5dd727..fa61da161 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -1572,3 +1572,46 @@ def test_status(self): with helper.mock.patch.object(GitHubStatus, "_recipe") as _recipe: self.instance.status() _recipe.assert_called_once_with("api", "status.json") + + +class TestGitHubIssue797(helper.UnitHelper): + described_class = GitHub + + def test_issue_797(self): + """user auth without user scope""" + import mock + without_user_scope_json = { + "login": "hogehoge", + "id": 1, + "node_id": "xxxxxxxx", + "avatar_url": "https://github.com/images/error/hogehoge.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/hogehoge", + "html_url": "https://github.com/hogehoge", + "followers_url": "https://api.github.com/users/hogehoge/followers", + "following_url": "https://api.github.com/users/hogehoge/following{/other_user}", + "gists_url": "https://api.github.com/users/hogehoge/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hogehoge/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hogehoge/subscriptions", + "organizations_url": "https://api.github.com/users/hogehoge/orgs", + "repos_url": "https://api.github.com/users/hogehoge/repos", + "events_url": "https://api.github.com/users/hogehoge/events{/privacy}", + "received_events_url": "https://api.github.com/users/hogehoge/received_events", + "type": "User", + "site_admin": False, + "name": "fugafuga hogehoge", + "company": "GitHub", + "blog": "https://example.com/blog", + "location": "Tokyo", + "email": "hogehoge@example.com", + "hireable": False, + "bio": "There once was...", + "public_repos": 2, + "public_gists": 1, + "followers": 20, + "following": 0, + "created_at": "2018-11-30T09:25:26Z", + "updated_at": "2018-11-30T09:38:56Z" + } + self.session.get.return_value = mock.Mock(status_code=200, json=lambda: without_user_scope_json) + self.instance.me() From b32c487904883a1fdc3213dc7fc7f21344ffccf3 Mon Sep 17 00:00:00 2001 From: Tatsuya Matoba Date: Fri, 30 Nov 2018 09:22:25 +0000 Subject: [PATCH 2/5] bug fix #797 --- src/github3/users.py | 19 +++++++++++++++---- tests/unit/test_github.py | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/github3/users.py b/src/github3/users.py index 119a58741..26230479b 100644 --- a/src/github3/users.py +++ b/src/github3/users.py @@ -885,10 +885,21 @@ class AuthenticatedUser(User): def _update_attributes(self, user): super(AuthenticatedUser, self)._update_attributes(user) - self.disk_usage = user["disk_usage"] - self.owned_private_repos_count = user["owned_private_repos"] - self.total_private_repos_count = user["total_private_repos"] - self.plan = user.get("plan") + user_can_be_see = { + "disk_usage": None, + "owned_private_repos_count": None, + "total_private_repos_count": None, + "plan": None, + } + user_can_be_see.update(user) + self.disk_usage = user_can_be_see["disk_usage"] + self.owned_private_repos_count = user_can_be_see[ + "owned_private_repos_count" + ] + self.total_private_repos_count = user_can_be_see[ + "total_private_repos_count" + ] + self.plan = user_can_be_see.get("plan") if self.plan is not None: self.plan = Plan(self.plan, self) diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index fa61da161..6e773c833 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -1580,6 +1580,7 @@ class TestGitHubIssue797(helper.UnitHelper): def test_issue_797(self): """user auth without user scope""" import mock + without_user_scope_json = { "login": "hogehoge", "id": 1, @@ -1611,7 +1612,18 @@ def test_issue_797(self): "followers": 20, "following": 0, "created_at": "2018-11-30T09:25:26Z", - "updated_at": "2018-11-30T09:38:56Z" + "updated_at": "2018-11-30T09:38:56Z", } - self.session.get.return_value = mock.Mock(status_code=200, json=lambda: without_user_scope_json) - self.instance.me() + self.session.get.return_value = mock.Mock( + status_code=200, json=lambda: without_user_scope_json + ) + user = self.instance.me() + self.assertEqual( + [ + user.disk_usage, + user.owned_private_repos_count, + user.total_private_repos_count, + user.plan, + ], + [None, None, None, None], + ) From 48e0261624eddf7ed43f0f7f83f4731ac039a2f8 Mon Sep 17 00:00:00 2001 From: Tatsuya Matoba Date: Fri, 30 Nov 2018 09:36:35 +0000 Subject: [PATCH 3/5] update AUTHORS.rst --- AUTHORS.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index ee86602b3..6e6ad8410 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -176,3 +176,6 @@ Contributors - Andreas Burger (@AndreasBurger) - James E. Blair (@jeblair) + +- Tatsuya Matoba (@mtb-beta) + From 192dd7570158186c34438b586b7f96279a1a00bf Mon Sep 17 00:00:00 2001 From: Tatsuya Matoba Date: Mon, 3 Dec 2018 04:09:55 +0000 Subject: [PATCH 4/5] fixed warning of flake8 --- tests/unit/test_github.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index 6e773c833..20169047a 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -1590,14 +1590,20 @@ def test_issue_797(self): "url": "https://api.github.com/users/hogehoge", "html_url": "https://github.com/hogehoge", "followers_url": "https://api.github.com/users/hogehoge/followers", - "following_url": "https://api.github.com/users/hogehoge/following{/other_user}", - "gists_url": "https://api.github.com/users/hogehoge/gists{/gist_id}", - "starred_url": "https://api.github.com/users/hogehoge/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/hogehoge/subscriptions", + "following_url": + "https://api.github.com/users/hogehoge/following{/other_user}", + "gists_url": + "https://api.github.com/users/hogehoge/gists{/gist_id}", + "starred_url": + "https://api.github.com/users/hogehoge/starred{/owner}{/repo}", + "subscriptions_url": + "https://api.github.com/users/hogehoge/subscriptions", "organizations_url": "https://api.github.com/users/hogehoge/orgs", "repos_url": "https://api.github.com/users/hogehoge/repos", - "events_url": "https://api.github.com/users/hogehoge/events{/privacy}", - "received_events_url": "https://api.github.com/users/hogehoge/received_events", + "events_url": + "https://api.github.com/users/hogehoge/events{/privacy}", + "received_events_url": + "https://api.github.com/users/hogehoge/received_events", "type": "User", "site_admin": False, "name": "fugafuga hogehoge", From 5b34be7927326f5f9241bae04a63bf181e7f12b4 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Wed, 12 Aug 2020 14:02:30 -0700 Subject: [PATCH 5/5] Remove accidental test reintroduction Bad merge commit --- tests/unit/test_github.py | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index 6354ea55f..fc7babffc 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -1544,37 +1544,6 @@ def test_str(self): ) -class TestGitHubStatus(helper.UnitHelper): - - """Test methods on GitHubStatus.""" - - described_class = GitHubStatus - - def test_api(self): - """Verify the request for /api.""" - with helper.mock.patch.object(GitHubStatus, "_recipe") as _recipe: - self.instance.api() - _recipe.assert_called_once_with("api.json") - - def test_last_message(self): - """Verify the request for /api/last-message.""" - with helper.mock.patch.object(GitHubStatus, "_recipe") as _recipe: - self.instance.last_message() - _recipe.assert_called_once_with("api", "last-message.json") - - def test_messages(self): - """Verify the request for /api/messages.""" - with helper.mock.patch.object(GitHubStatus, "_recipe") as _recipe: - self.instance.messages() - _recipe.assert_called_once_with("api", "messages.json") - - def test_status(self): - """Verify the request for /api/status.""" - with helper.mock.patch.object(GitHubStatus, "_recipe") as _recipe: - self.instance.status() - _recipe.assert_called_once_with("api", "status.json") - - class TestGitHubIssue797(helper.UnitHelper): described_class = GitHub