Beispiel #1
0
    def test_archive(self):
        headers = {'content-disposition': 'filename=foo'}
        self.request.return_value = generate_response('archive', 200,
                                                      **headers)
        self.args = ('GET', self.api + 'tarball/master')
        self.conf.update({'stream': True})

        expect(self.repo.archive(None)).is_False()

        expect(os.path.isfile('foo')).is_False()
        expect(self.repo.archive('tarball')).is_True()
        expect(os.path.isfile('foo')).is_True()
        os.unlink('foo')
        self.mock_assertions()

        self.request.return_value.raw.seek(0)
        self.request.return_value._content_consumed = False

        expect(os.path.isfile('path_to_file')).is_False()
        expect(self.repo.archive('tarball', 'path_to_file')).is_True()
        expect(os.path.isfile('path_to_file')).is_True()
        os.unlink('path_to_file')

        self.request.return_value.raw.seek(0)
        self.request.return_value._content_consumed = False

        self.args = ('GET', self.api + 'zipball/randomref')
        expect(self.repo.archive('zipball', ref='randomref')).is_True()
        os.unlink('foo')
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
0
    def test_create_issue(self):
        self.request.return_value = generate_response('issue', 201)
        title = 'Construct _api attribute on our own'
        self.args = ('POST', self.api + 'issues')
        self.conf = {'data': {'title': title}}

        with expect.githuberror():
            self.repo.create_issue(title)

        self.login()
        expect(self.repo.create_issue(None)).is_None()
        expect(self.repo.create_issue(title)).isinstance(github3.issues.Issue)
        self.mock_assertions()

        body = 'Fake body'
        #self.conf['data'].update(body=body)
        expect(self.repo.create_issue(title, body)
               ).isinstance(github3.issues.Issue)
        self.mock_assertions()

        assignee, mile, labels = 'sigmavirus24', 1, ['bug', 'enhancement']
        #self.conf['data'].update({'assignee': assignee, 'milestone': mile,
        #                          'labels': labels})
        expect(self.repo.create_issue(title, body, assignee, mile, labels)
               ).isinstance(github3.issues.Issue)
        self.mock_assertions()
