GeezerVison is showing github.com — Gist public handler completed · GunioRobot/python-github3@fbd0469
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: github3/handlers/gists.py +37-5Lines changed: 37 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/usr/bin/env python | 2 | 2 | # -*- encoding: utf-8 -*- | 3 | 3 |
| 4 | | -from .base import Handler | 5 | | -from .. import models | | 4 | +from .base import Handler, MimeTypeMixin | | 5 | +from github3 import models | 6 | 6 |
| 7 | 7 |
| 8 | | -class Gist(Handler): | 9 | | - """ Gist handler """ | | 8 | +class Gist(Handler, MimeTypeMixin): | | 9 | + """ Gist handler with public access """ | 10 | 10 |
| 11 | 11 | prefix = 'gists' | 12 | 12 |
| 13 | 13 | def __repr__(self): | 14 | 14 | return '<Gist handler>' | 15 | 15 |
| | 16 | + def all_gists(self, limit=None): | | 17 | + """ Return all public gists | | 18 | +
| | 19 | + NOTE: It returns all gists in github environment. Maybe you | | 20 | + want to use `limit` parameter | | 21 | + """ | | 22 | + | | 23 | + return self._get_resources('', model=models.Gist, limit=limit) | | 24 | + | 16 | 25 | def get(self, gist_id): | 17 | | - """ Return gist """ | | 26 | + """ Return gist | | 27 | +
| | 28 | + param `gist_id`: Gist id | | 29 | + """ | 18 | 30 |
| 19 | 31 | return self._get_resource(gist_id, model=models.Gist) | 20 | 32 |
| | 33 | + def get_comments(self, gist_id, limit=None): | | 34 | + """ Return gist's comments | | 35 | +
| | 36 | + param `gist_id`: Gist id | | 37 | + param `limit`: Number of comments | | 38 | + """ | | 39 | + | | 40 | + return self._get_resources('%s/comments' % gist_id, | | 41 | + model=models.GistComment, limit=limit, | | 42 | + headers=self.mime_header()) | | 43 | + | | 44 | + def get_comment(self, comment_id): | | 45 | + """ Return gist's comment | | 46 | +
| | 47 | + param `comment_id`: Comment id | | 48 | + """ | | 49 | + | | 50 | + return self._get_resource('comments/%s' % comment_id, | | 51 | + model=models.GistComment, headers=self.mime_header()) | | 52 | + | 21 | 53 |
| 22 | 54 | class AuthGist(Gist): | 23 | 55 |
| |
Collapse file Copy file name to clipboardExpand all lines: github3/tests/get_handlers_test.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,4 +26,6 @@ def test_get_gists(self): | 26 | 26 | auth_gists = self.auth_gh.gists | 27 | 27 |
| 28 | 28 | self.assertIsInstance(anom_gists, handlers.gists.Gist) | | 29 | + self.assertEquals(anom_gists.prefix, 'gists') | 29 | 30 | self.assertIsInstance(auth_gists, handlers.gists.AuthGist) | | 31 | + self.assertEquals(anom_gists.prefix, 'gists') |
Collapse file Copy file name to clipboard +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#!/usr/bin/env python | | 2 | +# -*- encoding: utf-8 -*- | | 3 | + | | 4 | +from unittest import TestCase | | 5 | +from mock import Mock, patch | | 6 | +from github3 import api | | 7 | +from github3.models import Gist, GistComment | | 8 | +from github3.handlers.base import Handler | | 9 | + | | 10 | + | | 11 | +class TestGistHandler(TestCase): | | 12 | + | | 13 | + def setUp(self): | | 14 | + self.gh = api.Github() | | 15 | + self.handler = self.gh.gists | | 16 | + | | 17 | + @patch.object(Handler, '_get_resources') | | 18 | + def test_get_gists(self, get): | | 19 | + gists = self.handler.all_gists() | | 20 | + get.assert_called_with('', model=Gist, limit=None) | | 21 | + | | 22 | + @patch.object(Handler, '_get_resource') | | 23 | + def test_get(self, get): | | 24 | + gist = self.handler.get(1) | | 25 | + get.assert_called_with(1, model=Gist) | | 26 | + | | 27 | + @patch.object(Handler, '_get_resources') | | 28 | + def test_get_comments(self, get): | | 29 | + comments = self.handler.get_comments(1) | | 30 | + get.assert_called_with('1/comments', model=GistComment, limit=None, | | 31 | + headers=None) | | 32 | + | | 33 | + @patch.object(Handler, '_get_resource') | | 34 | + def test_get_comment(self, get): | | 35 | + comment = self.handler.get_comment(1) | | 36 | + get.assert_called_with('comments/1', model=GistComment, headers=None) | | 37 | + | | 38 | +class TestAuthGistHandler(TestCase): | | 39 | + | | 40 | + def setUp(self): | | 41 | + self.gh = api.Github('test', 'pass') | | 42 | + self.handler = self.gh.gists | | 43 | + | | 44 | + def test_inherit(self): | | 45 | + self.assertTrue(hasattr(self.handler, 'get')) | | 46 | + self.assertTrue(hasattr(self.handler, 'get_comments')) | | 47 | + self.assertTrue(hasattr(self.handler, 'get_comment')) | | 48 | + |
|