Permalink
Browse files

Fix a few tests, add a couple others.

  • Loading branch information...
1 parent 9d5bbad commit 1d632da84200a800722bc820dee1099a994797e3 @sigmavirus24 sigmavirus24 committed Oct 2, 2012
Showing with 47 additions and 29 deletions.
  1. +25 −26 github3/repos.py
  2. +8 −0 tests/test_gists.py
  3. +3 −3 tests/test_github.py
  4. +11 −0 tests/test_repos.py
View
@@ -824,10 +824,11 @@ def label(self, name):
return Label(json, self) if json else None
def iter_assignees(self, number=-1):
- """Iterate over all available assignees to which an issue may be assigned.
+ """Iterate over all available assignees to which an issue may be
+ assigned.
- :param int number: (optional), number of assignees to return. Default: -1
- returns all available assignees
+ :param int number: (optional), number of assignees to return. Default:
+ -1 returns all available assignees
:returns: list of :class:`User <github3.users.User>`\ s
"""
url = self._build_url('assignees', base_url=self._api)
@@ -845,8 +846,8 @@ def list_assignees(self):
def iter_branches(self, number=-1):
"""Iterate over the branches in this repository.
- :param int number: (optional), number of branches to return. Default: -1
- returns all branches
+ :param int number: (optional), number of branches to return. Default:
+ -1 returns all branches
:returns: list of :class:`Branch <Branch>`\ es
"""
# Paginate?
@@ -866,8 +867,8 @@ def list_branches(self):
def iter_comments(self, number=-1):
"""Iterate over comments on all commits in the repository.
- :param int number: (optional), number of comments to return. Default: -1
- returns all comments
+ :param int number: (optional), number of comments to return. Default:
+ -1 returns all comments
:returns: list of :class:`RepoComment <RepoComment>`\ s
"""
# Paginate?
@@ -889,8 +890,8 @@ def iter_comments_on_commit(self, sha, number=1):
:param sha: (required), sha of the commit to list comments on
:type sha: str
- :param int number: (optional), number of comments to return. Default: -1
- returns all comments
+ :param int number: (optional), number of comments to return. Default:
+ -1 returns all comments
:returns: list of :class:`RepoComment <RepoComment>`\ s
"""
url = self._build_url('commits', sha, 'comments', base_url=self._api)
@@ -916,12 +917,12 @@ def iter_commits(self, sha='', path='', author='', number=-1):
listed
:param str author: (optional), GitHub login, real name, or email to
filter commits by (using commit author)
- :param int number: (optional), number of comments to return. Default: -1
- returns all comments
+ :param int number: (optional), number of comments to return. Default:
+ -1 returns all comments
:returns: list of :class:`RepoCommit <RepoCommit>`\ s
"""
- params={}
+ params = {}
if sha:
params['sha'] = sha
if path:
@@ -943,7 +944,7 @@ def list_commits(self, sha='', path='', author=''):
:returns: list of :class:`RepoCommit <RepoCommit>`\ s
"""
- params={}
+ params = {}
if sha:
params['sha'] = sha
if path:
@@ -959,8 +960,8 @@ def iter_contributors(self, anon=False, number=-1):
:param anon: (optional), True lists anonymous contributors as well
:type anon: bool
- :param number: (optional), number of contributors to return. Default: -1
- returns all contributors
+ :param number: (optional), number of contributors to return. Default:
+ -1 returns all contributors
:type number: int
:returns: list of :class:`User <github3.users.User>`\ s
"""
@@ -989,8 +990,8 @@ def list_contributors(self, anon=False):
def iter_downloads(self, number=-1):
"""Iterate over available downloads for this repository.
- :param int number: (optional), number of downloads to return. Default: -1
- returns all available downloads
+ :param int number: (optional), number of downloads to return. Default:
+ -1 returns all available downloads
:returns: list of :class:`Download <Download>`\ s
"""
url = self._build_url('downloads', base_url=self._api)
@@ -1057,7 +1058,7 @@ def list_forks(self, sort=''):
return [Repository(r, self) for r in json]
@requires_auth
- def iter_hooks(self):
+ def iter_hooks(self, number=-1):
"""Iterate over hooks registered on this repository.
:param int number: (optional), number of hoks to return. Default: -1
@@ -1247,8 +1248,8 @@ def list_labels(self):
def iter_languages(self, number=-1):
"""Iterate over the programming languages used in the repository.
- :param int number: (optional), number of languages to return. Default: -1
- returns all used languages
+ :param int number: (optional), number of languages to return. Default:
+ -1 returns all used languages
:returns: list of tuples
"""
url = self._build_url('languages', base_url=self._api)
@@ -1888,7 +1889,6 @@ def __repr__(self):
return '<Repository Tag [{0}]>'.format(self.name)
-# TODO(Ian) Come back to this after doing models.py
class RepoComment(BaseComment):
"""The :class:`RepoComment <RepoComment>` object. This stores the
information about a comment on a file in a repository.
@@ -1913,7 +1913,8 @@ def __init__(self, comment, session=None):
self.user = User(comment.get('user'), self)
def __repr__(self):
- return '<Repository Comment [{0}/{1}]>'.format(self.commit_id[:7], self.user.login or '')
+ return '<Repository Comment [{0}/{1}]>'.format(self.commit_id[:7],
+ self.user.login or '')
def _update_(self, comment):
super(RepoComment, self)._update_(comment)
@@ -1948,7 +1949,6 @@ def update(self, body, sha, line, path, position):
return False
-# TODO(Ian) Come back to this after doing models.py
class RepoCommit(BaseCommit):
"""The :class:`RepoCommit <RepoCommit>` object. This represents a commit as
viewed by a :class:`Repository`. This is different from a Commit object
@@ -1958,9 +1958,9 @@ class RepoCommit(BaseCommit):
def __init__(self, commit, session=None):
super(RepoCommit, self).__init__(commit, session)
#: :class:`User <github3.users.User>` who authored the commit.
- self.author = User(commit.get('author'), self._session)
+ self.author = User(commit.get('author', {}), self._session)
#: :class:`User <github3.users.User>` who committed the commit.
- self.committer = User(commit.get('committer'), self._session)
+ self.committer = User(commit.get('committer', {}), self._session)
#: :class:`Commit <github3.git.Commit>`.
self.commit = Commit(commit.get('commit'), self._session)
@@ -1980,7 +1980,6 @@ def __init__(self, commit, session=None):
self.files = commit.get('files', [])
def __repr__(self):
- # TODO(Ian) come back to this after models.py
return '<Repository Commit [{0}]>'.format(self.sha[:7])
View
@@ -18,17 +18,25 @@ def test_gists_not_empty(self):
def test_repr(self):
expect(repr(self.gist)) != ''
+ def test_iter_forks(self):
+ expect(next(self.gist.iter_forks())).isinstance(Gist)
+
def test_list_forks(self):
expect(self.gist.list_forks()).isinstance(list)
+ expect(self.gist.list_forks()).list_of(Gist)
def test_updated_at(self):
expect(self.gist.updated_at).isinstance(datetime)
def test_files(self):
expect(self.gist.files) >= 0
+ def test_iter_files(self):
+ expect(next(self.gist.iter_files())).isinstance(GistFile)
+
def test_list_files(self):
expect(self.gist.list_files()).isinstance(list)
+ expect(self.gist.list_files()).list_of(GistFile)
def test_forks(self):
expect(self.gist.forks) >= 0
View
@@ -228,16 +228,16 @@ def test_authorizations_requires_auth(self):
self.raisesGHE(self.g.authorize, 'foo', 'bar', ['gist', 'user'])
def test_list_emails(self):
- self.raisesGHE(self.g.list_emails())
+ self.raisesGHE(self.g.list_emails)
if self.auth:
expect(self._g.list_emails()).list_of(dict)
def test_iter_emails(self):
- self.raisesGHE(self.g.list_emails())
+ self.raisesGHE(self.g.iter_emails)
if self.auth:
- expect(next(self._g.list_emails())).isinstance(dict)
+ expect(next(self._g.iter_emails())).isinstance(dict)
def test_list_events(self):
expect(self.g.list_events()).list_of(Event)
View
@@ -180,6 +180,14 @@ def test_list_assignees(self):
return
self.fail('No user with login sigmavirus24')
+ def test_iter_assignees(self):
+ assignees = [a for a in self.repo.iter_assignees()]
+ expect(assignees).list_of(User)
+ for a in assignees:
+ if a.login == 'sigmavirus24':
+ return
+ self.fail('No user with login sigmavirus24')
+
def test_list_branches(self):
branches = self.repo.list_branches()
expect(branches).list_of(Branch)
@@ -188,6 +196,9 @@ def test_list_branches(self):
return
self.fail('No branch named master')
+ def test_iter_branches(self):
+ expect(next(self.repo.iter_branches())).isinstance(Branch)
+
def test_list_comments(self):
comments = self.requests_repo.list_comments()
expect(comments).list_of(RepoComment)

0 comments on commit 1d632da

Please sign in to comment.