Repository: PyGithub/PyGithub

Issue:
get_organization_membership is passed org, which should str but asserts if not int
The function get_organization_membership in file AuthenticatedUser.py expects (self, org) then asserts if org is not an int

line 1310 - assert isinstance(org, int)

however API expects a string - organisation login value

"GET", "/user/memberships/orgs/" + str(org)

changing assert to the following works as expected

line 1310 - assert isinstance(org, str)

(sorry, i'm not following all the rules this is my first ever GitHub issue) 


Discussion:
As it is written we coerce it to a str so we can construct the URL from an integer. The idea being that you give it the ID of the organization, and it returns the membership. However, I can see that calling it with the ID of an organization that I am a member of, it raises a 404, and giving it the org name works fine. I'll push up a PR soon.

Resolving patch:
diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py
--- a/github/AuthenticatedUser.py
+++ b/github/AuthenticatedUser.py
@@ -1307,9 +1307,9 @@ def get_organization_membership(self, org):
         :calls: `GET /user/memberships/orgs/:org <https://developer.github.com/v3/orgs/members/#get-your-organization-membership>`_
         :rtype: :class:`github.Membership.Membership`
         """
-        assert isinstance(org, int)
+        assert isinstance(org, str)
         headers, data = self._requester.requestJsonAndCheck(
-            "GET", "/user/memberships/orgs/" + str(org)
+            "GET", "/user/memberships/orgs/" + org
         )
         return github.Membership.Membership(
             self._requester, headers, data, completed=True


Test patch:
diff --git a/tests/GitMembership.py b/tests/GitMembership.py
--- a/tests/GitMembership.py
+++ b/tests/GitMembership.py
@@ -44,14 +44,10 @@
 
 
 class GitMembership(Framework.TestCase):
-    def setUp(self):
-        super().setUp()
-        self.org = self.g.get_organization("github")
-
     def testGetMembership(self):
         octocat = self.g.get_user()
         self.assertEqual(octocat.login, "octocat")
-        membership_data = octocat.get_organization_membership(self.org.id)
+        membership_data = octocat.get_organization_membership("github")
         self.assertEqual(membership_data.user.login, "octocat")
         self.assertEqual(membership_data.role, "admin")
         self.assertEqual(membership_data.organization.login, "github")
diff --git a/tests/ReplayData/GitMembership.setUp.txt b/tests/ReplayData/GitMembership.setUp.txt
deleted file mode 100644
--- a/tests/ReplayData/GitMembership.setUp.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-https
-GET
-api.github.com
-None
-/orgs/github
-{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
-None
-200
-[('status', '200 OK'), ('x-ratelimit-remaining', '4969'), ('content-length', '716'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d1b89d0f179a7977b3521babf470b71e"'), ('date', 'Sat, 26 May 2012 20:13:58 GMT'), ('content-type', 'application/json; charset=utf-8')]
-{"login":"github","id":1,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE=","url":"https://api.github.com/orgs/github","repos_url":"https://api.github.com/orgs/github/repos","events_url":"https://api.github.com/orgs/github/events","hooks_url":"https://api.github.com/orgs/github/hooks","issues_url":"https://api.github.com/orgs/github/issues","members_url":"https://api.github.com/orgs/github/members{/member}","public_members_url":"https://api.github.com/orgs/github/public_members{/member}","avatar_url":"https://github.com/images/error/octocat_happy.gif","description":"A great organization","name":"github","company":"GitHub","blog":"https://github.com/blog","location":"San Francisco","email":"octocat@github.com","is_verified":true,"has_organization_projects":true,"has_repository_projects":true,"public_repos":2,"public_gists":1,"followers":20,"following":0,"html_url":"https://github.com/octocat","created_at":"2008-01-14T04:33:35Z","type":"Organization","total_private_repos":100,"owned_private_repos":100,"private_gists":81,"disk_usage":10000,"collaborators":8,"billing_email":"support@github.com","plan":{"name":"Medium","space":400,"private_repos":20},"default_repository_settings":"read","members_can_create_repositories":true,"two_factor_requirement_enabled":true,"members_allowed_repository_creation_type":"all"}
diff --git a/tests/ReplayData/GitMembership.testGetMembership.txt b/tests/ReplayData/GitMembership.testGetMembership.txt
--- a/tests/ReplayData/GitMembership.testGetMembership.txt
+++ b/tests/ReplayData/GitMembership.testGetMembership.txt
@@ -13,7 +13,7 @@ https
 GET
 api.github.com
 None
-/user/memberships/orgs/1
+/user/memberships/orgs/github
 {'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
 None
 200