Skip to content

Commit 82776a8

Browse files
committed
"services.gists.Gist" tests and resources
1 parent 11e9410 commit 82776a8

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

pygithub3/resources/gists.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from .base import Resource
5+
from .users import User
6+
7+
8+
class File(Resource):
9+
10+
def __str__(self):
11+
return '<GistFile (%s)>' % getattr(self, 'filename', '')
12+
13+
14+
class Fork(Resource):
15+
16+
_dates = ('created_at', )
17+
_maps = {'user': User}
18+
def __str__(self):
19+
return '<GistFork>'
20+
21+
22+
class History(Resource):
23+
24+
_dates = ('committed_at', )
25+
_maps = {'user': User}
26+
27+
def __str__(self):
28+
return '<GistHistory (%s)>' % getattr(self, 'version', '')
29+
30+
class Gist(Resource):
31+
32+
_dates = ('created_at', )
33+
_maps = {'user': User}
34+
_collection_maps = {'files': File, 'forks': Fork, 'history': History}
35+
36+
def __str__(self):
37+
return '<Gist (%s)>' % getattr(self, 'description', '')
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
import requests
5+
from mock import patch, Mock
6+
7+
from pygithub3.tests.utils.core import TestCase
8+
from pygithub3.resources.base import json
9+
from pygithub3.services.gists import Gist
10+
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
11+
mock_json)
12+
from pygithub3.tests.utils.services import _
13+
14+
json.dumps = Mock(side_effect=mock_json)
15+
json.loads = Mock(side_effect=mock_json)
16+
17+
18+
@patch.object(requests.sessions.Session, 'request')
19+
class TestGistService(TestCase):
20+
21+
def setUp(self):
22+
self.gs = Gist()
23+
24+
def test_LIST_without_user(self, request_method):
25+
request_method.return_value = mock_response_result()
26+
self.gs.list().all()
27+
self.assertEqual(request_method.call_args[0], ('get', _('gists')))
28+
29+
def test_LIST_with_user(self, request_method):
30+
request_method.return_value = mock_response_result()
31+
self.gs.list('octocat').all()
32+
self.assertEqual(request_method.call_args[0],
33+
('get', _('users/octocat/gists')))
34+
35+
def test_LIST_public(self, request_method):
36+
request_method.return_value = mock_response_result()
37+
self.gs.list_public().all()
38+
self.assertEqual(request_method.call_args[0],
39+
('get', _('gists/public')))
40+
41+
def test_LIST_starred(self, request_method):
42+
request_method.return_value = mock_response_result()
43+
self.gs.list_starred.all()
44+
self.assertEqual(request_method.call_args[0],
45+
('get', _('gists/starred')))
46+
47+
def test_GET(self, request_method):
48+
request_method.return_value = mock_response()
49+
self.gs.get(1)
50+
self.assertEqual(request_method.call_args[0],
51+
('get', _('gists/1')))
52+
53+
def test_CREATE(self, request_method):
54+
request_method.return_value = mock_response('post')
55+
self.gs.create(dict(public=True, files={
56+
'file1.txt': {'content': 'Some\ncontent'}}))
57+
self.assertEqual(request_method.call_args[0],
58+
('post', _('gists')))
59+
60+
def test_UPDATE(self, request_method):
61+
request_method.return_value = mock_response('patch')
62+
self.gs.update(1, {'description': 'edited'})
63+
self.assertEqual(request_method.call_args[0],
64+
('patch', _('gists/1')))
65+
66+
def test_STAR(self, request_method):
67+
self.gs.star(1)
68+
self.assertEqual(request_method.call_args[0],
69+
('put', _('gists/1/star')))
70+
71+
def test_UNSTAR(self, request_method):
72+
request_method.return_value = mock_response('delete')
73+
self.gs.unstar(1)
74+
self.assertEqual(request_method.call_args[0],
75+
('delete', _('gists/1/star')))
76+
77+
def test_IS_STARRED(self, request_method):
78+
request_method.return_value = mock_response()
79+
self.gs.is_starred(1)
80+
self.assertEqual(request_method.call_args[0],
81+
('get', _('gists/1/star')))
82+
83+
def test_FORK(self, request_method):
84+
request_method.return_value = mock_response('post')
85+
self.gs.fork(1)
86+
self.assertEqual(request_method.call_args[0],
87+
('post', _('gists/1/fork')))
88+
89+
def test_DELETE(self, request_method):
90+
request_method.return_value = mock_response('delete')
91+
self.gs.delete(1)
92+
self.assertEqual(request_method.call_args[0],
93+
('delete', _('gists/1')))

0 commit comments

Comments
 (0)