aboutsummaryrefslogtreecommitdiffstats
path: root/github3
diff options
context:
space:
mode:
Diffstat (limited to 'github3')
-rw-r--r--github3/handlers/gists.py42
-rw-r--r--github3/tests/get_handlers_test.py2
-rw-r--r--github3/tests/gists_handler_test.py48
3 files changed, 87 insertions, 5 deletions
diff --git a/github3/handlers/gists.py b/github3/handlers/gists.py
index 38418ca..37b1c3d 100644
--- a/github3/handlers/gists.py
+++ b/github3/handlers/gists.py
@@ -1,23 +1,55 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
-from .base import Handler
-from .. import models
+from .base import Handler, MimeTypeMixin
+from github3 import models
-class Gist(Handler):
- """ Gist handler """
+class Gist(Handler, MimeTypeMixin):
+ """ Gist handler with public access """
prefix = 'gists'
def __repr__(self):
return '<Gist handler>'
+ def all_gists(self, limit=None):
+ """ Return all public gists
+
+ NOTE: It returns all gists in github environment. Maybe you
+ want to use `limit` parameter
+ """
+
+ return self._get_resources('', model=models.Gist, limit=limit)
+
def get(self, gist_id):
- """ Return gist """
+ """ Return gist
+
+ param `gist_id`: Gist id
+ """
return self._get_resource(gist_id, model=models.Gist)
+ def get_comments(self, gist_id, limit=None):
+ """ Return gist's comments
+
+ param `gist_id`: Gist id
+ param `limit`: Number of comments
+ """
+
+ return self._get_resources('%s/comments' % gist_id,
+ model=models.GistComment, limit=limit,
+ headers=self.mime_header())
+
+ def get_comment(self, comment_id):
+ """ Return gist's comment
+
+ param `comment_id`: Comment id
+ """
+
+ return self._get_resource('comments/%s' % comment_id,
+ model=models.GistComment, headers=self.mime_header())
+
class AuthGist(Gist):
diff --git a/github3/tests/get_handlers_test.py b/github3/tests/get_handlers_test.py
index f07a7cf..0d88670 100644
--- a/github3/tests/get_handlers_test.py
+++ b/github3/tests/get_handlers_test.py
@@ -26,4 +26,6 @@ class TestGetHandlers(TestCase):
auth_gists = self.auth_gh.gists
self.assertIsInstance(anom_gists, handlers.gists.Gist)
+ self.assertEquals(anom_gists.prefix, 'gists')
self.assertIsInstance(auth_gists, handlers.gists.AuthGist)
+ self.assertEquals(anom_gists.prefix, 'gists')
diff --git a/github3/tests/gists_handler_test.py b/github3/tests/gists_handler_test.py
new file mode 100644
index 0000000..df67659
--- /dev/null
+++ b/github3/tests/gists_handler_test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from unittest import TestCase
+from mock import Mock, patch
+from github3 import api
+from github3.models import Gist, GistComment
+from github3.handlers.base import Handler
+
+
+class TestGistHandler(TestCase):
+
+ def setUp(self):
+ self.gh = api.Github()
+ self.handler = self.gh.gists
+
+ @patch.object(Handler, '_get_resources')
+ def test_get_gists(self, get):
+ gists = self.handler.all_gists()
+ get.assert_called_with('', model=Gist, limit=None)
+
+ @patch.object(Handler, '_get_resource')
+ def test_get(self, get):
+ gist = self.handler.get(1)
+ get.assert_called_with(1, model=Gist)
+
+ @patch.object(Handler, '_get_resources')
+ def test_get_comments(self, get):
+ comments = self.handler.get_comments(1)
+ get.assert_called_with('1/comments', model=GistComment, limit=None,
+ headers=None)
+
+ @patch.object(Handler, '_get_resource')
+ def test_get_comment(self, get):
+ comment = self.handler.get_comment(1)
+ get.assert_called_with('comments/1', model=GistComment, headers=None)
+
+class TestAuthGistHandler(TestCase):
+
+ def setUp(self):
+ self.gh = api.Github('test', 'pass')
+ self.handler = self.gh.gists
+
+ def test_inherit(self):
+ self.assertTrue(hasattr(self.handler, 'get'))
+ self.assertTrue(hasattr(self.handler, 'get_comments'))
+ self.assertTrue(hasattr(self.handler, 'get_comment'))
+