Skip to content

Fixed error that happened to try get user information without user scope #911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ Contributors

- James E. Blair (@jeblair)

- Tatsuya Matoba (@mtb-beta)

- Simon Westphahl (@westphahl)

- Steven Nyman (@stevennyman)
Expand All @@ -197,4 +199,4 @@ Contributors

- Kevin P. Fleming (@kpfleming)

- Andrew Hayworth (@ahayworth)
- Andrew Hayworth (@ahayworth)
19 changes: 15 additions & 4 deletions src/github3/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean "seen"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_can_be_see = {
user_can_be_seen = {

"disk_usage": None,
"owned_private_repos_count": None,
"total_private_repos_count": None,
"plan": None,
}
user_can_be_see.update(user)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_can_be_see.update(user)
user_can_be_seen.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")
Comment on lines +895 to +902
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
self.disk_usage = user_can_be_seen["disk_usage"]
self.owned_private_repos_count = user_can_be_seen[
"owned_private_repos_count"
]
self.total_private_repos_count = user_can_be_seen[
"total_private_repos_count"
]
self.plan = user_can_be_seen.get("plan")

if self.plan is not None:
self.plan = Plan(self.plan, self)

Expand Down
61 changes: 61 additions & 0 deletions tests/unit/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,3 +1542,64 @@ def test_str(self):
assert str(self.instance) == "<GitHub Enterprise [{0}]>".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],
)