diff --git a/AUTHORS.rst b/AUTHORS.rst index 81fddac7a..c6a7e4a1e 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -177,6 +177,8 @@ Contributors - James E. Blair (@jeblair) +- Tatsuya Matoba (@mtb-beta) + - Simon Westphahl (@westphahl) - Steven Nyman (@stevennyman) @@ -197,4 +199,4 @@ Contributors - Kevin P. Fleming (@kpfleming) -- Andrew Hayworth (@ahayworth) +- Andrew Hayworth (@ahayworth) \ No newline at end of file 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 89bac8029..fc7babffc 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -1542,3 +1542,64 @@ def test_str(self): assert str(self.instance) == "".format( enterprise_url_for() ) + + +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 + ) + 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], + )