From e44d11d565c022496544dd6ed1f19a8d718c2b0c Mon Sep 17 00:00:00 2001 From: Anuj Bansal Date: Wed, 11 Mar 2020 07:10:25 +0530 Subject: [PATCH] Add list projects support, update tests (#1431) --- github/NamedUser.py | 18 ++++++++++ tests/NamedUser1430.py | 36 +++++++++++++++++++ tests/ReplayData/NamedUser1430.setUp.txt | 11 ++++++ .../NamedUser1430.testGetProjects.txt | 11 ++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/NamedUser1430.py create mode 100644 tests/ReplayData/NamedUser1430.setUp.txt create mode 100644 tests/ReplayData/NamedUser1430.testGetProjects.txt diff --git a/github/NamedUser.py b/github/NamedUser.py index d1ad8cf5..44d41b88 100644 --- a/github/NamedUser.py +++ b/github/NamedUser.py @@ -49,6 +49,8 @@ import github.Permissions import github.Plan import github.Repository +from . import Consts + class NamedUser(github.GithubObject.CompletableGithubObject): """ @@ -481,6 +483,22 @@ class NamedUser(github.GithubObject.CompletableGithubObject): github.Organization.Organization, self._requester, self.url + "/orgs", None ) + def get_projects(self, state="open"): + """ + :calls: `GET /users/:user/projects `_ + :param state: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` + """ + assert isinstance(state, str), state + url_parameters = {"state": state} + return github.PaginatedList.PaginatedList( + github.Project.Project, + self._requester, + self.url + "/projects", + url_parameters, + headers={"Accept": Consts.mediaTypeProjectsPreview}, + ) + def get_public_events(self): """ :calls: `GET /users/:user/events/public `_ diff --git a/tests/NamedUser1430.py b/tests/NamedUser1430.py new file mode 100644 index 00000000..33f8e833 --- /dev/null +++ b/tests/NamedUser1430.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +############################ Copyrights and license ############################ +# # +# Copyright 2020 Anuj Bansal # +# # +# This file is part of PyGithub. # +# http://pygithub.readthedocs.io/ # +# # +# PyGithub is free software: you can redistribute it and/or modify it under # +# the terms of the GNU Lesser General Public License as published by the Free # +# Software Foundation, either version 3 of the License, or (at your option) # +# any later version. # +# # +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # +# details. # +# # +# You should have received a copy of the GNU Lesser General Public License # +# along with PyGithub. If not, see . # +# # +################################################################################ + +from . import Framework + + +class NamedUser1430(Framework.TestCase): + def setUp(self): + super().setUp() + self.user = self.g.get_user("ahhda") + + def testGetProjects(self): + self.assertListKeyBegin( + self.user.get_projects(state="all"), lambda e: e.id, [4083095], + ) diff --git a/tests/ReplayData/NamedUser1430.setUp.txt b/tests/ReplayData/NamedUser1430.setUp.txt new file mode 100644 index 00000000..abf285c9 --- /dev/null +++ b/tests/ReplayData/NamedUser1430.setUp.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/users/ahhda +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Mon, 09 Mar 2020 20:17:21 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4975'), ('X-RateLimit-Reset', '1583787082'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"df3f26811bc0b8e004078ee4dff56831"'), ('Last-Modified', 'Mon, 09 Mar 2020 18:51:05 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'CE65:5225:24E50A:307321:5E66A451')] +{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false,"name":"Anuj Bansal","company":null,"blog":"https://ahhda.github.io/","location":null,"email":"bansalanuj1996@gmail.com","hireable":true,"bio":null,"public_repos":40,"public_gists":5,"followers":23,"following":58,"created_at":"2014-06-04T15:57:45Z","updated_at":"2020-03-09T18:51:05Z","private_gists":4,"total_private_repos":36,"owned_private_repos":31,"disk_usage":226412,"collaborators":10,"two_factor_authentication":false,"plan":{"name":"pro","space":976562499,"collaborators":0,"private_repos":9999}} + diff --git a/tests/ReplayData/NamedUser1430.testGetProjects.txt b/tests/ReplayData/NamedUser1430.testGetProjects.txt new file mode 100644 index 00000000..12406463 --- /dev/null +++ b/tests/ReplayData/NamedUser1430.testGetProjects.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/users/ahhda/projects?state=all +{'Accept': 'application/vnd.github.inertia-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Mon, 09 Mar 2020 20:17:22 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4974'), ('X-RateLimit-Reset', '1583787083'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"14effeef315c8c569963ae39adc9619a"'), ('X-GitHub-Media-Type', 'github.inertia-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'CE66:638B:8DED89:B5F000:5E66A451')] +[{"owner_url":"https://api.github.com/users/ahhda","url":"https://api.github.com/projects/4083095","html_url":"https://github.com/users/ahhda/projects/1","columns_url":"https://api.github.com/projects/4083095/columns","id":4083095,"node_id":"MDc6UHJvamVjdDQwODMwOTU=","name":"My project 1","body":"The body","number":1,"state":"closed","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false},"created_at":"2020-03-09T14:15:48Z","updated_at":"2020-03-09T19:00:07Z"},{"owner_url":"https://api.github.com/users/ahhda","url":"https://api.github.com/projects/4083137","html_url":"https://github.com/users/ahhda/projects/2","columns_url":"https://api.github.com/projects/4083137/columns","id":4083137,"node_id":"MDc6UHJvamVjdDQwODMxMzc=","name":"My project 12","body":"The body","number":2,"state":"closed","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false},"created_at":"2020-03-09T14:20:51Z","updated_at":"2020-03-09T19:00:04Z"},{"owner_url":"https://api.github.com/users/ahhda","url":"https://api.github.com/projects/4084607","html_url":"https://github.com/users/ahhda/projects/3","columns_url":"https://api.github.com/projects/4084607/columns","id":4084607,"node_id":"MDc6UHJvamVjdDQwODQ2MDc=","name":"TestPyGithub","body":"This is the body","number":3,"state":"closed","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false},"created_at":"2020-03-09T18:51:05Z","updated_at":"2020-03-09T19:00:01Z"},{"owner_url":"https://api.github.com/users/ahhda","url":"https://api.github.com/projects/4084610","html_url":"https://github.com/users/ahhda/projects/4","columns_url":"https://api.github.com/projects/4084610/columns","id":4084610,"node_id":"MDc6UHJvamVjdDQwODQ2MTA=","name":"TestPyGithub","body":"This is the body","number":4,"state":"closed","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false},"created_at":"2020-03-09T18:51:19Z","updated_at":"2020-03-09T18:59:57Z"},{"owner_url":"https://api.github.com/users/ahhda","url":"https://api.github.com/projects/4084664","html_url":"https://github.com/users/ahhda/projects/5","columns_url":"https://api.github.com/projects/4084664/columns","id":4084664,"node_id":"MDc6UHJvamVjdDQwODQ2NjQ=","name":"My new project","body":"This is the body","number":5,"state":"open","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars2.githubusercontent.com/u/7795956?v=4","gravatar_id":"","url":"https://api.github.com/users/ahhda","html_url":"https://github.com/ahhda","followers_url":"https://api.github.com/users/ahhda/followers","following_url":"https://api.github.com/users/ahhda/following{/other_user}","gists_url":"https://api.github.com/users/ahhda/gists{/gist_id}","starred_url":"https://api.github.com/users/ahhda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahhda/subscriptions","organizations_url":"https://api.github.com/users/ahhda/orgs","repos_url":"https://api.github.com/users/ahhda/repos","events_url":"https://api.github.com/users/ahhda/events{/privacy}","received_events_url":"https://api.github.com/users/ahhda/received_events","type":"User","site_admin":false},"created_at":"2020-03-09T19:00:36Z","updated_at":"2020-03-09T19:00:36Z"}] +