Add list projects support, update tests (#1431)

This commit is contained in:
Anuj Bansal
2020-03-11 12:40:25 +11:00
committed by GitHub
parent b1c35499f4
commit e44d11d565
4 changed files with 76 additions and 0 deletions
+18
View File
@@ -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 <https://developer.github.com/v3/projects/#list-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 <http://developer.github.com/v3/activity/events>`_
+36
View File
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2020 Anuj Bansal <bansalanuj1996@gmail.com> #
# #
# 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 <http://www.gnu.org/licenses/>. #
# #
################################################################################
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],
)
+11
View File
@@ -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}}
File diff suppressed because one or more lines are too long