aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/tests/services/test_gists.py
blob: 8cf93ed575a6094c8f962e40b41ae6e1a0a1c7e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import requests
from mock import patch, Mock

from pygithub3.tests.utils.core import TestCase
from pygithub3.resources.base import json
from pygithub3.services.gists import Gist, Comments
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
                                        mock_json)
from pygithub3.tests.utils.services import _

json.dumps = Mock(side_effect=mock_json)
json.loads = Mock(side_effect=mock_json)


@patch.object(requests.sessions.Session, 'request')
class TestGistService(TestCase):

    def setUp(self):
        self.gs = Gist()

    def test_LIST_without_user(self, request_method):
        request_method.return_value = mock_response_result()
        self.gs.list().all()
        self.assertEqual(request_method.call_args[0], ('get', _('gists')))

    def test_LIST_with_user(self, request_method):
        request_method.return_value = mock_response_result()
        self.gs.list('octocat').all()
        self.assertEqual(request_method.call_args[0],
            ('get', _('users/octocat/gists')))

    def test_LIST_public(self, request_method):
        request_method.return_value = mock_response_result()
        self.gs.public().all()
        self.assertEqual(request_method.call_args[0],
            ('get', _('gists/public')))

    def test_LIST_starred(self, request_method):
        request_method.return_value = mock_response_result()
        self.gs.starred().all()
        self.assertEqual(request_method.call_args[0],
            ('get', _('gists/starred')))

    def test_GET(self, request_method):
        request_method.return_value = mock_response()
        self.gs.get(1)
        self.assertEqual(request_method.call_args[0],
            ('get', _('gists/1')))

    def test_CREATE(self, request_method):
        request_method.return_value = mock_response('post')
        self.gs.create(dict(public=True, files={
            'file1.txt': {'content': 'Some\ncontent'}}))
        self.assertEqual(request_method.call_args[0],
            ('post', _('gists')))

    def test_UPDATE(self, request_method):
        request_method.return_value = mock_response('patch')
        self.gs.update(1, {'description': 'edited'})
        self.assertEqual(request_method.call_args[0],
            ('patch', _('gists/1')))

    def test_STAR(self, request_method):
        self.gs.star(1)
        self.assertEqual(request_method.call_args[0],
            ('put', _('gists/1/star')))

    def test_UNSTAR(self, request_method):
        request_method.return_value = mock_response('delete')
        self.gs.unstar(1)
        self.assertEqual(request_method.call_args[0],
            ('delete', _('gists/1/star')))

    def test_IS_STARRED(self, request_method):
        request_method.return_value = mock_response()
        self.gs.is_starred(1)
        self.assertEqual(request_method.call_args[0],
            ('head', _('gists/1/star')))

    def test_FORK(self, request_method):
        request_method.return_value = mock_response('post')
        self.gs.fork(1)
        self.assertEqual(request_method.call_args[0],
            ('post', _('gists/1/fork')))

    def test_DELETE(self, request_method):
        request_method.return_value = mock_response('delete')
        self.gs.delete(1)
        self.assertEqual(request_method.call_args[0],
            ('delete', _('gists/1')))


@patch.object(requests.sessions.Session, 'request')
class TestCommentService(TestCase):

    def setUp(self):
        self.cs = Comments()

    def test_LIST(self, request_method):
        request_method.return_value = mock_response_result()
        self.cs.list(1).all()
        self.assertEqual(request_method.call_args[0],
            ('get', _('gists/1/comments')))

    def test_GET(self, request_method):
        request_method.return_value = mock_response()
        self.cs.get(1)
        self.assertEqual(request_method.call_args[0],
            ('get', _('gists/comments/1')))

    def test_CREATE(self, request_method):
        request_method.return_value = mock_response('post')
        self.cs.create(1, dict(body='comment'))
        self.assertEqual(request_method.call_args[0],
            ('post', _('gists/1/comments')))

    def test_UPDATE(self, request_method):
        request_method.return_value = mock_response('patch')
        self.cs.update(1, dict(body='new_comment'))
        self.assertEqual(request_method.call_args[0],
            ('patch', _('gists/comments/1')))

    def test_DELETE(self, request_method):
        request_method.return_value = mock_response('delete')
        self.cs.delete(1)
        self.assertEqual(request_method.call_args[0],
            ('delete', _('gists/comments/1')))