Example #1
0
    def test_oauth(self):
        # Test "oauth" auth
        self.g.login(token=self.fake_oauth)
        h = github3.login('', '', token=self.fake_oauth)
        for i in [self.g, h]:
            expect(i._session.headers['Authorization']) == 'token ' +\
                self.fake_oauth

        with expect.raises(github3.GitHubError):
            self.g.user()

        if self.auth:
            expect(self._g.user()).is_not_None()
Example #2
0
    def test_watching(self):
        expect(self.g.list_watching(self.sigm)) != []
        with expect.raises(github3.GitHubError):
            self.g.watch(self.sigm, self.todo)
            self.g.unwatch(self.sigm, self.todo)
            self.g.list_watching()
            self.g.is_watching(self.sigm, self.todo)

        if self.auth:
            expect(self._g.watch(self.sigm, self.todo)).isinstance(bool)
            expect(self._g.unwatch(self.sigm, self.todo)).isinstance(bool)
            expect(self._g.list_watching()) != []
            expect(self._g.is_watching(self.sigm, self.todo)) != []
Example #3
0
 def test_with_auth(self):
     if self.auth:
         repo = self._g.repository(self.sigm, self.todo)
         # Try somethings only I can test
         try:
             expect(repo.hook(74859)).isinstance(Hook)
             expect(repo.key(3069618)).isinstance(Key)
             expect(repo.pubsubhubbub(
                 'subscribe',
                 'https://github.com/sigmavirus24/github3.py/events',
                 'https://httpbin.org/post'
                 )).is_False()
             expect(repo.add_collaborator('jcordasc')).is_True()
             expect(repo.remove_collaborator('jcordasc')).is_True()
         except github3.GitHubError:
             pass
Example #4
0
def scp(from_path, to_path, is_local=True, is_receive=False, use_env_host=True):
    if is_receive:
        target = CONF._remote_tmp_dir + from_path
        target_dir = target.rsplit('/', 1)[0]
        run('mkdir -p {0}'.format(target_dir))
        cmd = 'scp -P {0} -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" {1}@{2}:{3} {4}'.format(
            api.env.port, api.env.user, api.env.host, target, to_path)

        if CONF.user and CONF.password:
            result = expect(
                cmd,
                [['* password:'******'{0}\\n'.format(CONF.password)]],
                is_local=is_local)

        else:
            result = local(cmd)

        return result

    else:
        cmd = 'scp -P {0} -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" {1} {2}@'.format(
            api.env.port, from_path, api.env.user)
        if use_env_host:
            cmd += '{0}:'.format(api.env.host)

        if is_local:
            tmp_target = CONF._remote_tmp_dir + to_path
            tmp_target_dir = tmp_target.rsplit('/', 1)[0]

            run('mkdir -p {0}'.format(tmp_target_dir))
            cmd += tmp_target

            if CONF.user and CONF.password:
                result = expect(
                    cmd,
                    [['* password:'******'{0}\\n'.format(CONF.password)]],
                    is_local=is_local)

            else:
                result = local(cmd)

            sudo('cp {0} {1}'.format(tmp_target, to_path))
            return result

        else:
            cmd += to_path
            return run(cmd)
Example #5
0
 def test_authenticated(self):
     if not self.auth:
         return
     user = self._g.user()
     expect(user.add_email_addresses(['*****@*****.**'])).is_True()
     expect(user.delete_email_addresses(['*****@*****.**'])).is_True()
     try:
         ev = user.list_org_events(self.gh3py)
         self.expect_list_of_class(ev, Event)
     except github3.GitHubError:
         pass
     expect(user.update()).isinstance(bool)
Example #6
0
def scp(from_path,
        to_path,
        is_local=True,
        is_receive=False,
        use_env_host=True):
    if is_receive:
        cmd = 'scp -P {0} -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" {1}@{2}:{3} {4}'.format(
            api.env.port, api.env.user, api.env.host, from_path, to_path)

        if CONF.user and CONF.password:
            result = expect(cmd,
                            [['* password:'******'{0}\\n'.format(CONF.password)]],
                            is_local=is_local)

        else:
            result = local(cmd)

        return result

    else:
        cmd = 'scp -P {0} -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null" {1} {2}@'.format(
            api.env.port, from_path, api.env.user)
        if use_env_host:
            cmd += '{0}:'.format(api.env.host)

        if is_local:
            tmp_target = CONF._remote_tmp_dir + to_path
            tmp_target_dir = tmp_target.rsplit('/', 1)[0]

            run('mkdir -p {0}'.format(tmp_target_dir))
            cmd += tmp_target
            result = api.put(from_path, tmp_target)

            sudo('cp {0} {1}'.format(tmp_target, to_path))
            return result

        else:
            cmd += to_path
            return run(cmd)
