diff options
author | 2012-02-22 01:16:10 +0100 | |
---|---|---|
committer | 2012-02-22 01:16:32 +0100 | |
commit | 36381d426f5da0552d2db0b60c757ef5e3a67c2d (patch) | |
tree | e5dc0081cbb3cc67655f45ee217ebf7165dc0fa2 /pygithub3 | |
parent | Repos.downloads service done (diff) | |
download | python-github3-36381d426f5da0552d2db0b60c757ef5e3a67c2d.tar.xz python-github3-36381d426f5da0552d2db0b60c757ef5e3a67c2d.zip |
Repos.forks service done
Diffstat (limited to 'pygithub3')
-rw-r--r-- | pygithub3/requests/repos/forks.py | 18 | ||||
-rw-r--r-- | pygithub3/resources/repos.py | 3 | ||||
-rw-r--r-- | pygithub3/services/repos.py | 13 | ||||
-rw-r--r-- | pygithub3/tests/services/test_repos.py | 22 |
4 files changed, 55 insertions, 1 deletions
diff --git a/pygithub3/requests/repos/forks.py b/pygithub3/requests/repos/forks.py new file mode 100644 index 0000000..b27dde3 --- /dev/null +++ b/pygithub3/requests/repos/forks.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from . import Request + +from pygithub3.resources.repos import Repo + + +class List(Request): + + uri = 'repos/{user}/{repo}/forks' + resource = Repo + + +class Create(Request): + + uri = '/repos/{user}/{repo}/forks' + resource = Repo diff --git a/pygithub3/resources/repos.py b/pygithub3/resources/repos.py index 865f039..89e5682 100644 --- a/pygithub3/resources/repos.py +++ b/pygithub3/resources/repos.py @@ -106,6 +106,9 @@ class Branch(Resource): class Download(Resource): + def __str__(self): + return '<Download (%s)>' % getattr(self, 'name', '') + def ball_to_upload(self): return OrderedDict({ 'key': self.path, 'acl': self.acl, 'success_action_status': '201', diff --git a/pygithub3/services/repos.py b/pygithub3/services/repos.py index d88338f..dfb9e48 100644 --- a/pygithub3/services/repos.py +++ b/pygithub3/services/repos.py @@ -6,6 +6,18 @@ import requests from .base import Service, MimeTypeMixin +class Forks(Service): + + def list(self, user=None, repo=None, sort='newest'): + request = self.make_request('repos.forks.list', user=user, repo=repo) + return self._get_result(request, sort=sort) + + def create(self, user=None, repo=None, org=None): + request = self.make_request('repos.forks.create', user=user, repo=repo) + org = {'org': org} if org else {} + return self._post(request, **org) + + class Downloads(Service): def list(self, user=None, repo=None): @@ -111,6 +123,7 @@ class Repo(Service): self.collaborators = Collaborator(**config) self.commits = Commits(**config) self.downloads = Downloads(**config) + self.forks = Forks(**config) super(Repo, self).__init__(**config) def list(self, user=None, type='all'): diff --git a/pygithub3/tests/services/test_repos.py b/pygithub3/tests/services/test_repos.py index 615f883..f8392b5 100644 --- a/pygithub3/tests/services/test_repos.py +++ b/pygithub3/tests/services/test_repos.py @@ -6,7 +6,8 @@ from unittest import TestCase import requests from mock import patch, Mock -from pygithub3.services.repos import Repo, Collaborator, Commits, Downloads +from pygithub3.services.repos import (Repo, Collaborator, Commits, Downloads, + Forks) from pygithub3.resources.base import json from pygithub3.tests.utils.base import (mock_response, mock_response_result, mock_json) @@ -268,3 +269,22 @@ class TestDownloadsService(TestCase): self.assertEqual(request_method.call_args[0], ('post', _('repos/oct/re_oct/downloads'))) self.assertTrue(hasattr(download, 'upload')) + + +@patch.object(requests.sessions.Session, 'request') +class TestForksService(TestCase): + + def setUp(self): + self.fs = Forks(user='oct', repo='re_oct') + + def test_LIST(self, request_method): + request_method.return_value = mock_response_result() + self.fs.list().all() + self.assertEqual(request_method.call_args[0], + ('get', _('repos/oct/re_oct/forks'))) + + def test_CREATE(self, request_method): + request_method.return_value = mock_response('post') + self.fs.create() + self.assertEqual(request_method.call_args[0], + ('post', _('repos/oct/re_oct/forks'))) |