Delete file from gist (issue #156)

This commit is contained in:
Vincent Jacques
2013-04-08 21:07:17 +02:00
parent db5560bd65
commit 6861c5cd19
3 changed files with 30 additions and 2 deletions
+2 -2
View File
@@ -200,12 +200,12 @@ class Gist(github.GithubObject.CompletableGithubObject):
:rtype: None
"""
assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description
assert files is github.GithubObject.NotSet or all(isinstance(element, github.InputFileContent) for element in files.itervalues()), files
assert files is github.GithubObject.NotSet or all(element is None or isinstance(element, github.InputFileContent) for element in files.itervalues()), files
post_parameters = dict()
if description is not github.GithubObject.NotSet:
post_parameters["description"] = description
if files is not github.GithubObject.NotSet:
post_parameters["files"] = dict((key, value._identity) for key, value in files.iteritems())
post_parameters["files"] = dict((key, None if value is None else value._identity) for key, value in files.iteritems())
headers, data = self._requester.requestJsonAndCheck(
"PATCH",
self.url,
+6
View File
@@ -72,6 +72,12 @@ class Gist(Framework.TestCase):
self.assertEqual(self.gist.updated_at, datetime.datetime(2012, 5, 19, 7, 6, 10))
self.assertEqual(set(self.gist.files.keys()), set(["foobar.txt", "barbaz.txt"]))
def testDeleteFile(self):
gist = self.g.get_gist("5339374")
self.assertEqual(gist.files.keys(), ["foo.txt", "bar.txt"])
gist.edit(files={"foo.txt": None})
self.assertEqual(gist.files.keys(), ["bar.txt"])
def testCreateComment(self):
comment = self.gist.create_comment("Comment created by PyGithub")
self.assertEqual(comment.id, 323629)
@@ -0,0 +1,22 @@
https
GET
api.github.com
None
/gists/5339374
{'Authorization': 'Basic login_and_password_removed'}
null
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4995'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '3241'), ('server', 'GitHub.com'), ('last-modified', 'Mon, 08 Apr 2013 18:46:15 GMT'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d1bfdcec2c35202fa167ebdfed524d25"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('date', 'Mon, 08 Apr 2013 18:50:39 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"url":"https://api.github.com/gists/5339374","forks_url":"https://api.github.com/gists/5339374/forks","commits_url":"https://api.github.com/gists/5339374/commits","id":"5339374","git_pull_url":"https://gist.github.com/5339374.git","git_push_url":"https://gist.github.com/5339374.git","html_url":"https://gist.github.com/5339374","files":{"bar.txt":{"filename":"bar.txt","type":"text/plain","language":null,"raw_url":"https://gist.github.com/raw/5339374/9a84713661904c94ce1e404151d15030b042a884/bar.txt","size":49,"content":"This file will be renamed \"baz.txt\" by PyGithub.\n"},"foo.txt":{"filename":"foo.txt","type":"text/plain","language":null,"raw_url":"https://gist.github.com/raw/5339374/920c28027f920979606c96ca347b050b1ebd1013/foo.txt","size":39,"content":"This file will be deleted by PyGithub.\n"}},"public":true,"created_at":"2013-04-08T18:46:14Z","updated_at":"2013-04-08T18:46:15Z","description":"Test gist for PyGithub","comments":0,"user":{"login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User"},"comments_url":"https://api.github.com/gists/5339374/comments","forks":[],"history":[{"user":{"login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User"},"version":"7887f7ac9eb5c1963004bdde3bcfe2221d9a0515","committed_at":"2013-04-08T18:46:14Z","change_status":{"total":2,"additions":2,"deletions":0},"url":"https://api.github.com/gists/5339374/7887f7ac9eb5c1963004bdde3bcfe2221d9a0515"}]}
https
PATCH
api.github.com
None
/gists/5339374
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed'}
{"files": {"foo.txt": null}}
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('content-length', '4233'), ('server', 'GitHub.com'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"316f00c71eeb327bbeac7a3f7aba5237"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Mon, 08 Apr 2013 18:50:40 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"url":"https://api.github.com/gists/5339374","forks_url":"https://api.github.com/gists/5339374/forks","commits_url":"https://api.github.com/gists/5339374/commits","id":"5339374","git_pull_url":"https://gist.github.com/5339374.git","git_push_url":"https://gist.github.com/5339374.git","html_url":"https://gist.github.com/5339374","files":{"bar.txt":{"filename":"bar.txt","type":"text/plain","language":null,"raw_url":"https://gist.github.com/raw/5339374/9a84713661904c94ce1e404151d15030b042a884/bar.txt","size":49,"content":"This file will be renamed \"baz.txt\" by PyGithub.\n"}},"public":true,"created_at":"2013-04-08T18:46:14Z","updated_at":"2013-04-08T18:50:40Z","description":"Test gist for PyGithub","comments":0,"user":{"login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User"},"comments_url":"https://api.github.com/gists/5339374/comments","forks":[],"history":[{"user":{"login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User"},"version":"3b66ad4cc07f2bebb2eae2b2f2eefba33d2fb2d5","committed_at":"2013-04-08T18:50:40Z","change_status":{"total":1,"additions":0,"deletions":1},"url":"https://api.github.com/gists/5339374/3b66ad4cc07f2bebb2eae2b2f2eefba33d2fb2d5"},{"user":{"login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User"},"version":"7887f7ac9eb5c1963004bdde3bcfe2221d9a0515","committed_at":"2013-04-08T18:46:14Z","change_status":{"total":2,"additions":2,"deletions":0},"url":"https://api.github.com/gists/5339374/7887f7ac9eb5c1963004bdde3bcfe2221d9a0515"}]}