Example #7
0
 def test_is_assignee_on(self):
     expect(self.user.is_assignee_on(self.sigm, self.todo)).is_True()
     expect(self.user.is_assignee_on(self.kr, 'requests')).is_False()
Example #8
0
    def test_gists(self):
        # My gcd example
        gist_id = 2648112
        g = self.g.gist(gist_id)
        if not g:
            self.fail('Check gcd gist')
        expect(g).isinstance(github3.gists.Gist)

        with expect.raises(github3.GitHubError):
            self.g.gist(-1)

        for i in None, self.sigm:
            expect(self.g.list_gists(i)) != []

        if self.auth:
            desc = 'Testing gist creation'
            files = {'test.txt': {'content': 'Test contents'}}
            gist = self._g.create_gist(desc, files, False)
            expect(gist).is_not_None()
            expect(gist.description) == desc
            expect(gist.is_public()).is_False()
            for g in gist.list_files():
                expect(g.content) == files[g.name]['content']
            expect(gist.delete()).is_True()
Example #9
0
    def test_with_auth(self):
        if not self.auth:
            return
        # Try and do something only sigmavirus24 or other org members
        # should be able to do. As of now (26 Aug 2012) there are no other
        # org members.
        # Might as well avoid a call to the API, right?
        org = Organization(self.org.to_json(), self._g)
        try:
            expect(org.add_member('jcordasc', 'Collaborators')).is_True()
            expect(org.remove_member('jcordasc', 'Collaborators')).is_True()
        except github3.GitHubError:
            pass

        try:
            expect(org.add_repo(self.test_repo, 'Contributors')).is_True()
            expect(org.remove_repo(self.test_repo, 'Contributors')).is_True()
        except github3.GitHubError:
            pass

        try:
            repo = org.create_repo('test_repo_creation', 'testing')
            expect(repo).isinstance(Repository)
            repo.delete()
        except github3.GitHubError:
            pass

        try:
            expect(org.conceal_member(self.sigm)).is_True()
            expect(org.publicize_member(self.sigm)).is_True()
        except github3.GitHubError:
            pass

        try:
            team = org.create_team('New Team', permissions='admin')
            expect(team).isinstance(Team)
            team.delete()
        except github3.GitHubError:
            pass

        try:
            expect(org.edit(name='github3[dot]py')).is_True()
            expect(org.edit(name='github3.py')).is_True()
        except github3.GitHubError:
            pass

        try:
            teams = org.list_teams()
            self.expect_list_of_class(teams, Team)
        except github3.GitHubError:
            pass

        try:
            expect(org.team(190083)).isinstance(Team)
        except github3.GitHubError:
            pass
Example #10
0
 def test_public_gists(self):
     expect(self.user.public_gists) >= 0
Example #11
0
 def test_is_member(self):
     expect(self.org.is_member(self.sigm)).is_False()
Example #12
0
 def test_private_repos(self):
     expect(self.org.private_repos) >= 0
Example #13
0
 def test_title(self):
     expect(self.key.title).isinstance(base.str_test)
