Complete "ref in Repository.get_contents and .get_readme" (pull #124)

Add documentation and automated tests
This commit is contained in:
Vincent Jacques
2012-12-25 11:50:54 +01:00
parent aac5eec5fd
commit d8e4ece9a7
5 changed files with 28 additions and 7 deletions
+9 -5
View File
@@ -590,11 +590,11 @@ class Repository(github.GithubObject.GithubObject):
url_parameters
)
def get_contents(self, path, ref=GithubObject.NotSet):
def get_contents(self, path, ref=github.GithubObject.NotSet):
assert isinstance(path, (str, unicode)), path
assert ref is GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
url_parameters = dict()
if ref is not GithubObject.NotSet:
if ref is not github.GithubObject.NotSet:
url_parameters["ref"] = ref
headers, data = self._requester.requestAndCheck(
"GET",
@@ -899,11 +899,15 @@ class Repository(github.GithubObject.GithubObject):
url_parameters
)
def get_readme(self):
def get_readme(self, ref=github.GithubObject.NotSet):
assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
url_parameters = dict()
if ref is not github.GithubObject.NotSet:
url_parameters["ref"] = ref
headers, data = self._requester.requestAndCheck(
"GET",
self.url + "/readme",
None,
url_parameters,
None
)
return github.ContentFile.ContentFile(self._requester, data, completed=True)
File diff suppressed because one or more lines are too long
+4
View File
@@ -393,6 +393,10 @@ class Repository(Framework.TestCase):
self.assertEqual(len(self.repo.get_readme().content), 10212)
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)
def testGetArchiveLink(self):
self.assertEqual(self.repo.get_archive_link("tarball"), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master")
self.assertEqual(self.repo.get_archive_link("zipball"), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master")