Skip to content

Commit 3926355

Browse files
committed
creates a ghost user when github3.users.User is None
1 parent 08fe91c commit 3926355

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/github3/users.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,54 @@ class _User(models.GitHubCore):
307307

308308
class_name = "_User"
309309

310+
def __init__(self, json, session):
311+
if json is None:
312+
# from https://api.github.com/users/ghost
313+
json = {
314+
"login": "ghost",
315+
"id": 10137,
316+
"node_id": "MDQ6VXNlcjEwMTM3",
317+
"avatar_url": "https://avatars.githubusercontent.com/u/10137?v"
318+
"=4",
319+
"gravatar_id": "",
320+
"url": "https://api.github.com/users/ghost",
321+
"html_url": "https://github.com/ghost",
322+
"followers_url": "https://api.github.com/users/ghost/followers",
323+
"following_url": "https://api.github.com/users/ghost/following"
324+
"{/other_user}",
325+
"gists_url": "https://api.github.com/users/ghost/gists{/gist_id"
326+
"}",
327+
"starred_url": "https://api.github.com/users/ghost/starred{/own"
328+
"er}{/repo}",
329+
"subscriptions_url": "https://api.github.com/users/ghost/subscr"
330+
"iptions",
331+
"organizations_url": "https://api.github.com/users/ghost/orgs",
332+
"repos_url": "https://api.github.com/users/ghost/repos",
333+
"events_url": "https://api.github.com/users/ghost/events{/priva"
334+
"cy}",
335+
"received_events_url": "https://api.github.com/users/ghost/rece"
336+
"ived_events",
337+
"type": "User",
338+
"user_view_type": "public",
339+
"site_admin": False,
340+
"name": "Deleted user",
341+
"company": None,
342+
"blog": "",
343+
"location": "Nothing to see here, move along.",
344+
"email": None,
345+
"hireable": None,
346+
"bio": "Hi, I'm @ghost! I take the place of user accounts that "
347+
"have been deleted.\n:ghost:\n",
348+
"twitter_username": None,
349+
"public_repos": 0,
350+
"public_gists": 0,
351+
"followers": 11584,
352+
"following": 0,
353+
"created_at": "2008-05-13T06:14:25Z",
354+
"updated_at": "2018-04-10T17:22:33Z",
355+
}
356+
super().__init__(json, session)
357+
310358
def _update_attributes(self, user):
311359
self.avatar_url = user["avatar_url"]
312360
self.events_urlt = URITemplate(user["events_url"])
@@ -869,7 +917,7 @@ class AuthenticatedUser(User):
869917
"""Object to represent the currently authenticated user.
870918
871919
This is returned by :meth:`~github3.github.GitHub.me`. It contains the
872-
extra informtation that is not returned for other users such as the
920+
extra information that is not returned for other users such as the
873921
currently authenticated user's plan and private email information.
874922
875923
.. versionadded:: 1.0.0

tests/unit/test_users.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ def test_is_following(self):
6767
)
6868

6969

70+
class TestGhostUser(helper.UnitHelper):
71+
"""Test methods on Ghost User class."""
72+
73+
described_class = github3.users.User
74+
75+
def setUp(self):
76+
"""Use None to create a ghost user."""
77+
self.session = self.create_session_mock()
78+
self.old_build_url = None
79+
self.instance = github3.users.User(None, self.session)
80+
81+
def test_str(self):
82+
"""Show that instance string and repr is ghost."""
83+
assert str(self.instance) == "ghost"
84+
assert repr(self.instance) == "<User [ghost:Deleted user]>"
85+
86+
7087
class TestUserGPGKeyRequiresAuth(helper.UnitRequiresAuthenticationHelper):
7188
"""Unit tests that demonstrate which GPGKey methods require auth."""
7289

0 commit comments

Comments
 (0)