Example #14
0
    def test_issues(self):
        title = 'Test issue for github3.py'
        with expect.raises(github3.GitHubError):
            # Try to create one without authenticating
            self.g.create_issue(self.sigm, self.todo, title)
            # Try to get individual ones
            self.g.issue(self.sigm, self.todo, 2000)
            self.g.list_user_issues()

        i = self.g.issue(self.sigm, self.todo, 1)
        self.assertIsNotNone(i)
        expect(i).isinstance(github3.issues.Issue)
        expect(i.list_comments()) != []
        # Test listing issues
        list_issues = self.g.list_repo_issues
        expect(list_issues(self.kr, 'requests')) != []
        expect(list_issues(self.sigm, self.todo)).isinstance(list)
        for f in ('assigned', 'created', 'mentioned'):
            self.assertIsNotNone(list_issues(self.sigm, self.todo, f))
        for s in ('open', 'closed'):
            self.assertIsNotNone(list_issues(self.sigm, self.todo, state=s))
        self.assertIsNotNone(list_issues(self.sigm, self.todo, state='closed',
            labels='Bug,Enhancement'))
        for s in ('created', 'updated', 'comments'):
            self.assertIsNotNone(list_issues(self.sigm, self.todo, sort=s))
        for d in ('asc', 'desc'):
            self.assertIsNotNone(list_issues(self.sigm, self.todo,
                state='closed', direction=d))
        expect(list_issues(self.sigm, self.todo,
            since='2011-01-01T00:00:01Z')).is_not_None()

        if self.auth:
            i = self._g.create_issue(self.gh3py, self.test_repo,
            'Testing github3.py', 'Ignore this.')
            expect(i).isinstance(github3.issue.Issue)
            expect(i.close()).is_True()
Example #15
0
 def test_pubkey(self):
     expect(self.key.key).isinstance(base.str_test)
Example #16
0
 def test_id(self):
     expect(self.key.id) > 0
Example #17
0
 def test_key(self):
     expect(self.key).isinstance(Key)
Example #18
0
 def test_private_gists(self):
     expect(self.user.private_gists) >= 0
Example #19
0
 def test_total_private_repos(self):
     expect(self.user.total_private_repos) >= 0
Example #20
0
    def test_following(self):
        expect(self.g.list_followers('kennethreitz')) != []
        expect(self.g.list_following('kennethreitz')) != []
        with expect.raises(github3.GitHubError):
            self.g.is_following(self.sigm)
            self.g.follow(self.sigm)
            self.g.unfollow(self.sigm)
            self.g.list_followers()
            self.g.list_following()

        if self.auth:
            expect(self._g.is_following(self.sigm)).isinstance(bool)
            expect(self._g.follow(self.sigm)).isinstance(bool)
            expect(self._g.unfollow(self.sigm)).isinstance(bool)
            expect(self._g.list_followers()) != []
            expect(self._g.list_following()) != []
Example #21
0
 def test_login(self):
     # Test "regular" auth
     self.g.login(*self.fake_auth)
     h = github3.login(*self.fake_auth)
     for i in [self.g, h]:
         expect(self.fake_auth) == i._session.auth
Example #22
0
 def test_for_hire(self):
     expect(self.user.for_hire).isinstance(bool)
Example #23
0
 def test_owned_private_repos(self):
     expect(self.user.owned_private_repos) >= 0
Example #24
0
 def test_organization(self):
     expect(self.org).isinstance(Organization)
Example #25
0
 def test_orgs(self):
     expect(self.g.list_orgs(self.kr)) != []
     expect(self.g.organization(self.gh3py)).is_not_None()
     with expect.raises(github3.GitHubError):
         self.g.list_orgs()
Example #26
0
 def test_is_public_member(self):
     expect(self.org.is_public_member(self.sigm)).is_True()
Example #27
0
 def test_search(self):
     expect(self.g.search_issues(self.sigm, self.todo, 'closed',
             'todo')).is_not_None()
     expect(self.g.search_users(self.sigm)).is_not_None()
     expect(self.g.search_email('*****@*****.**')).is_not_None()
Example #28
0
 def test_name(self):
     expect(self.org.name).isinstance(str_test)
     expect(self.org.name) == 'github3.py'
Example #29
0
 def test_users(self):
     with expect.raises(github3.GitHubError):
         self.g.update_user()
         self.g.user()
     expect(self.g.user(self.sigm)).is_not_None()
Example #30
0
 def test_repos(self):
     with expect.raises(github3.GitHubError):
         self.g.create_repo('test_github3.py')
         self.g.list_repos()
     expect(self.g.list_repos(self.sigm)) != []
     expect(self.g.repository(self.sigm, self.todo)).is_not_None()
Example #31
0
 def test_plan(self):
     if self.user.plan:
         expect(self.user.plan).isinstance(Plan)