Add a trailing slash to URL when updating or deleting a file (tests fixed) (#931)

* Add a trailing slash to URL when updating or deleting a file.

* Update test files to match new create/update/delete_file Repo methods

* Add trailing slash to get_contents() method

* update tests

* add missing slash in get_dir_contents

* add example usage

* remove dup slashes in tests

* clarify example comments
This commit is contained in:
AetherDeity
2018-10-17 08:21:17 +08:00
committed by Wan Liuyang
parent 9d2129c7b9
commit ee9f098d91
6 changed files with 112 additions and 23 deletions
+5 -5
View File
@@ -1449,7 +1449,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
url_parameters["ref"] = ref
headers, data = self._requester.requestJsonAndCheck(
"GET",
self.url + "/contents" + urllib.quote(path),
self.url + "/contents/" + urllib.quote(path),
parameters=url_parameters
)
if isinstance(data, list):
@@ -1530,7 +1530,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/contents" + urllib.quote(path),
self.url + "/contents/" + urllib.quote(path),
input=put_parameters
)
@@ -1594,7 +1594,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/contents" + urllib.quote(path),
self.url + "/contents/" + urllib.quote(path),
input=put_parameters
)
@@ -1644,7 +1644,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
headers, data = self._requester.requestJsonAndCheck(
"DELETE",
self.url + "/contents" + urllib.quote(path),
self.url + "/contents/" + urllib.quote(path),
input=url_parameters
)
@@ -1665,7 +1665,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
url_parameters["ref"] = ref
headers, data = self._requester.requestJsonAndCheck(
"GET",
self.url + "/contents" + urllib.quote(path),
self.url + "/contents/" + urllib.quote(path),
parameters=url_parameters
)
+3 -3
View File
@@ -35,7 +35,7 @@ class Issue140(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu
self.repo = self.g.get_repo("twitter/bootstrap")
def testGetDirContentsThenLazyCompletionOfFile(self):
contents = self.repo.get_dir_contents("/js")
contents = self.repo.get_dir_contents("js")
self.assertEqual(len(contents), 15)
n = 0
for content in contents:
@@ -48,10 +48,10 @@ class Issue140(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issu
self.assertEqual(n, 2)
def testGetFileContents(self):
contents = self.repo.get_file_contents("/js/bootstrap-affix.js")
contents = self.repo.get_file_contents("js/bootstrap-affix.js")
self.assertEqual(contents.encoding, "base64")
self.assertEqual(contents.url, "https://api.github.com/repos/twitter/bootstrap/contents/js/bootstrap-affix.js")
self.assertEqual(len(contents.content), 4722)
def testGetDirContentsWithRef(self):
self.assertEqual(len(self.repo.get_dir_contents("/js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33")), 15)
self.assertEqual(len(self.repo.get_dir_contents("js", "8c7f9c66a7d12f47f50618ef420868fe836d0c33")), 15)
+1 -1
View File
@@ -35,5 +35,5 @@ class Issue174(Framework.TestCase):
self.repo = self.g.get_repo("twitter/bootstrap")
def testGetDirContentsWhithHttpRedirect(self):
contents = self.repo.get_dir_contents("/js/")
contents = self.repo.get_dir_contents("js/")
self.assertEqual(len(contents), 15)
@@ -332,7 +332,7 @@ https
GET
api.github.com
None
/repos/jacquev6/PyGithub/contentsREADME.rst
/repos/jacquev6/PyGithub/contents/README.rst
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
+6 -6
View File
@@ -513,20 +513,20 @@ 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 testGetContentDir(self):
contents = self.repo.get_contents("/")
contents = self.repo.get_contents("")
self.assertTrue(isinstance(contents, list))
self.assertEquals(len(contents), 14)
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):
newFile = '/doc/testCreateUpdateDeleteFile.md'
newFile = 'doc/testCreateUpdateDeleteFile.md'
content = 'Hello world'
self.repo.create_file(
path=newFile, message='Create file for testCreateFile', content=content,
@@ -534,7 +534,7 @@ class Repository(Framework.TestCase):
author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"))
def testUpdateFile(self):
updateFile = '/doc/testCreateUpdateDeleteFile.md'
updateFile = 'doc/testCreateUpdateDeleteFile.md'
content = 'Hello World'
sha = self.repo.get_contents(updateFile).sha
self.repo.update_file(
@@ -543,7 +543,7 @@ class Repository(Framework.TestCase):
author=github.InputGitAuthor("Enix Yu", "enix223@163.com", "2016-01-15T16:13:30+12:00"))
def testDeleteFile(self):
deleteFile = '/doc/testCreateUpdateDeleteFile.md'
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")