mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Correct API for NamedUser.get_organization_membership (#1277)
NamedUser.get_organization_membership() was calling the API method for fetching the currently authenticated user only, which is incorrect. The method was not tested directly, so add tests. Furthermore, Membership had some errors which had slipped through review, so correct them. Sadly, this is an API break, since passing the organization as an int made no sense in this case. Fixes #1276
This commit is contained in:
@@ -45,7 +45,7 @@ import github.GithubObject
|
||||
|
||||
class Membership(github.GithubObject.CompletableGithubObject):
|
||||
"""
|
||||
This class represents Organizations. The reference can be found here http://developer.github.com/v3/orgs/
|
||||
This class represents Membership of an organization. The reference can be found here http://developer.github.com/v3/orgs/
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
@@ -94,7 +94,7 @@ class Membership(github.GithubObject.CompletableGithubObject):
|
||||
@property
|
||||
def user(self):
|
||||
"""
|
||||
:type: :class:`github.AuthenticatedUser.AuthenticatedUser`
|
||||
:type: :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
self._completeIfNotSet(self._user)
|
||||
return self._user.value
|
||||
@@ -119,4 +119,4 @@ class Membership(github.GithubObject.CompletableGithubObject):
|
||||
if "organization" in attributes: # pragma no branch
|
||||
self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"])
|
||||
if "user" in attributes: # pragma no branch
|
||||
self._user = self._makeClassAttribute(github.AuthenticatedUser.AuthenticatedUser, attributes["user"])
|
||||
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
|
||||
|
||||
+6
-3
@@ -626,13 +626,16 @@ class NamedUser(github.GithubObject.CompletableGithubObject):
|
||||
|
||||
def get_organization_membership(self, org):
|
||||
"""
|
||||
:calls: `GET /user/memberships/orgs/:org <https://developer.github.com/v3/orgs/members/#get-your-organization-membership>`_
|
||||
:calls: `GET /orgs/:org/memberships/:username <https://developer.github.com/v3/orgs/members/#get-organization-membership>`_
|
||||
:param org: string or :class:`github.Organization.Organization`
|
||||
:rtype: :class:`github.Membership.Membership`
|
||||
"""
|
||||
assert isinstance(org, int)
|
||||
assert isinstance(org, (str, six.text_type)) or isinstance(org, github.Organization.Organization), org
|
||||
if isinstance(org, github.Organization.Organization):
|
||||
org = org.login
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/user/memberships/orgs/" + str(org)
|
||||
"/orgs/" + org + "/memberships/" + self.login
|
||||
)
|
||||
return github.Membership.Membership(self._requester, headers, data, completed=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user