10000 Merge pull request #813 from electrofelix/convert-plan-attr-option · admdev8/github3.py@8a0d314 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a0d314

Browse files
authored
Merge pull request sigmavirus24#813 from electrofelix/convert-plan-attr-option
Make plan attribute in authenticated user response optional
2 parents 2425b4a + a89d49a commit 8a0d314

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

github3/users.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,14 @@ class AuthenticatedUser(User):
744744
745745
.. attribute:: plan
746746
747+
.. note::
748+
749+
When used with a Github Enterprise instance <= 2.12.7, this
750+
attribute will not be returned. To handle these situations
751+
sensitively, the attribute will be set to ``None``.
752+
Repositories may still have a license associated with them
753+
in these cases.
754+
747755
The name of the plan that you, the user, have purchased
748756
"""
749757

@@ -754,4 +762,6 @@ def _update_attributes(self, user):
754762
self.disk_usage = user['disk_usage']
755763
self.owned_private_repos_count = user['owned_private_repos']
756764
self.total_private_repos_count = user['total_private_repos']
757-
self.plan = Plan(user['plan'], self)
765+
self.plan = user.get('plan')
766+
if self.plan is not None:
767+
self.plan = Plan(self.plan, self)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"login": "octocat",
3+
" 8000 id": 1,
4+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
5+
"gravatar_id": "",
6+
"url": "https://api.github.com/users/octocat",
7+
"html_url": "https://github.com/octocat",
8+
"followers_url": "https://api.github.com/users/octocat/followers",
9+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
10+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
11+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
12+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
13+
"organizations_url": "https://api.github.com/users/octocat/orgs",
14+
"repos_url": "https://api.github.com/users/octocat/repos",
15+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
16+
"received_events_url": "https://api.github.com/users/octocat/received_events",
17+
"type": "User",
18+
"site_admin": false,
19+
"name": "monalisa octocat",
20+
"company": "GitHub",
21+
"blog": "https://github.com/blog",
22+
"location": "San Francisco",
23+
"email": "octocat@github.com",
24+
"hireable": false,
25+
"bio": "There once was...",
26+
"public_repos": 2,
27+
"public_gists": 1,
28+
"followers": 20,
29+
"following": 0,
30+
"created_at": "2008-01-14T04:33:35Z",
31+
"updated_at": "2008-01-14T04:33:35Z",
32+
"total_private_repos": 100,
33+
"owned_private_repos": 100,
34+
"private_gists": 81,
35+
"disk_usage": 10000,
36+
"collaborators": 8
37+
}

tests/unit/test_users.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
get_authenticated_user_example_data = helper.create_example_data_helper(
2020
'authenticated_user_example'
2121
)
22+
get_authenticated_user_2_12_example_data = helper.create_example_data_helper(
23+
'authenticated_user_2_12_example'
24+
)
2225
get_users_example_data = helper.create_example_data_helper('users_example')
2326
get_user_key_example_data = helper.create_example_data_helper(
2427
'user_key_example'
2528
)
2629

2730
example_data = get_users_example_data()
31+
authenticated_user_2_12_example_data = (
32+
get_authenticated_user_2_12_example_data()
33+
)
2834

2935

3036
class TestUser(helper.UnitHelper):
@@ -272,3 +278,15 @@ def test_str(self):
272278
def test_is_free(self):
273279
"""Show that user can check if the plan is free."""
274280
assert self.instance.is_free() is False
281+
282+
283+
class TestAuthenticatedUserCompatibility_2_12(helper.UnitHelper):
284+
285+
"""Test methods on AuthenticatedUser from Github Enterprise 2.12."""
286+
287+
described_class = github3.users.AuthenticatedUser
288+
example_data = authenticated_user_2_12_example_data
289+
290+
def test_user(self):
291+
"""Test the ability to retrieve an AuthenticatedUser"""
292+
assert str(self.instance) == 'octocat'

0 commit comments

Comments
 (0)
0