forked from donnemartin/gitsome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_github_cli.py
More file actions
285 lines (247 loc) · 12 KB
/
test_github_cli.py
File metadata and controls
285 lines (247 loc) · 12 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# -*- coding: utf-8 -*-
# Copyright 2015 Donne Martin. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from __future__ import unicode_literals
from __future__ import print_function
import mock
from compat import unittest
from click.testing import CliRunner
from gitsome.githubcli import GitHubCli
class GitHubCliTest(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()
self.github_cli = GitHubCli()
self.limit = 1000
def test_cli(self):
result = self.runner.invoke(self.github_cli.cli)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.configure')
def test_configure(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli, ['configure'])
mock_gh_call.assert_called_with(False)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.create_comment')
def test_create_comment(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['create-comment', 'u/r/n',
'--text', 'foo'])
mock_gh_call.assert_called_with('u/r/n', 'foo')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.create_issue')
def test_create_issue(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['create-issue', 'u/r',
'--issue_title', 'foo',
'--issue_desc', 'bar'])
mock_gh_call.assert_called_with('u/r', 'foo', 'bar')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.create_repo')
def test_create_repo(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['create-repo', 'r',
'--repo_desc', 'foo',
'--private'])
mock_gh_call.assert_called_with('r', 'foo', True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.emails')
def test_emails(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['emails'])
mock_gh_call.assert_called_with()
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.emojis')
def test_emojis(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['emojis',
'--pager'])
mock_gh_call.assert_called_with(True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.feed')
def test_feed(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['feed', 'u',
'--private', '--pager'])
mock_gh_call.assert_called_with('u', True, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.followers')
def test_followers(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['followers', 'u',
'--pager'])
mock_gh_call.assert_called_with('u', True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.following')
def test_following(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['following', 'u',
'--pager'])
mock_gh_call.assert_called_with('u', True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.gitignore_template')
def test_gitignore_template(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['gitignore-template', 'l'])
mock_gh_call.assert_called_with('l')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.gitignore_templates')
def test_gitignore_templates(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['gitignore-templates',
'--pager'])
mock_gh_call.assert_called_with(True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.issue')
def test_issue(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['issue', 'u/r/n'])
mock_gh_call.assert_called_with('u/r/n')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.issues_setup')
def test_issues(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['issues',
'--issue_filter', 'mentioned',
'--issue_state', 'closed',
'--limit', '10',
'--pager'])
mock_gh_call.assert_called_with('mentioned', 'closed', 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.license')
def test_license(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['license', 'l'])
mock_gh_call.assert_called_with('l')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.licenses')
def test_licenses(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['licenses'])
mock_gh_call.assert_called_with()
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.user_me')
def test_me(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['me',
'--browser', '--text_avatar',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with(True, True, 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.notifications')
def test_notifications(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['notifications',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with(10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.octocat')
def test_octocat(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['octo', 'foo'])
mock_gh_call.assert_called_with('foo')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.issue')
def test_pull_request(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['pull-request', 'u/r/n'])
mock_gh_call.assert_called_with('u/r/n')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.pull_requests')
def test_pull_requests(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['pull-requests',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with(10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.rate_limit')
def test_rate_limit(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['rate-limit'])
mock_gh_call.assert_called_with()
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.repository')
def test_repository(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['repo', 'u/r'])
mock_gh_call.assert_called_with('u/r')
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.repositories_setup')
def test_repositories(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['repos', 'foo',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with('foo', 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.search_issues')
def test_search_issues(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['search-issues', 'foo',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with('foo', 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.search_repositories')
def test_search_repositories(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['search-repos', 'foo',
'--sort', 'stars',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with('foo', 'stars', 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.starred')
def test_starred(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['starred', 'foo',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with('foo', 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.trending')
def test_trending(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['trending', 'l',
'--pager'])
mock_gh_call.assert_called_with('l', False, False, False, False, True)
result = self.runner.invoke(self.github_cli.cli,
['trending', 'l',
'--weekly',
'--pager'])
mock_gh_call.assert_called_with('l', True, False, False, False, True)
result = self.runner.invoke(self.github_cli.cli,
['trending', 'l',
'--monthly',
'--devs',
'--browser',
'--pager'])
mock_gh_call.assert_called_with('l', False, True, True, True, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.user')
def test_user(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['user', 'foo',
'--browser', '--text_avatar',
'--limit', 10,
'--pager'])
mock_gh_call.assert_called_with('foo', True, True, 10, True)
assert result.exit_code == 0
@mock.patch('gitsome.githubcli.GitHub.view')
def test_view(self, mock_gh_call):
result = self.runner.invoke(self.github_cli.cli,
['view', '1',
'--browser'])
mock_gh_call.assert_called_with(1, True)
assert result.exit_code == 0