Beispiel #5
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()
Beispiel #6
0
    def test_iter_events(self):
        self.request.return_value = generate_response('event', _iter=True)
        self.args = ('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()
Beispiel #7
0
    def test_commit_comment(self):
        self.request.return_value = generate_response('commit_comment')
        comment_id = 1380832
        self.args = ('GET', self.api + 'comments/{0}'.format(comment_id))

        expect(self.repo.commit_comment(comment_id)
               ).isinstance(github3.repos.RepoComment)
        self.mock_assertions()
Beispiel #8
0
    def test_iter_all_users(self):
        self.request.return_value = generate_response('user', _iter=True)
        self.args = ('GET', 'https://api.github.com/users')
        self.conf.update(params=None)

        repo = next(self.g.iter_all_users())
        expect(repo).isinstance(github3.users.User)
        self.mock_assertions()
Beispiel #9
0
    def test_gitignore_template(self):
        self.request.return_value = generate_response('template')
        self.args = ('GET',
                     'https://api.github.com/gitignore/templates/Python')

        template = self.g.gitignore_template('Python')
        expect(template.startswith('*.py[cod]')).is_True()
        self.mock_assertions()
Beispiel #10
0
 def test_search_users(self):
     self.request.return_value = generate_response('legacy_user')
     self.args = ('get',
                  'https://api.github.com/{0}/{1}/{2}/{3}'.format(
                  'legacy', 'user', 'search', 'sigmavirus24')
                  )
     users = self.g.search_users('sigmavirus24')
     expect(users[0]).isinstance(github3.legacy.LegacyUser)
     self.mock_assertions()
Beispiel #11
0
 def test_search_email(self):
     self.request.return_value = generate_response('legacy_email')
     self.args = ('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()
Beispiel #12
0
    def test_delete_key(self):
        self.request.return_value = generate_response(None, 204)

        self.login()
        with patch.object(github3.github.GitHub, 'key') as key:
            key.return_value = github3.users.Key(load('key'), self.g)
            assert self.g.delete_key(10) is True

        assert self.request.called is True
Beispiel #13
0
    def test_compare_commits(self):
        self.request.return_value = generate_response('comparison')
        base = 'a811e1a270f65eecb65755eca38d888cbefcb0a7'
        head = '76dcc6cb4b9860034be81b7e58adc286a115aa97'
        self.args = ('GET', self.api + 'compare/{0}...{1}'.format(base, head))

        expect(self.repo.compare_commits(base, head)
               ).isinstance(github3.repos.Comparison)
        self.mock_assertions()
Beispiel #14
0
    def test_authorize(self):
        self.request.return_value = generate_response('authorization', 201)
        scopes = ['scope1', 'scope2']

        self.g.authorize(None, None, scopes)
        assert self.request.called is False

        a = self.g.authorize('user', 'password', scopes)
        expect(a).isinstance(github3.auths.Authorization)
        assert self.request.called is True
Beispiel #15
0
    def test_repository(self):
        self.request.return_value = generate_response('repo')
        repo = self.g.repository(None, None)
        expect(repo).is_None()
        expect(self.request.called).is_False()

        self.args = ('GET',
                     'https://api.github.com/repos/sigmavirus24/github3.py')
        repo = self.g.repository('sigmavirus24', 'github3.py')
        expect(repo).isinstance(github3.repos.Repository)
        self.mock_assertions()
Beispiel #16
0
    def test_user(self):
        self.request.return_value = generate_response('user')
        self.args = ('GET', 'https://api.github.com/users/sigmavirus24')

        expect(self.g.user('sigmavirus24')).isinstance(github3.users.User)
        self.mock_assertions()

        self.args = ('GET', 'https://api.github.com/user')
        self.login()
        expect(self.g.user()).isinstance(github3.users.User)
        self.mock_assertions()
Beispiel #17
0
    def test_utf8_user(self):
        self.request.return_value = generate_response('utf8_user')
        self.args = ('GET', 'https://api.github.com/users/alejandrogomez')

        u = self.g.user('alejandrogomez')

        try:
            repr(u)
        except UnicodeEncodeError:
            self.fail('Regression caught. See PR #52. Names must be utf-8'
                      ' encoded')
Beispiel #18
0
    def test_iter_keys(self):
        self.request.return_value = generate_response('key', _iter=True)
        self.args = ('GET', 'https://api.github.com/user/keys')
        self.conf.update(params=None)

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

        self.login()
        expect(next(self.g.iter_keys())).isinstance(github3.users.Key)
        self.mock_assertions()
Beispiel #19
0
    def test_authorization(self):
        self.request.return_value = generate_response('authorization')
        self.args = ('GET', 'https://api.github.com/authorizations/10')
        with expect.githuberror():
            self.g.authorization(10)
        assert self.request.called is False

        self.login()
        a = self.g.authorization(10)
        expect(a).isinstance(github3.auths.Authorization)
        self.mock_assertions()
Beispiel #20
0
    def test_iter_orgs(self):
        self.request.return_value = generate_response('org', _iter=True)
        self.args = ('GET', 'https://api.github.com/users/login/orgs')

        expect(next(self.g.iter_orgs('login'))).isinstance(
            github3.orgs.Organization)
        self.mock_assertions()

        self.args = ('GET', 'https://api.github.com/user/orgs')
        self.login()
        expect(next(self.g.iter_orgs())).isinstance(github3.orgs.Organization)
        self.mock_assertions()
Beispiel #21
0
    def test_create_key(self):
        self.request.return_value = generate_response('key', 201)

        with expect.githuberror():
            k = self.g.create_key(None, None)
            assert k is None
        assert self.request.called is False

        self.login()
        k = self.g.create_key('Name', 'Key')
        expect(k).isinstance(github3.users.Key)
        assert self.request.called is True
Beispiel #22
0
    def test_add_collaborator(self):
        self.request.return_value = generate_response('', 204)
        self.args = ('put', self.api + 'collaborators/sigmavirus24')
        self.conf = {'headers': {'Content-Length': '0'}, 'data': None}

        with expect.githuberror():
            self.repo.add_collaborator('foo')

        self.login()
        expect(self.repo.add_collaborator(None)).is_False()
        expect(self.repo.add_collaborator('sigmavirus24')).is_True()
        self.mock_assertions()
Beispiel #23
0
    def test_search_issues(self):
        self.request.return_value = generate_response('legacy_issue')
        self.args = ('get',
                     'https://api.github.com/legacy/{0}/{1}/{2}/'
                     '{3}/{4}/{5}'.format(
                     'issues', 'search', 'sigmavirus24', 'github3.py',
                     'closed', 'requests'))
        issues = self.g.search_issues('sigmavirus24', 'github3.py', 'closed',
                'requests')  # nopep8

        expect(issues[0]).isinstance(github3.legacy.LegacyIssue)
        self.mock_assertions()
Beispiel #24
0
    def test_iter_emails(self):
        self.request.return_value = generate_response('emails', _iter=True)
        self.args = ('GET', 'https://api.github.com/user/emails')
        self.conf.update(params=None)

        with expect.githuberror():
            self.g.iter_emails()
        assert self.request.called is False

        self.login()
        email = next(self.g.iter_emails())
        expect(email['email']) == '*****@*****.**'
        self.mock_assertions()
Beispiel #25
0
    def test_is_starred(self):
        self.request.return_value = generate_response(None, 204)
        self.args = ('GET', 'https://api.github.com/user/starred/user/repo')

        with expect.githuberror():
            self.g.is_starred('user', 'repo')

        self.login()
        expect(self.g.is_starred(None, None)).is_False()
        assert self.request.called is False

        expect(self.g.is_starred('user', 'repo')).is_True()
        self.mock_assertions()
Beispiel #26
0
    def test_iter_repo_issues(self):
        self.request.return_value = generate_response('issue', _iter=True)
        self.args = ('GET',
                     'https://api.github.com/repos/sigmavirus24/github3.py/'
                     'issues')

        with patch.object(github3.GitHub, 'repository') as repo:
            repo.return_value = github3.repos.Repository(load('repo'),
                                                         self.g)
            i = next(self.g.iter_repo_issues('sigmavirus24', 'github3.py'))

        expect(i).isinstance(github3.issues.Issue)
        self.mock_assertions()
Beispiel #27
0
    def test_iter_repos(self):
        self.request.return_value = generate_response('repo', _iter=True)
        self.args = ('GET', 'https://api.github.com/user/repos')
        self.conf.update(params={})

        self.login()
        expect(next(self.g.iter_repos())).isinstance(github3.repos.Repository)
        self.mock_assertions()

        self.args = ('GET', 'https://api.github.com/users/sigmavirus24/repos')
        expect(next(self.g.iter_repos('sigmavirus24'))).isinstance(
            github3.repos.Repository)
        self.mock_assertions()
Beispiel #28
0
    def test_create_status(self):
        self.request.return_value = generate_response('status', 201)
        self.args = ('POST', self.api + 'statuses/fakesha')
        self.conf = {'data': {'state': 'success'}}

        with expect.githuberror():
            self.repo.create_status('fakesha', 'success')

        self.login()
        expect(self.repo.create_status(None, None)).is_None()
        expect(self.repo.create_status('fakesha', 'success')).isinstance(
            github3.repos.Status)
        self.mock_assertions()
Beispiel #29
0
    def test_create_ref(self):
        self.request.return_value = generate_response('ref', 201)
        self.args = ('POST', self.api + 'git/refs')
        self.conf = {'data': {'ref': 'refs/heads/master', 'sha': 'fakesha'}}

        with expect.githuberror():
            self.repo.create_ref('foo', 'bar')

        self.login()
        expect(self.repo.create_ref('foo/bar', None)).is_None()
        expect(self.repo.create_ref(**self.conf['data'])).isinstance(
            github3.git.Reference)
        self.mock_assertions()
Beispiel #30
0
    def test_follow(self):
        self.request.return_value = generate_response(None, 204)
        self.args = ('PUT',
                     'https://api.github.com/user/following/sigmavirus24')
        self.conf = {'data': None}

        with expect.githuberror():
            self.g.follow('sigmavirus24')

        self.login()
        assert self.g.follow(None) is False
        assert self.g.follow('sigmavirus24') is True
        self.mock_assertions()