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:
Steve Kowalik
2019-10-31 20:56:46 +11:00
committed by GitHub
parent 6ad592b1b6
commit 077c80ba2d
5 changed files with 52 additions and 6 deletions
+6 -3
View File
@@ -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)