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
131
132
133
134
135
136
137
138
139
140
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from unittest import TestCase
import requests
from mock import patch, Mock
from pygithub3.services.repos import Repo
from pygithub3.resources.base import json
from pygithub3.tests.utils.base import mock_response, mock_response_result
from pygithub3.tests.utils.services import _, mock_json
json.dumps = Mock(side_effect=mock_json)
json.loads = Mock(side_effect=mock_json)
@patch.object(requests.sessions.Session, 'request')
class TestRepoService(TestCase):
def setUp(self):
self.rs = Repo()
self.rs.set_user('octocat')
self.rs.set_repo('octocat_repo')
def test_LIST_without_user(self, request_method):
request_method.return_value = mock_response_result()
self.rs.set_user('')
self.rs.list().all()
self.assertEqual(request_method.call_args[0], ('get', _('user/repos')))
def test_LIST_with_user_in_args(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list('octoc').all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octoc/repos')))
def test_LIST_with_user_in_service(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list().all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octocat/repos')))
def test_LIST_filters(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list('octoc', type='public').all()
self.assertEqual(request_method.call_args[0],
('get', _('users/octoc/repos')))
self.assertEqual(request_method.call_args[1]['params']['type'],
'public')
def test_LIST_BY_ORG(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_by_org('org_name').all()
self.assertEqual(request_method.call_args[0],
('get', _('orgs/org_name/repos')))
def test_LIST_BY_ORG_filters(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_by_org('org_name', type='public').all()
self.assertEqual(request_method.call_args[0],
('get', _('orgs/org_name/repos')))
self.assertEqual(request_method.call_args[1]['params']['type'],
'public')
def test_CREATE(self, request_method):
request_method.return_value = mock_response('post')
self.rs.create({'name': 'test'})
self.assertEqual(request_method.call_args[0],
('post', _('user/repos')))
def test_CREATE_in_org(self, request_method):
request_method.return_value = mock_response('post')
self.rs.create({'name': 'test'}, in_org='org_name')
self.assertEqual(request_method.call_args[0],
('post', _('orgs/org_name/repos')))
def test_GET_with_repo_in_args(self, request_method):
request_method.return_value = mock_response()
self.rs.get(user='user', repo='repo')
self.assertEqual(request_method.call_args[0],
('get', _('repos/user/repo')))
def test_GET_with_repo_in_service(self, request_method):
request_method.return_value = mock_response()
self.rs.get()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo')))
def test_UPDATE_with_repo_in_args(self, request_method):
request_method.return_value = mock_response('patch')
self.rs.update({'name': 'test'}, user='user', repo='repo')
self.assertEqual(request_method.call_args[0],
('patch', _('repos/user/repo')))
def test_UPDATE_with_repo_in_service(self, request_method):
request_method.return_value = mock_response('patch')
self.rs.update({'name': 'test'})
self.assertEqual(request_method.call_args[0],
('patch', _('repos/octocat/octocat_repo')))
""" From here I stop to do '*in_args' and '*filter' tests, I consider
that I tested it enough... """
def test_LIST_contributors(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_contributors().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/contributors')))
def test_LIST_contributors_with_anonymous(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_contributors_with_anonymous().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/contributors')))
self.assertEqual(request_method.call_args[1]['params']['anom'], True)
def test_LIST_languages(self, request_method):
request_method.return_value = mock_response()
self.rs.list_languages()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/languages')))
def test_LIST_teams(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_teams().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/teams')))
def test_LIST_tags(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_tags().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/tags')))
def test_LIST_branches(self, request_method):
request_method.return_value = mock_response_result()
self.rs.list_branches().all()
self.assertEqual(request_method.call_args[0],
('get', _('repos/octocat/octocat_repo/branches')))
|