diff --git a/github/Repository.py b/github/Repository.py index 999bfb36..07272179 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1265,14 +1265,7 @@ class Repository(github.GithubObject.CompletableGithubObject): input=put_parameters ) - if headers.get('status') == '201 Created' \ - and 'content' in data and 'commit' in data: - data['content'] = github.ContentFile.ContentFile( - self._requester, headers, data, completed=True) - data['commit'] = github.Commit.Commit( - self._requester, headers, data, completed=True) - - return data + return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) def update_file(self, path, message, content, sha, branch=github.GithubObject.NotSet, @@ -1324,14 +1317,7 @@ class Repository(github.GithubObject.CompletableGithubObject): input=put_parameters ) - if headers.get('status') == '200 OK' \ - and 'content' in data and 'commit' in data: - data['content'] = github.ContentFile.ContentFile( - self._requester, headers, data, completed=True) - data['commit'] = github.Commit.Commit( - self._requester, headers, data, completed=True) - - return data + return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) def delete_file(self, path, message, sha, branch=github.GithubObject.NotSet): @@ -1359,7 +1345,7 @@ class Repository(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", - self.url + "/contents/" + path, + self.url + "/contents" + path, input=url_parameters ) diff --git a/github/tests/ReplayData/Repository.testCreateFile.txt b/github/tests/ReplayData/Repository.testCreateFile.txt new file mode 100644 index 00000000..6015d67e --- /dev/null +++ b/github/tests/ReplayData/Repository.testCreateFile.txt @@ -0,0 +1,10 @@ +https +PUT +api.github.com +None +/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md +{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +{"author": {"date": "2016-01-15T16:13:30+12:00", "email": "enix223@163.com", "name": "Enix Yu"}, "branch": "master", "committer": {"date": "2016-01-15T16:13:30+12:00", "email": "enix223@163.com", "name": "Enix Yu"}, "content": "SGVsbG8gd29ybGQ=", "message": "Create file for testCreateFile"} +201 +[('status', '201 Created'), ('x-ratelimit-remaining', '4997'), ('content-length', '16'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"f5cc2fa3ba4de95ac0eb8c2ca47350c0"'), ('date', 'Fri, 11 May 2012 11:43:09 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md')] +{"content": {"name": "hello.txt", "url": "https://api.github.com/repos/PyGithub/contents/doc/testCreateUpdateDeleteFile.md", "html_url": "https://github.com/PyGithub/doc/testCreateUpdateDeleteFile.md", "download_url": "https://raw.githubusercontent.com/PyGithub/doc/testCreateUpdateDeleteFile.md", "sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "_links": {"self": "https://api.github.com/repos/PyGithub/contents/doc/testCreateUpdateDeleteFile.md", "git": "https://api.github.com/repos/PyGithub/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "html": "https://github.com/jacquev6/PyGithub/blob/master/doc/testCreateUpdateDeleteFile.md"}, "git_url": "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "path": "doc/testCreateUpdateDeleteFile.md", "type": "file", "size": 9}, "commit": {"committer": {"date": "2014-11-07T22:01:45Z", "name": "Enix Yu", "email": "enix223@gmail.com"}, "author": {"date": "2016-01-15T16:13:30+12:00", "name": "Enix Yu", "email": "enix223@gmail.com"}, "url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "tree": {"url": "https://api.github.com/repos/jacquev6/PyGithub/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "691272480426f78a0138979dd3ce63b77f706feb"}, "html_url": "https://github.com/jacquev6/PyGithub/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd", "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "parents": [{"url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5", "html_url": "https://github.com/jacquev6/PyGithub/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5"}], "Create file for testCreateFile"}} \ No newline at end of file diff --git a/github/tests/ReplayData/Repository.testDeleteFile.txt b/github/tests/ReplayData/Repository.testDeleteFile.txt new file mode 100644 index 00000000..e977db6f --- /dev/null +++ b/github/tests/ReplayData/Repository.testDeleteFile.txt @@ -0,0 +1,21 @@ +https +GET +api.github.com +None +/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +null +200 +[('status', '200 OK'), ('content-length', '16'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('x-ratelimit-remaining', '4997'), ('server', 'nginx/1.0.13'), ('last-modified', 'Wed, 05 Sep 2012 17:54:40 GMT'), ('connection', 'keep-alive'), ('etag', '"71786feb5f476112c5a8aa894ee7ca6c"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 08 Sep 2012 10:43:48 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"file","sha":"5628799a7d517a4aaa0c1a7004d07569cd154df0","path":"doc/testCreateUpdateDeleteFile.md","encoding":"base64","_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md","html":"https://github.com/jacquev6/PyGithub/blob/master/doc/testCreateUpdateDeleteFile.md","git":"https://api.github.com/repos/jacquev6/PyGithub/git/blobs/5628799a7d517a4aaa0c1a7004d07569cd154df0"},"content":"SGVsbG8gd29ybGQ=","size":16,"name":"doc/testCreateUpdateDeleteFile.md"} + +https +DELETE +api.github.com +None +/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md +{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +{"branch": "master", "message": "Delete file for testDeleteFile", "sha": "5628799a7d517a4aaa0c1a7004d07569cd154df0"} +200 +[('status', '200 OK'), ('content-length', '16'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('x-ratelimit-remaining', '4997'), ('server', 'nginx/1.0.13'), ('last-modified', 'Wed, 05 Sep 2012 17:54:40 GMT'), ('connection', 'keep-alive'), ('etag', '"71786feb5f476112c5a8aa894ee7ca6c"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 08 Sep 2012 10:43:48 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"content": None, "commit": {"committer": {"date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "schacon@gmail.com"}, "author": {"date": "2014-11-07T22:01:45Z", "name": "Scott Chacon", "email": "schacon@gmail.com"}, "url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "tree": {"url": "https://api.github.com/repos/jacquev6/PyGithub/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "691272480426f78a0138979dd3ce63b77f706feb"}, "html_url": "https://github.com/jacquev6/PyGithub/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd", "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "parents": [{"url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5", "html_url": "https://github.com/jacquev6/PyGithub/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5"}], "message": "Delete file for testDeleteFile"}} diff --git a/github/tests/ReplayData/Repository.testGetContents.txt b/github/tests/ReplayData/Repository.testGetContents.txt index c8201fb2..24662a87 100644 --- a/github/tests/ReplayData/Repository.testGetContents.txt +++ b/github/tests/ReplayData/Repository.testGetContents.txt @@ -13,7 +13,7 @@ https GET api.github.com None -/repos/jacquev6/PyGithub/contentsdoc/ReferenceOfClasses.md +/repos/jacquev6/PyGithub/contents/doc/ReferenceOfClasses.md {'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} null 200 diff --git a/github/tests/ReplayData/Repository.testGetContentsWithRef.txt b/github/tests/ReplayData/Repository.testGetContentsWithRef.txt index 882d26ff..ce33693a 100644 --- a/github/tests/ReplayData/Repository.testGetContentsWithRef.txt +++ b/github/tests/ReplayData/Repository.testGetContentsWithRef.txt @@ -13,7 +13,7 @@ https GET api.github.com None -/repos/jacquev6/PyGithub/contentsdoc/ReferenceOfClasses.md?ref=refs%2Fheads%2Ftopic%2FExperimentOnDocumentation +/repos/jacquev6/PyGithub/contents/doc/ReferenceOfClasses.md?ref=refs%2Fheads%2Ftopic%2FExperimentOnDocumentation {'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} null 200 diff --git a/github/tests/ReplayData/Repository.testUpdateFile.txt b/github/tests/ReplayData/Repository.testUpdateFile.txt new file mode 100644 index 00000000..db6c03bc --- /dev/null +++ b/github/tests/ReplayData/Repository.testUpdateFile.txt @@ -0,0 +1,21 @@ +https +GET +api.github.com +None +/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +null +200 +[('status', '200 OK'), ('content-length', '16'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('x-ratelimit-remaining', '4997'), ('server', 'nginx/1.0.13'), ('last-modified', 'Wed, 05 Sep 2012 17:54:40 GMT'), ('connection', 'keep-alive'), ('etag', '"71786feb5f476112c5a8aa894ee7ca6c"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 08 Sep 2012 10:43:48 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"type":"file","sha":"5628799a7d517a4aaa0c1a7004d07569cd154df0","path":"doc/testCreateUpdateDeleteFile.md","encoding":"base64","_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md","html":"https://github.com/jacquev6/PyGithub/blob/master/doc/testCreateUpdateDeleteFile.md","git":"https://api.github.com/repos/jacquev6/PyGithub/git/blobs/5628799a7d517a4aaa0c1a7004d07569cd154df0"},"content":"SGVsbG8gd29ybGQ=","size":16,"name":"doc/testCreateUpdateDeleteFile.md"} + +https +PUT +api.github.com +None +/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md +{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +{"author": {"date": "2016-01-15T16:13:30+12:00", "email": "enix223@163.com", "name": "Enix Yu"}, "branch": "master", "committer": {"date": "2016-01-15T16:13:30+12:00", "email": "enix223@163.com", "name": "Enix Yu"}, "content": "SGVsbG8gV29ybGQ=", "message": "Update file for testUpdateFile", "sha": "5628799a7d517a4aaa0c1a7004d07569cd154df0"} +200 +[('status', '200 OK'), ('content-length', '16'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('x-ratelimit-remaining', '4997'), ('server', 'nginx/1.0.13'), ('last-modified', 'Wed, 05 Sep 2012 17:54:40 GMT'), ('connection', 'keep-alive'), ('etag', '"71786feb5f476112c5a8aa894ee7ca6c"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 08 Sep 2012 10:43:48 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"content": {"name": "testCreateUpdateDeleteFile.md", "url": "https://api.github.com/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md", "html_url": "https://github.com/jacquev6/PyGithub/blob/master/doc/testCreateUpdateDeleteFile.md", "download_url": "https://raw.githubusercontent.com/octocat/HelloWorld/master/doc/testCreateUpdateDeleteFile.md", "sha": "95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "_links": {"self": "https://api.github.com/repos/jacquev6/PyGithub/contents/doc/testCreateUpdateDeleteFile.md", "git": "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "html": "https://github.com/jacquev6/PyGithub/blob/master/doc/testCreateUpdateDeleteFile.md"}, "git_url": "https://api.github.com/repos/jacquev6/PyGithub/git/blobs/95b966ae1c166bd92f8ae7d1c313e738c731dfc3", "path": "doc/testCreateUpdateDeleteFile.md", "type": "file", "size": 9}, "commit": {"committer": {"date": "2016-01-15T16:13:30+12:00", "name": "Enix Yu", "email": "enix223@gmail.com"}, "author": {"date": "2016-01-15T16:13:30+12:00", "name": "Enix Yu", "email": "enix223@gmail.com"}, "url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd", "tree": {"url": "https://api.github.com/repos/jacquev6/PyGithub/git/trees/691272480426f78a0138979dd3ce63b77f706feb", "sha": "691272480426f78a0138979dd3ce63b77f706feb"}, "html_url": "https://github.com/jacquev6/PyGithub/git/commit/7638417db6d59f3c431d3e1f261cc637155684cd", "sha": "7638417db6d59f3c431d3e1f261cc637155684cd", "parents": [{"url": "https://api.github.com/repos/jacquev6/PyGithub/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5", "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5", "html_url": "https://github.com/jacquev6/PyGithub/git/commit/1acc419d4d6a9ce985db7be48c6349a0475975b5"}], "message": "my commit message"}} \ No newline at end of file diff --git a/github/tests/Repository.py b/github/tests/Repository.py index f016407c..3c90af89 100644 --- a/github/tests/Repository.py +++ b/github/tests/Repository.py @@ -406,21 +406,33 @@ class Repository(Framework.TestCase): def testGetContents(self): self.assertEqual(len(self.repo.get_readme().content), 10212) - self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md").content), 38121) + self.assertEqual(len(self.repo.get_contents("/doc/ReferenceOfClasses.md").content), 38121) def testGetContentsWithRef(self): self.assertEqual(len(self.repo.get_readme(ref="refs/heads/topic/ExperimentOnDocumentation").content), 6747) - self.assertEqual(len(self.repo.get_contents("doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation").content), 43929) + self.assertEqual(len(self.repo.get_contents("/doc/ReferenceOfClasses.md", ref="refs/heads/topic/ExperimentOnDocumentation").content), 43929) def testCreateFile(self): - self.repo.create_file('', '', ) + newFile = '/doc/testCreateUpdateDeleteFile.md' + content = bytes('Hello world') + self.repo.create_file( + path=newFile, message='Create file for testCreateFile', content=content, + branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), + author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00")) def testUpdateFile(self): - pass + updateFile = '/doc/testCreateUpdateDeleteFile.md' + content = bytes('Hello World') + sha = self.repo.get_contents(updateFile).sha + self.repo.update_file( + path=updateFile, message='Update file for testUpdateFile', content=content, sha=sha, + branch="master", committer=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"), + author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00")) def testDeleteFile(self): - pass - + deleteFile = '/doc/testCreateUpdateDeleteFile.md' + sha = self.repo.get_contents(deleteFile).sha + self.repo.delete_file(path=deleteFile, message='Delete file for testDeleteFile', sha=sha, branch="master") def testGetArchiveLink(self): self.assertEqual(self.repo.get_archive_link("tarball"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master")