Skip to content

Commit

Permalink
Add create project method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahhda committed Mar 15, 2020
1 parent afb1259 commit 801ea38
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
20 changes: 20 additions & 0 deletions github/Organization.py
Expand Up @@ -391,6 +391,26 @@ def create_hook(
)
return github.Hook.Hook(self._requester, headers, data, completed=True)

def create_project(self, name, body=github.GithubObject.NotSet):
"""
:calls: `POST /orgs/:org/projects <https://developer.github.com/v3/projects/#create-an-organization-project>`_
:param name: string
:param body: string
:rtype: :class:`github.Project.Project`
"""
assert isinstance(name, str), name
assert body is github.GithubObject.NotSet or isinstance(body, str), body
post_parameters = {"name": name}
if body is not github.GithubObject.NotSet:
post_parameters["body"] = body
headers, data = self._requester.requestJsonAndCheck(
"POST",
self.url + "/projects",
input=post_parameters,
headers={"Accept": Consts.mediaTypeProjectsPreview},
)
return github.Project.Project(self._requester, headers, data, completed=True)

def create_repo(
self,
name,
Expand Down
35 changes: 35 additions & 0 deletions tests/Organization1437.py
@@ -0,0 +1,35 @@
# -*- 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 Organization1437(Framework.TestCase):
def setUp(self):
super().setUp()
self.org = self.g.get_organization("PyGithubSampleOrg")

def testCreateProject(self):
project = self.org.create_project("Project title", "This is the body")
self.assertEqual(project.id, 4115694)
11 changes: 11 additions & 0 deletions tests/ReplayData/Organization1437.setUp.txt
@@ -0,0 +1,11 @@
https
GET
api.github.com
None
/orgs/PyGithubSampleOrg
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('Date', 'Sun, 15 Mar 2020 16:30:51 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4996'), ('X-RateLimit-Reset', '1584292656'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"5a44b3584cfbb71e5ae99df123138fc5"'), ('Last-Modified', 'Sun, 15 Mar 2020 16:23:28 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', 'D02B:0E77:6CA8B4:899B24:5E6E583B')]
{"login":"PyGithubSampleOrg","id":62213331,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYyMjEzMzMx","url":"https://api.github.com/orgs/PyGithubSampleOrg","repos_url":"https://api.github.com/orgs/PyGithubSampleOrg/repos","events_url":"https://api.github.com/orgs/PyGithubSampleOrg/events","hooks_url":"https://api.github.com/orgs/PyGithubSampleOrg/hooks","issues_url":"https://api.github.com/orgs/PyGithubSampleOrg/issues","members_url":"https://api.github.com/orgs/PyGithubSampleOrg/members{/member}","public_members_url":"https://api.github.com/orgs/PyGithubSampleOrg/public_members{/member}","avatar_url":"https://avatars3.githubusercontent.com/u/62213331?v=4","description":null,"is_verified":false,"has_organization_projects":true,"has_repository_projects":true,"public_repos":0,"public_gists":0,"followers":0,"following":0,"html_url":"https://github.com/PyGithubSampleOrg","created_at":"2020-03-15T16:23:28Z","updated_at":"2020-03-15T16:23:28Z","type":"Organization","total_private_repos":0,"owned_private_repos":0,"private_gists":0,"disk_usage":0,"collaborators":0,"billing_email":"bansalanuj1996@gmail.com","default_repository_permission":"read","members_can_create_repositories":true,"two_factor_requirement_enabled":false,"plan":{"name":"free","space":976562499,"private_repos":0,"filled_seats":1,"seats":0}}

11 changes: 11 additions & 0 deletions tests/ReplayData/Organization1437.testCreateProject.txt
@@ -0,0 +1,11 @@
https
POST
api.github.com
None
/orgs/PyGithubSampleOrg/projects
{'Accept': 'application/vnd.github.inertia-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
{"name": "Project title", "body": "This is the body"}
201
[('Date', 'Sun, 15 Mar 2020 16:30:52 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '1409'), ('Server', 'GitHub.com'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1584292656'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', '"facd2116232591d58f7efd4c226d71d2"'), ('Location', 'https://api.github.com/projects/4115694'), ('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'"), ('X-GitHub-Request-Id', '611A:7C7D:699325:86F5B8:5E6E583B')]
{"owner_url":"https://api.github.com/orgs/PyGithubSampleOrg","url":"https://api.github.com/projects/4115694","html_url":"https://github.com/orgs/PyGithubSampleOrg/projects/1","columns_url":"https://api.github.com/projects/4115694/columns","id":4115694,"node_id":"MDc6UHJvamVjdDQxMTU2OTQ=","name":"Project title","body":"This is the body","number":1,"state":"open","creator":{"login":"ahhda","id":7795956,"node_id":"MDQ6VXNlcjc3OTU5NTY=","avatar_url":"https://avatars0.githubusercontent.com/u/7795956?u=69331080d94f26f4e465cbc5437167637ae324f1&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-15T16:30:52Z","updated_at":"2020-03-15T16:30:52Z","organization_permission":"write","private":true}

0 comments on commit 801ea38

Please sign in to comment.