desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test the ability to use the issues search endpoint.'
def test_search_issues(self):
cassette_name = self.cassette_name('search_issues') with self.recorder.use_cassette(cassette_name): issues = self.gh.search_issues('github3 labels:bugs') assert isinstance(next(issues), github3.search.IssueSearchResult) assert isinstance(issues, github3.structs.SearchIterator)
'Test the ability to use the repository search endpoint.'
def test_search_repositories(self):
cassette_name = self.cassette_name('search_repositories') with self.recorder.use_cassette(cassette_name): repos = self.gh.search_repositories('github3 language:python') assert isinstance(next(repos), github3.search.RepositorySearchResult) assert isinstance(repos, github3.structs.SearchIte...
'Test the ability to use the repository search endpoint.'
def test_search_repositories_with_text_match(self):
self.token_login() cassette_name = self.cassette_name('search_repositories_text_match') with self.recorder.use_cassette(cassette_name, match_requests_on=self.match_on): repos = self.gh.search_repositories('github3 language:python', text_match=True) repo_result = next(repos) assert...
'Test the ability to star a repository.'
def test_star(self):
self.token_login() cassette_name = self.cassette_name('star') with self.recorder.use_cassette(cassette_name): starred = self.gh.star('sigmavirus24', 'github3.py') assert (starred is True)
'Test the ability to update the current authenticated User.'
def test_update_me(self):
cassette_name = self.cassette_name('update_me') self.basic_login() with self.recorder.use_cassette(cassette_name): assert (self.gh.update_me(name='Matt "RFC" Chung') is True) assert (self.gh.update_me(name='Matt Chung') is True)
'Test the ability to retrieve a User.'
def test_user(self):
cassette_name = self.cassette_name('user') with self.recorder.use_cassette(cassette_name): sigmavirus24 = self.gh.user('sigmavirus24') assert isinstance(sigmavirus24, github3.users.User) try: assert repr(sigmavirus24) except UnicodeEncodeError: self.fail('Regression caught...
'Test the ability to unfollow a user.'
def test_unfollow(self):
self.token_login() cassette_name = self.cassette_name('unfollow') with self.recorder.use_cassette(cassette_name): unfollowed = self.gh.unfollow('sigmavirus24') assert (unfollowed is True)
'Test the ability to unstar a repository.'
def test_unstar(self):
self.token_login() cassette_name = self.cassette_name('unstar') with self.recorder.use_cassette(cassette_name): unstarred = self.gh.unstar('sigmavirus24', 'github3.py') assert (unstarred is True)
'Test the ability to retrieve a user by their id.'
def test_user_with_id(self):
cassette_name = self.cassette_name('user_with_id') with self.recorder.use_cassette(cassette_name): sigmavirus24 = self.gh.user_with_id(240830) assert isinstance(sigmavirus24, github3.users.User)
'Test the ability to retrieve tidbits of Zen.'
def test_zen(self):
cassette_name = self.cassette_name('zen') with self.recorder.use_cassette(cassette_name): z = self.gh.zen() assert (z is not None) assert (z != '')
'Test the ability to check the status of /api.'
def test_api(self):
cassette_name = self.cassette_name('api') with self.recorder.use_cassette(cassette_name): api = self.gh.api() assert isinstance(api, dict)
'Test the ability to check the status of /api/last-message.'
def test_last_message(self):
cassette_name = self.cassette_name('last_message') with self.recorder.use_cassette(cassette_name): last_message = self.gh.last_message() assert isinstance(last_message, dict)
'Test the ability to check the status of /api/messages.'
def test_messages(self):
cassette_name = self.cassette_name('messages') with self.recorder.use_cassette(cassette_name): messages = self.gh.messages() assert isinstance(messages, list)
'Test the ability to check the status of /api/status.'
def test_status(self):
cassette_name = self.cassette_name('status') with self.recorder.use_cassette(cassette_name): status = self.gh.status() assert isinstance(status, dict)
'Test the ability to retrieve the latest pages build for a repo.'
def test_latest_pages_build(self):
self.basic_login() cassette_name = self.cassette_name('latest_pages_build') with self.recorder.use_cassette(cassette_name): repository = self.gh.repository('sigmavirus24', 'github3.py') assert (repository is not None) latest_build = repository.latest_pages_build() assert isinstan...
'Test the ability to retrieve information about a repository\'s pages.'
def test_pages(self):
self.basic_login() cassette_name = self.cassette_name('pages') with self.recorder.use_cassette(cassette_name): repository = self.gh.repository('sigmavirus24', 'github3.py') assert (repository is not None) pages_info = repository.pages() assert isinstance(pages_info, github3.repos...
'Test the ability to list the pages builds.'
def test_pages_builds(self):
self.basic_login() cassette_name = self.cassette_name('pages_builds') with self.recorder.use_cassette(cassette_name): repository = self.gh.repository('sigmavirus24', 'github3.py') assert (repository is not None) for build in repository.pages_builds(): assert isinstance(bu...
'Test the ability to delete a milestone.'
def test_delete(self):
self.token_login() cassette_name = self.cassette_name('delete') with self.recorder.use_cassette(cassette_name): repository = self.gh.repository('sigmavirus24', 'github3.py') milestone = repository.milestone(14) assert (milestone.delete() is True)
'Test the ability to update a milestone.'
def test_update(self):
self.token_login() cassette_name = self.cassette_name('update') with self.recorder.use_cassette(cassette_name): repository = self.gh.repository('sigmavirus24', 'github3.py') milestone = repository.milestone(14) assert (milestone.update(title='integration', description='delete me')...
'Test the ability to iterate over milestone labels.'
def test_labels(self):
cassette_name = self.cassette_name('labels') with self.recorder.use_cassette(cassette_name): issue = self.gh.issue('sigmavirus24', 'github3.py', 206) milestone = issue.milestone assert (milestone is not None) for label in milestone.labels(): assert isinstance(label, g...
'Show that a user can iterate over the comments on a gist.'
def test_comments(self):
cassette_name = self.cassette_name('comments') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist(3342247) assert (gist is not None) for comment in gist.comments(): assert isinstance(comment, github3.gists.comment.GistComment)
'Show that a user can comment on a gist.'
def test_create_comment(self):
self.basic_login() cassette_name = self.cassette_name('create_comment') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist('f396190a0d0047be791b') assert (gist is not None) c = gist.create_comment("```ruby\n mac.split(''...
'Show that a user can iterate over the commits in a gist.'
def test_commits(self):
cassette_name = self.cassette_name('commits') with self.recorder.use_cassette(cassette_name, preserve_exact_body_bytes=True): gist = self.gh.gist(1834570) assert (gist is not None) for commit in gist.commits(): assert isinstance(commit, github3.gists.history.GistHistory)
'Show that a user can delete a gist.'
def test_delete(self):
self.basic_login() cassette_name = self.cassette_name('delete') with self.recorder.use_cassette(cassette_name): gist = self.gh.create_gist('Title', {'filename.py': {'content': '# -*- coding: utf-8 -*-'}}) assert isinstance(gist, github3.gists.Gist) assert (gist.delete() i...
'Show that a user can edit the contents of a gist.'
def test_edit(self):
self.basic_login() cassette_name = self.cassette_name('edit') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist(6647085) assert (gist is not None) assert (gist.edit('Updated description', files={'filename.py': {'content': '# New content'}, 'new_file.py': {'...
'Show that a user can iterate over a list of gist files.'
def test_files(self):
cassette_name = self.cassette_name('files') with self.recorder.use_cassette(cassette_name): gists = self.gh.gists_by('sigmavirus24') assert (gists is not None) for gist in gists: files = gist.files() for _file in files: assert isinstance(_file, git...
'Show that a user can fork another user\'s gist.'
def test_fork(self):
self.basic_login() cassette_name = self.cassette_name('fork') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist('8de9b9b0ae2e45383d85') assert (gist is not None) forked = gist.fork() assert isinstance(forked, github3.gists.Gist) assert (str(forked.ow...
'Show that a user can iterate over the forks of a gist.'
def test_forks(self):
cassette_name = self.cassette_name('forks') with self.recorder.use_cassette(cassette_name, preserve_exact_body_bytes=True): gist = self.gh.gist(1834570) assert (gist is not None) for commit in gist.forks(): assert isinstance(commit, github3.gists.gist.Gist)
'Show that a user can check if they\'ve starred a gist.'
def test_is_starred(self):
self.basic_login() cassette_name = self.cassette_name('is_starred') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist(1834570) assert (gist is not None) assert (gist.is_starred() is True)
'Show that a user can star a gist.'
def test_star(self):
self.basic_login() cassette_name = self.cassette_name('star') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist('8de9b9b0ae2e45383d85') assert (gist is not None) assert (gist.star() is True)
'Show that a user can unstar a gist.'
def test_unstar(self):
self.basic_login() cassette_name = self.cassette_name('unstar') with self.recorder.use_cassette(cassette_name): gist = self.gh.gist('8de9b9b0ae2e45383d85') assert (gist is not None) assert (gist.unstar() is True)
'Verify the request to iterate over statuses of a commit.'
def test_statuses(self):
i = self.instance.statuses() self.get_next(i) self.session.get.assert_called_once_with(url_for('statuses'), params={'per_page': 100}, headers={})
'Verify the request to iterate over comments of a commit.'
def test_comments(self):
i = self.instance.comments() self.get_next(i) self.session.get.assert_called_once_with(url_for('comments'), params={'per_page': 100}, headers={})
'Show that an authenticated user can add a member to an org.'
def test_add_member(self):
self.instance.add_member('user', 10) self.session.put.assert_called_once_with('https://api.github.com/teams/10/members/user')
'Show that one can add a repository to an organization.'
def test_add_repository(self):
self.instance.add_repository('name-of-repo', 10) self.session.put.assert_called_once_with('https://api.github.com/teams/10/repos/name-of-repo')
'Show that one can conceal an organization member.'
def test_conceal_member(self):
self.instance.conceal_member('concealed') self.session.delete.assert_called_once_with(url_for('public_members/concealed'))
'Show that one can create a repository in an organization.'
def test_create_repository(self):
self.instance.create_repository('repo-name', 'description', team_id=1) self.post_called_with(url_for('repos'), data={'name': 'repo-name', 'description': 'description', 'homepage': '', 'private': False, 'has_issues': True, 'has_wiki': True, 'auto_init': False, 'team_id': 1, 'gitignore_template': '', 'license_tem...
'Show that one can create a team in an organization.'
def test_create_team(self):
self.instance.create_team('team-name', permission='push') self.post_called_with(url_for('teams'), data={'name': 'team-name', 'repo_names': [], 'permission': 'push'})
'Show that one can edit the organization.'
def test_edit(self):
email = 'billing@cordas.co' corp = 'Company, LLC' self.instance.edit(email, company=corp) self.patch_called_with(url_for(), data={'billing_email': email, 'company': corp})
'Show that a user can compare teams.'
def test_equality(self):
team = self.create_instance_of_described_class() assert (team == self.instance)
'Show that a user can if another user is an organization member.'
def test_is_member(self):
self.instance.is_member('username') self.session.get.assert_called_once_with(url_for('members/username'))
'Show that a user can if another user is a public org member.'
def test_is_public_member(self):
self.instance.is_public_member('username') self.session.get.assert_called_once_with(url_for('public_members/username'))
'Show that a user can publicize their own membership.'
def test_publicize_member(self):
self.instance.publicize_member('username') self.session.put.assert_called_once_with(url_for('public_members/username'))
'Show that one can remove a user from an organization.'
def test_remove_member(self):
self.instance.remove_member('username') self.session.delete.assert_called_once_with(url_for('members/username'))
'Show that one can remove a repository from a team.'
def test_remove_repository(self):
self.instance.remove_repository('repo-name', 10) self.session.delete.assert_called_once_with('https://api.github.com/teams/10/repos/repo-name')
'Assert the Organization name is in the repr.'
def test_repr(self):
assert ('github' in repr(self.instance))
'Show that remove_repository requires a team_id greater than 0.'
def test_remove_repository_requires_positive_team_id(self):
assert (self.instance.remove_repository('name', (-1)) is False) assert (self.session.delete.called is False)
'Show that a user can retrieve a team by id.'
def test_team(self):
self.instance.team(10) self.session.get.assert_called_once_with('https://api.github.com/teams/10')
'Show that team requires a team_id greater than 0.'
def test_team_requires_positive_team_id(self):
self.instance.team((-1)) assert (self.session.get.called is False)
'Show that one must be authenticated to add a member to an org.'
def test_add_member(self):
with pytest.raises(GitHubError): self.instance.add_member('user', 10)
'Show that one must be authenticated to add a repo to an org.'
def test_add_repository(self):
with pytest.raises(GitHubError): self.instance.add_repository('foo', 10)
'Show that one must be authenticated to conceal a member.'
def test_conceal_member(self):
with pytest.raises(GitHubError): self.instance.conceal_member('user')
'Show that one must be authenticated to create a repo for an org.'
def test_create_repository(self):
with pytest.raises(GitHubError): self.instance.create_repository('foo')
'Show that one must be authenticated to create a team for an org.'
def test_create_team(self):
with pytest.raises(GitHubError): self.instance.create_team('foo')
'Show that a user must be authenticated to edit an organization.'
def test_edit(self):
with pytest.raises(GitHubError): self.instance.edit('foo')
'Show that a user must be authenticated to publicize membership.'
def test_publicize_member(self):
with pytest.raises(GitHubError): self.instance.publicize_member('foo')
'Show that a user must be authenticated to remove a member.'
def test_remove_member(self):
with pytest.raises(GitHubError): self.instance.remove_member('foo')
'Show that a user must be authenticated to remove a repository.'
def test_remove_repository(self):
with pytest.raises(GitHubError): self.instance.remove_repository('repo-name', 10)
'Show that a user must be authenticated to retrieve a team.'
def test_team(self):
with pytest.raises(GitHubError): self.instance.team(10)
'Show that one can iterate over an organization\'s events.'
@mock.patch('warnings.warn') def test_events(self, warn_mock):
i = self.instance.events() self.get_next(i) self.session.get.assert_called_once_with(url_for('events'), params={'per_page': 100}, headers={}) warn_mock.assert_called_once_with('This method is deprecated. Please use ``public_events`` instead.', DeprecationWarning)
'Show that one can iterate over all members.'
def test_members(self):
i = self.instance.members() self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100}, headers={})
'Show that one can iterate over all members with 2fa_disabled.'
def test_members_filters(self):
i = self.instance.members(filter='2fa_disabled') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100, 'filter': '2fa_disabled'}, headers={})
'Show that one cannot pass a bogus filter to the API.'
def test_members_excludes_fake_filters(self):
i = self.instance.members(filter='bogus-filter') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100}, headers={})
'Show that one can iterate over all admins.'
def test_members_roles(self):
i = self.instance.members(role='admin') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100, 'role': 'admin'}, headers={'Accept': 'application/vnd.github.ironman-preview+json'})
'Show that one cannot pass a bogus role to the API.'
def test_members_excludes_fake_roles(self):
i = self.instance.members(role='bogus-role') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100}, headers={})
'Show that one can iterate over an organization\'s public events.'
def test_public_events(self):
i = self.instance.public_events() self.get_next(i) self.session.get.assert_called_once_with(url_for('events'), params={'per_page': 100}, headers={})
'Show that one can iterate over all public members.'
def test_public_members(self):
i = self.instance.public_members() self.get_next(i) self.session.get.assert_called_once_with(url_for('public_members'), params={'per_page': 100}, headers={})
'Show that one can iterate over an organization\'s repositories.'
def test_repositories(self):
i = self.instance.repositories() self.get_next(i) self.session.get.assert_called_once_with(url_for('repos'), params={'per_page': 100}, headers={})
'Show that one can pass a repository type.'
def test_respositories_accepts_type(self):
i = self.instance.repositories('all') self.get_next(i) self.session.get.assert_called_once_with(url_for('repos'), params={'type': 'all', 'per_page': 100}, headers={})
'Show that one can iterate over an organization\'s teams.'
def test_teams(self):
i = self.instance.teams() self.get_next(i) self.session.get.assert_called_once_with(url_for('teams'), params={'per_page': 100}, headers={})
'Show that one must be authenticated to retrieve an org\'s teams.'
def test_teams_requires_auth(self):
self.session.has_auth.return_value = False with pytest.raises(GitHubError): self.instance.teams()
'Show that __iter__ is called when refreshing.'
def test_refresh(self):
with mock.patch.object(GitHubIterator, '__iter__') as i: self.instance.refresh() assert (i.called is True)
'Show that __iter__ is called when refreshing.'
def test_refresh_conditional(self):
with mock.patch.object(GitHubIterator, '__iter__') as i: self.instance.refresh(True) assert (i.called is True)
'Test that the Iterator defaults the per_page parameter to 100'
def test_sets_per_page_to_100(self):
self.session.get.return_value = mock.Mock(status_code=200, json=(lambda : []), links={}) for i in self.instance: break self.session.get.assert_called_once_with(self.url, params={'per_page': 100}, headers={})
'Show that instance string is formatted correctly.'
def test_str(self):
assert str(self.instance).startswith('<GitHubIterator')
'Show that one can add a member to an organization team.'
def test_add_member(self):
self.instance.add_member('user') self.session.put.assert_called_once_with(url_for('members/user'))
'Show that one can add a repository to an organization team.'
def test_add_repository(self):
self.instance.add_repository('name-of-repo') self.put_called_with(url_for('repos/name-of-repo'), data={'permission': ''}) self.instance.add_repository('name-of-repo', permission='push') self.put_called_with(url_for('repos/name-of-repo'), data={'permission': 'push'})
'Show that a user can delete an organization team.'
def test_delete(self):
self.instance.delete() self.session.delete.assert_called_once_with(url_for())
'Show that a user can edit a team.'
def test_edit(self):
self.instance.edit('name', 'admin') self.patch_called_with(url_for(), data={'name': 'name', 'permission': 'admin'})
'Show that a user can check if a team has access to a repository.'
def test_has_repository(self):
self.instance.has_repository('org/repo') self.session.get.assert_called_once_with(url_for('repos/org/repo'))
'Show that a user can check if another user is a team member.'
def test_is_member(self):
self.instance.is_member('username') self.session.get.assert_called_once_with(url_for('members/username'))
'Show that a user can check if another user is a team member.'
def test_remove_member(self):
self.instance.remove_member('username') self.session.delete.assert_called_once_with(url_for('members/username'))
'Show that a user can remove a repository from a team.'
def test_remove_repository(self):
self.instance.remove_repository('repo') self.session.delete.assert_called_once_with(url_for('/repos/repo'))
'Show that adding a repo to a team requires authentication.'
def test_add_member_requires_auth(self):
with pytest.raises(GitHubError): self.instance.add_member('user')
'Show that adding a repo to a team requires authentication.'
def test_add_repository_requires_auth(self):
with pytest.raises(GitHubError): self.instance.add_repository('repo')
'Show that deleteing a team requires authentication.'
def test_delete_requires_auth(self):
with pytest.raises(GitHubError): self.instance.delete()
'Show that editing a team requires authentication.'
def test_edit_requires_auth(self):
with pytest.raises(GitHubError): self.instance.edit('name')
'Show that checking a team\'s access to a repo needs auth.'
def test_has_repository_requires_auth(self):
with pytest.raises(GitHubError): self.instance.has_repository('org/repo')
'Show that checking a user\'s team membership requires auth.'
def test_is_member_requires_auth(self):
with pytest.raises(GitHubError): self.instance.is_member('user')
'Show that removing a team member requires authentication.'
def test_remove_member_requires_auth(self):
with pytest.raises(GitHubError): self.instance.remove_member('user')
'Show that removing a repo from a team requires authentication.'
def test_remove_repository_requires_auth(self):
with pytest.raises(GitHubError): self.instance.remove_repository('repo')
'Show that one can iterate over all members of a Team.'
def test_members(self):
i = self.instance.members() self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100}, headers={})
'Show that one can iterate of all maintainers of a Team.'
def test_members_roles(self):
i = self.instance.members(role='maintainer') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100, 'role': 'maintainer'}, headers={'Accept': 'application/vnd.github.ironman-preview+json'})
'Show that one cannot pass a bogus role to the API.'
def test_members_excludes_fake_roles(self):
i = self.instance.members(role='bogus-role') self.get_next(i) self.session.get.assert_called_once_with(url_for('members'), params={'per_page': 100}, headers={})
'Show that one needs to authenticate to get team members.'
def test_members_requires_auth(self):
self.session.has_auth.return_value = False with pytest.raises(GitHubError): self.instance.members()
'Show that one can iterate over an organization\'s repositories.'
def test_repositories(self):
i = self.instance.repositories() self.get_next(i) self.session.get.assert_called_once_with(url_for('repos'), params={'per_page': 100}, headers={'Accept': 'application/vnd.github.ironman-preview+json'})
'Verify the request to add a collaborator to a repository.'
def test_add_collaborator(self):
self.instance.add_collaborator('sigmavirus24') self.session.put.assert_called_once_with(url_for('collaborators/sigmavirus24'))
'Verify no request is made when adding `None` as a collaborator.'
def test_add_null_collaborator(self):
self.instance.add_collaborator(None) assert (self.session.put.called is False)
'Test retrieving an asset uses the right headers. The Releases section of the API is still in Beta and uses custom headers'
def test_asset(self):
self.instance.asset(1) self.session.get.assert_called_once_with(url_for('releases/assets/1'), headers={'Accept': 'application/vnd.github.manifold-preview'})
'Test that a positive asset id is required.'
def test_asset_requires_a_positive_id(self):
self.instance.asset(0) assert (self.session.get.called is False)