From e384a52971a8452b9c8eb32ed862e88cd828ee8e Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 21 Aug 2013 21:43:08 +0200 Subject: [PATCH] NamedUser.has_in_following --- README.rst | 4 +--- github/NamedUser.py | 15 +++++++++++++ github/tests/NamedUser.py | 4 ++++ .../NamedUser.testHasInFollowing.txt | 22 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 github/tests/ReplayData/NamedUser.testHasInFollowing.txt diff --git a/README.rst b/README.rst index e80811ef..fde0bf28 100644 --- a/README.rst +++ b/README.rst @@ -12,6 +12,7 @@ What's new? `Version 1.19.0 `_ (?? ??th, 2013) +* Implement ``NamedUser.has_in_following`` * Use the new URL to fork gists (minor change) * Use the new URL to test hooks (minor change) @@ -63,9 +64,6 @@ Github API v3 URLs not (yet) covered by PyGithub * ``/search/issues`` (GET) * ``/search/repositories`` (GET) * ``/search/users`` (GET) -* ``/users/:user/following/:target_user`` (GET) - - * should be called in method ``NamedUser.has_in_following`` Documentation ============= diff --git a/github/NamedUser.py b/github/NamedUser.py index a8016a15..b2a6dc48 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -449,6 +449,21 @@ class NamedUser(github.GithubObject.CompletableGithubObject): None ) + def has_in_following(self, following): + """ + :calls: `GET /user/:user/following/:target_user `_ + :param following: :class:`github.NamedUser.NamedUser` + :rtype: bool + """ + assert isinstance(following, github.NamedUser.NamedUser), following + status, headers, data = self._requester.requestJson( + "GET", + self.url + "/following/" + following._identity, + None, + None + ) + return status == 204 + @property def _identity(self): return self.login diff --git a/github/tests/NamedUser.py b/github/tests/NamedUser.py index 2ea6944d..5a56bd19 100644 --- a/github/tests/NamedUser.py +++ b/github/tests/NamedUser.py @@ -109,6 +109,10 @@ class NamedUser(Framework.TestCase): def testGetFollowing(self): self.assertListKeyEqual(self.user.get_following(), lambda f: f.login, ["nvie", "schacon", "jamis", "chad", "unclebob", "dabrahams", "jnorthrup", "brugidou", "regisb", "walidk", "tanzilli", "fjardon", "r3c", "sdanzan", "vineus", "cjuniet", "gturri", "ant9000", "asquini", "claudyus", "jardon-u", "s-bernard", "kamaradclimber", "Lyloa"]) + def testHasInFollowing(self): + nvie = self.g.get_user("nvie") + self.assertTrue(self.user.has_in_following(nvie)) + def testGetOrgs(self): self.assertListKeyEqual(self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"]) diff --git a/github/tests/ReplayData/NamedUser.testHasInFollowing.txt b/github/tests/ReplayData/NamedUser.testHasInFollowing.txt new file mode 100644 index 00000000..08c61a84 --- /dev/null +++ b/github/tests/ReplayData/NamedUser.testHasInFollowing.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/users/nvie +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4996'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('access-control-expose-headers', 'ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes'), ('access-control-allow-credentials', 'true'), ('vary', 'Accept, Authorization, Cookie, Accept-Encoding'), ('content-length', '1218'), ('server', 'GitHub.com'), ('last-modified', 'Wed, 21 Aug 2013 16:26:40 GMT'), ('x-ratelimit-limit', '5000'), ('etag', '"8e2b307f8fb4186bfb512febd7215fc8"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Wed, 21 Aug 2013 17:20:44 GMT'), ('access-control-allow-origin', '*'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1377108637')] +{"login":"nvie","id":83844,"avatar_url":"https://2.gravatar.com/avatar/466ef7561a0b100dc5a1021959962d28?d=https%3A%2F%2Fidenticons.github.com%2Fe6d0513ce49cc06cb956251623cb8fd9.png","gravatar_id":"466ef7561a0b100dc5a1021959962d28","url":"https://api.github.com/users/nvie","html_url":"https://github.com/nvie","followers_url":"https://api.github.com/users/nvie/followers","following_url":"https://api.github.com/users/nvie/following{/other_user}","gists_url":"https://api.github.com/users/nvie/gists{/gist_id}","starred_url":"https://api.github.com/users/nvie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvie/subscriptions","organizations_url":"https://api.github.com/users/nvie/orgs","repos_url":"https://api.github.com/users/nvie/repos","events_url":"https://api.github.com/users/nvie/events{/privacy}","received_events_url":"https://api.github.com/users/nvie/received_events","type":"User","name":"Vincent Driessen","company":"3rd Cloud","blog":"http://nvie.com","location":"Netherlands","email":"vincent@3rdcloud.com","hireable":true,"bio":null,"public_repos":86,"followers":530,"following":45,"created_at":"2009-05-12T21:19:38Z","updated_at":"2013-08-21T16:26:40Z","public_gists":38} + +https +GET +api.github.com +None +/users/jacquev6/following/nvie +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +null +204 +[('status', '204 No Content'), ('x-ratelimit-remaining', '4995'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('access-control-expose-headers', 'ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes'), ('vary', 'Accept-Encoding'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('access-control-allow-credentials', 'true'), ('date', 'Wed, 21 Aug 2013 17:20:48 GMT'), ('access-control-allow-origin', '*'), ('x-ratelimit-reset', '1377108637')] + +