Ejemplo n.º 1
0
    def test_iter_user_issues(self):
        self.response('issue', _iter=True)
        self.get('https://api.github.com/user/issues')
        self.conf.update(params={})

        with expect.githuberror():
            self.g.iter_user_issues()

        self.login()
        expect(next(self.g.iter_user_issues())).isinstance(
            github3.issues.Issue)
        self.mock_assertions()

        params = {
            'filter': 'assigned',
            'state': 'closed',
            'labels': 'bug',
            'sort': 'created',
            'direction': 'asc',
            'since': '2012-05-20T23:10:27Z'
        }
        self.conf.update(params=params)
        expect(next(self.g.iter_user_issues(**params))).isinstance(
            github3.issues.Issue)
        self.mock_assertions()
Ejemplo n.º 2
0
    def test_iter_repos(self):
        self.response('repo', _iter=True)
        self.get(self.api + '/repos')

        expect(next(self.team.iter_repos())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()
Ejemplo n.º 3
0
    def test_gitignore_template(self):
        self.response('template')
        self.get('https://api.github.com/gitignore/templates/Python')

        template = self.g.gitignore_template('Python')
        expect(template.startswith('*.py[cod]')).is_True()
        self.mock_assertions()
Ejemplo n.º 4
0
    def test_create_repo(self):
        self.response('repo', 201)
        self.post(self.api + '/repos')
        self.conf = {
            'data': {
                'name': 'repo',
                'description': 'desc',
                'homepage': '',
                'private': False,
                'has_issues': True,
                'has_wiki': True,
                'has_downloads': True,
                'auto_init': False,
                'team_id': 1,
                'gitignore_template': '',
            }
        }

        with expect.githuberror():
            self.org.create_repo(None)

        self.not_called()
        self.login()
        expect(self.org.create_repo('repo', 'desc', team_id=1)).isinstance(
            github3.repos.Repository)
        self.mock_assertions()
Ejemplo n.º 5
0
    def test_iter_public_members(self):
        self.response('user', _iter=True)
        self.get(self.api + '/public_members')

        expect(next(self.org.iter_public_members())).isinstance(
            github3.users.User)
        self.mock_assertions()
Ejemplo n.º 6
0
 def test_search_email(self):
     self.response('legacy_email')
     self.get('https://api.github.com/{0}/{1}/{2}/{3}'.format(
         'legacy', 'user', 'email', '*****@*****.**'))
     user = self.g.search_email('*****@*****.**')
     expect(user).isinstance(github3.legacy.LegacyUser)
     self.mock_assertions()
Ejemplo n.º 7
0
    def test_commit(self):
        self.response('commit')
        sha = '76dcc6cb4b9860034be81b7e58adc286a115aa97'
        self.get(self.api + 'commits/' + sha)

        expect(self.repo.commit(sha)).isinstance(repos.commit.RepoCommit)
        self.mock_assertions()
Ejemplo n.º 8
0
    def test_blob(self):
        self.response("blob")
        sha = "3ceb856e2f14e9669fed6384e58c9a1590a2314f"
        self.get(self.api + "git/blobs/" + sha)

        expect(self.repo.blob(sha)).isinstance(github3.git.Blob)
        self.mock_assertions()
Ejemplo n.º 9
0
    def test_commit_comment(self):
        self.response("commit_comment")
        comment_id = 1380832
        self.get(self.api + "comments/{0}".format(comment_id))

        expect(self.repo.commit_comment(comment_id)).isinstance(github3.repos.RepoComment)
        self.mock_assertions()
Ejemplo n.º 10
0
    def test_subscription(self):
        self.response('subscription')
        self.get(self.api + '/subscription')

        expect(self.thread.subscription()).isinstance(
            github3.notifications.Subscription)
        self.mock_assertions()
Ejemplo n.º 11
0
    def test_set(self):
        self.response('subscription')
        self.put(self.api)
        self.conf = {'data': {'subscribed': True, 'ignored': False}}

        expect(self.subscription.set(True, False)).is_None()
        self.mock_assertions()
Ejemplo n.º 12
0
    def test_mark(self):
        self.response('', 205)
        self.patch(self.api)
        self.conf = {'data': {'read': True}}

        expect(self.thread.mark()).is_True()
        self.mock_assertions()
Ejemplo n.º 13
0
    def test_set(self):
        self.response('subscription')
        self.put(self.api)
        self.conf = {'data': {'subscribed': True, 'ignored': False}}

        expect(self.subscription.set(True, False)).is_None()
        self.mock_assertions()
Ejemplo n.º 14
0
    def test_subscription(self):
        self.response('subscription')
        self.get(self.api + '/subscription')

        expect(self.thread.subscription()).isinstance(
            github3.notifications.Subscription)
        self.mock_assertions()
Ejemplo n.º 15
0
    def test_login(self):
        self.g.login('user', 'password')
        expect(self.g._session.auth) == ('user', 'password')

        self.g.login(token='FakeOAuthToken')
        auth = self.g._session.headers.get('Authorization')
        expect(auth) == 'token FakeOAuthToken'
Ejemplo n.º 16
0
    def test_contents(self):
        self.response("contents")
        filename = "setup.py"
        self.get(self.api + "contents/" + filename)

        expect(self.repo.contents(filename)).isinstance(github3.repos.Contents)
        self.mock_assertions()
Ejemplo n.º 17
0
    def test_search_users(self):
        self.response('legacy_user')
        self.get('https://api.github.com/{0}/{1}/{2}/{3}'.format(
            'legacy', 'user', 'search', 'sigmavirus24'))
        self.conf.update({'params': {}})
        users = self.g.search_users('sigmavirus24')
        expect(users[0]).isinstance(github3.legacy.LegacyUser)
        expect(repr(users[0]).startswith('<Legacy User')).is_True()
        self.mock_assertions()

        users = self.g.search_users('sigmavirus24', sort='Foobar')
        self.mock_assertions()

        users = self.g.search_users('sigmavirus24', order='Foobar')
        self.mock_assertions()

        self.conf.update({'params': {'start_page': 2}})
        self.g.search_users('sigmavirus24', 2)
        self.mock_assertions()

        self.conf.update({'params': {'sort': 'joined'}})
        self.g.search_users('sigmavirus24', sort='joined', order='Foobar')
        self.mock_assertions()

        self.conf.update({'params': {'order': 'asc'}})
        self.g.search_users('sigmavirus24', order='asc')
        self.mock_assertions()
Ejemplo n.º 18
0
    def test_iter_subscriptions(self):
        self.response('repo', 200, _iter=True)
        self.get(self.api + '/subscriptions')

        expect(next(self.user.iter_subscriptions())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()
Ejemplo n.º 19
0
    def test_set_user_agent(self):
        ua = 'Fake User Agents'
        self.g.set_user_agent(ua)
        expect(self.g._session.headers['User-Agent']) == ua

        self.g.set_user_agent(None)
        expect(self.g._session.headers['User-Agent']) == ua
Ejemplo n.º 20
0
    def test_update(self):
        self.response('authorization', 200)
        self.post(self.api)
        data = {
            'scopes': ['user']
        }
        self.conf = {'data': data}

        with expect.githuberror():
            self.auth.update()

        def sub_test():
            expect(self.auth.update(**data)).is_True()
            self.mock_assertions()

        self.login()
        expect(self.auth.update()).is_False()
        self.not_called()

        sub_test()

        del(data['scopes'])
        data['add_scopes'] = ['repo']
        sub_test()

        del(data['add_scopes'])
        data['rm_scopes'] = ['user']
        self.conf['data'] = {'remove_scopes': ['user']}
        sub_test()
        self.conf['data'] = data

        del(data['rm_scopes'])
        data['note'] = 'GitHub API'
        data['note_url'] = 'http://example.com'
        sub_test()
Ejemplo n.º 21
0
    def test_pubsubhubbub(self):
        self.response('', 204)
        self.post('https://api.github.com/hub')
        body = [('hub.mode', 'subscribe'),
                ('hub.topic', 'https://github.com/foo/bar/events/push'),
                ('hub.callback', 'https://localhost/post')]
        self.conf = {}

        with expect.githuberror():
            self.g.pubsubhubbub('', '', '')

        self.login()
        expect(self.g.pubsubhubbub('', '', '')).is_False()
        self.not_called()

        expect(self.g.pubsubhubbub('foo', 'https://example.com', 'foo')
               ).is_False()
        self.not_called()

        d = dict([(k[4:], v) for k, v in body])
        expect(self.g.pubsubhubbub(**d)).is_True()
        _, kwargs = self.request.call_args
        expect('data').is_in(kwargs)
        expect(body) == kwargs['data']
        self.mock_assertions()
Ejemplo n.º 22
0
    def test_edit(self):
        self.response('hook', 200)
        self.patch(self.api)
        data = {
            'name': 'hookname',
            'config': {'push': 'http://example.com'},
            'events': ['push'],
            'add_events': ['fake_ev'],
            'rm_events': ['fake_ev'],
            'active': True,
        }
        self.conf = {'data': data.copy()}
        self.conf['data']['remove_events'] = data['rm_events']
        del(self.conf['data']['rm_events'])

        with expect.githuberror():
            self.hook.edit(**data)

        self.login()
        expect(self.hook.edit(None, None, None)).is_False()
        expect(self.hook.edit('True', None, None)).is_False()
        expect(self.hook.edit(None, 'True', None)).is_False()
        expect(self.hook.edit(None, None, {})).is_False()
        self.not_called()

        expect(self.hook.edit(**data)).is_True()
        self.mock_assertions()
Ejemplo n.º 23
0
 def test_search_email(self):
     self.response('legacy_email')
     self.get('https://api.github.com/{0}/{1}/{2}/{3}'.format(
              'legacy', 'user', 'email', '*****@*****.**'))
     user = self.g.search_email('*****@*****.**')
     expect(user).isinstance(github3.legacy.LegacyUser)
     self.mock_assertions()
Ejemplo n.º 24
0
    def test_set_user_agent(self):
        ua = 'Fake User Agents'
        self.g.set_user_agent(ua)
        expect(self.g._session.headers['User-Agent']) == ua

        self.g.set_user_agent(None)
        expect(self.g._session.headers['User-Agent']) == ua
Ejemplo n.º 25
0
    def test_patch(self):
        self.response('archive', 200)
        self.get(self.api)
        self.conf.update(headers={'Accept': 'application/vnd.github.patch'})

        expect(self.comp.patch().startswith(b'archive_data')).is_True()
        self.mock_assertions()
Ejemplo n.º 26
0
    def test_login(self):
        self.g.login('user', 'password')
        expect(self.g._session.auth) == ('user', 'password')

        self.g.login(token='FakeOAuthToken')
        auth = self.g._session.headers.get('Authorization')
        expect(auth) == 'token FakeOAuthToken'
Ejemplo n.º 27
0
    def test_iter_comments(self):
        self.response('issue_comment', _iter=True)
        self.get(self.api + '/comments')

        expect(next(self.i.iter_comments())).isinstance(
            github3.issues.IssueComment)
        self.mock_assertions()
Ejemplo n.º 28
0
    def test_gitignore_template(self):
        self.response('template')
        self.get('https://api.github.com/gitignore/templates/Python')

        template = self.g.gitignore_template('Python')
        expect(template.startswith('*.py[cod]')).is_True()
        self.mock_assertions()
Ejemplo n.º 29
0
    def test_blob(self):
        self.request.return_value = generate_response('blob')
        sha = '3ceb856e2f14e9669fed6384e58c9a1590a2314f'
        self.args = ('GET', self.api + 'git/blobs/' + sha)

        expect(self.repo.blob(sha)).isinstance(github3.git.Blob)
        self.mock_assertions()
Ejemplo n.º 30
0
    def test_commit(self):
        self.request.return_value = generate_response('commit')
        sha = '76dcc6cb4b9860034be81b7e58adc286a115aa97'
        self.args = ('GET', self.api + 'commits/' + sha)

        expect(self.repo.commit(sha)).isinstance(github3.repos.RepoCommit)
        self.mock_assertions()
Ejemplo n.º 31
0
    def test_mark(self):
        self.response('', 205)
        self.patch(self.api)
        self.conf = {}

        expect(self.thread.mark()).is_True()
        self.mock_assertions()
Ejemplo n.º 32
0
    def test_commit(self):
        self.response('commit')
        sha = '76dcc6cb4b9860034be81b7e58adc286a115aa97'
        self.get(self.api + 'commits/' + sha)

        expect(self.repo.commit(sha)).isinstance(github3.repos.RepoCommit)
        self.mock_assertions()
Ejemplo n.º 33
0
    def test_iter_network_events(self):
        self.response('event', _iter=True)
        self.get(self.api.replace('repos', 'networks', 1) + 'events')

        e = next(self.repo.iter_network_events())
        expect(e).isinstance(github3.events.Event)
        self.mock_assertions()
Ejemplo n.º 34
0
    def test_iter_subscribers(self):
        self.response('user', _iter=True)
        self.get(self.api + 'subscribers')

        u = next(self.repo.iter_subscribers())
        expect(u).isinstance(github3.users.User)
        self.mock_assertions()
Ejemplo n.º 35
0
    def test_iter_labels(self):
        self.response('label', _iter=True)
        self.get(self.api + 'labels')

        l = next(self.repo.iter_labels())
        expect(l).isinstance(github3.repos.Label)
        self.mock_assertions()
Ejemplo n.º 36
0
    def test_iter_milestones(self):
        self.response('milestone', _iter=True)
        self.get(self.api + 'milestones')

        m = next(self.repo.iter_milestones())
        expect(m).isinstance(github3.issues.Milestone)
        self.mock_assertions()
Ejemplo n.º 37
0
    def test_contents(self):
        self.request.return_value = generate_response('contents')
        filename = 'setup.py'
        self.args = ('GET', self.api + 'contents/' + filename)

        expect(self.repo.contents(filename)).isinstance(github3.repos.Contents)
        self.mock_assertions()
Ejemplo n.º 38
0
    def test_search_users(self):
        self.response('legacy_user')
        self.get('https://api.github.com/{0}/{1}/{2}/{3}'.format(
                 'legacy', 'user', 'search', 'sigmavirus24'))
        self.conf.update({'params': {}})
        users = self.g.search_users('sigmavirus24')
        expect(users[0]).isinstance(github3.legacy.LegacyUser)
        expect(repr(users[0]).startswith('<Legacy User')).is_True()
        self.mock_assertions()

        users = self.g.search_users('sigmavirus24', sort='Foobar')
        self.mock_assertions()

        users = self.g.search_users('sigmavirus24', order='Foobar')
        self.mock_assertions()

        self.conf.update({'params': {'start_page': 2}})
        self.g.search_users('sigmavirus24', 2)
        self.mock_assertions()

        self.conf.update({'params': {'sort': 'joined'}})
        self.g.search_users('sigmavirus24', sort='joined', order='Foobar')
        self.mock_assertions()

        self.conf.update({'params': {'order': 'asc'}})
        self.g.search_users('sigmavirus24', order='asc')
        self.mock_assertions()
Ejemplo n.º 39
0
    def test_iter_subscriptions(self):
        self.response('repo', 200, _iter=True)
        self.get(self.api + '/subscriptions')

        expect(next(self.user.iter_subscriptions())).isinstance(
            github3.repos.Repository)
        self.mock_assertions()
Ejemplo n.º 40
0
    def test_patch(self):
        self.response('archive', 200)
        self.get(self.api)
        self.conf = {'headers': {'Accept': 'application/vnd.github.patch'}}

        expect(self.pull.patch()) != ''
        self.mock_assertions()
Ejemplo n.º 41
0
    def test_catch_etags(self):
        self.response('user', _iter=True, etag='"foobarbogus"')
        self.get(self.api_url)
        self.conf = {'params': None, 'headers': {}}

        expect(next(self.i)).isinstance(github3.users.User)
        expect(self.i.etag) == '"foobarbogus"'
        self.mock_assertions()
Ejemplo n.º 42
0
 def test_nexts(self):
     self.response('user', _iter=True)
     self.get(self.api_url)
     self.conf = {'params': None, 'headers': {}}
     self.j = GitHubIterator(self.num, self.api_url, github3.users.User,
                             self.g)
     expect(self.j.next().login) == next(self.i).login
     self.mock_assertions()
Ejemplo n.º 43
0
    def test_iter_branches(self):
        self.response('branch', _iter=True)
        self.get(self.api + 'branches')
        self.conf = {'params': None}

        b = next(self.repo.iter_branches())
        expect(b).isinstance(repos.branch.Branch)
        self.mock_assertions()
Ejemplo n.º 44
0
    def test_iter_languages(self):
        #: repos/:login/:repo/languages is just a dictionary, so _iter=False
        self.response('language')
        self.get(self.api + 'languages')

        l = next(self.repo.iter_languages())
        expect(l).isinstance(tuple)
        self.mock_assertions()
Ejemplo n.º 45
0
    def test_iter_issue_events(self):
        self.response('issue_event', _iter=True)
        self.get(self.api + 'issues/events')
        self.conf = {'params': None}

        e = next(self.repo.iter_issue_events())
        expect(e).isinstance(github3.issues.event.IssueEvent)
        self.mock_assertions()
Ejemplo n.º 46
0
    def test_iter_downloads(self):
        self.response('download', _iter=True)
        self.get(self.api + 'downloads')
        self.conf = {'params': None}

        d = next(self.repo.iter_downloads())
        expect(d).isinstance(repos.download.Download)
        self.mock_assertions()
Ejemplo n.º 47
0
    def test_iter_comments_on_commit(self):
        self.response('repo_comment', _iter=True)
        self.get(self.api + 'commits/fakesha/comments')
        self.conf = {'params': None}

        c = next(self.repo.iter_comments_on_commit('fakesha'))
        expect(c).isinstance(repos.comment.RepoComment)
        self.mock_assertions()
Ejemplo n.º 48
0
    def test_is_assignee(self):
        self.response('', 204)
        self.get(self.api + 'assignees/login')

        expect(self.repo.is_assignee(None)).is_False()
        self.not_called()
        expect(self.repo.is_assignee('login')).is_True()
        self.mock_assertions()
Ejemplo n.º 49
0
    def test_iter_assignees(self):
        self.response('user', _iter=True)
        self.get(self.api + 'assignees')
        self.conf = {'params': None}

        u = next(self.repo.iter_assignees())
        expect(u).isinstance(github3.users.User)
        self.mock_assertions()
Ejemplo n.º 50
0
    def test_is_collaborator(self):
        self.response('', 204)
        self.get(self.api + 'collaborators/user')

        expect(self.repo.is_collaborator(None)).is_False()
        self.not_called()
        expect(self.repo.is_collaborator('user')).is_True()
        self.mock_assertions()
Ejemplo n.º 51
0
    def test_issue(self):
        self.response('issue')
        self.get(self.api + 'issues/2')

        expect(self.repo.issue(-2)).is_None()
        self.not_called()
        expect(self.repo.issue(2)).isinstance(github3.issues.Issue)
        self.mock_assertions()
Ejemplo n.º 52
0
    def test_iter_events(self):
        self.response('event', _iter=True)
        self.get('https://api.github.com/events')
        self.conf.update(params=None)

        event = next(self.g.iter_events())
        expect(event).isinstance(github3.events.Event)
        self.mock_assertions()
Ejemplo n.º 53
0
    def test_git_commit(self):
        self.response('git_commit')
        self.get(self.api + 'git/commits/fakesha')

        expect(self.repo.git_commit(None)).is_None()
        self.not_called()
        expect(self.repo.git_commit('fakesha')).isinstance(github3.git.Commit)
        self.mock_assertions()
Ejemplo n.º 54
0
    def test_edit_failed(self):
        self.response('', 404)
        self.patch(self.api)
        self.conf = {}

        self.login()
        expect(self.hook.edit()).is_False()
        self.mock_assertions()
Ejemplo n.º 55
0
    def test_download(self):
        self.response('download')
        self.get(self.api + 'downloads/2')

        expect(self.repo.download(-2)).is_None()
        self.not_called()
        expect(self.repo.download(2)).isinstance(repos.download.Download)
        self.mock_assertions()
Ejemplo n.º 56
0
    def test_label(self):
        self.response('label')
        self.get(self.api + 'labels/name')

        expect(self.repo.label(None)).is_None()
        self.not_called()
        expect(self.repo.label('name')).isinstance(github3.issues.label.Label)
        self.mock_assertions()
Ejemplo n.º 57
0
    def test_iter_code_frequency(self):
        self.response('code_frequency', _iter=True)
        self.get(self.api + 'stats/code_frequency')

        s = next(self.repo.iter_code_frequency())
        expect(s).isinstance(list)

        self.mock_assertions()