Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafb2fbf

Browse files
committed
Add unit tests for search methods
Also adds the UnitSearchIteratorHelper class to helpwriting more in the future.
1 parentba0dc07 commitafb2fbf

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

‎tests/unit/helper.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ def tearDown(self):
241241
self.get_json_mock.stop()
242242

243243

244+
classUnitSearchIteratorHelper(UnitIteratorHelper):
245+
246+
"""Base class for search iterator based unit tests."""
247+
248+
defpatch_get_json(self):
249+
"""Patch a SearchIterator's _get_json method."""
250+
self.get_json_mock=mock.patch.object(
251+
github3.structs.SearchIterator,'_get_json'
252+
)
253+
self.patched_get_json=self.get_json_mock.start()
254+
self.patched_get_json.return_value= []
255+
256+
defsetUp(self):
257+
"""Use UnitIteratorHelper's setUp and patch _get_json."""
258+
super(UnitSearchIteratorHelper,self).setUp()
259+
self.patch_get_json()
260+
261+
244262
classUnitRequiresAuthenticationHelper(UnitHelper):
245263

246264
"""Helper for unit tests that demonstrate authentication is required."""

‎tests/unit/test_github.py‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,85 @@ def test_repositories_by_with_type(self):
12951295
)
12961296

12971297

1298+
classTestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
1299+
1300+
"""Test GitHub methods that return search iterators."""
1301+
1302+
described_class=GitHub
1303+
example_data=None
1304+
1305+
deftest_search_code(self):
1306+
"""Verify the request to search for code."""
1307+
i=self.instance.search_code(
1308+
'addClass in:file language:js repo:jquery/jquery')
1309+
self.get_next(i)
1310+
1311+
self.session.get.assert_called_once_with(
1312+
url_for('search/code'),
1313+
params={'per_page':100,
1314+
'q':'addClass in:file language:js repo:jquery/jquery'},
1315+
headers={}
1316+
)
1317+
1318+
deftest_search_commits(self):
1319+
"""Verify the request to search for commits."""
1320+
i=self.instance.search_commits(
1321+
'css repo:octocat/Spoon-Knife')
1322+
self.get_next(i)
1323+
1324+
self.session.get.assert_called_once_with(
1325+
url_for('search/commits'),
1326+
params={'per_page':100,
1327+
'q':'css repo:octocat/Spoon-Knife'},
1328+
headers={'Accept':'application/vnd.github.cloak-preview'}
1329+
)
1330+
1331+
deftest_search_issues(self):
1332+
"""Verify the request to search for issues."""
1333+
i=self.instance.search_issues(
1334+
'windows label:bug language:python state:open',
1335+
sort='created',order='asc')
1336+
self.get_next(i)
1337+
1338+
self.session.get.assert_called_once_with(
1339+
url_for('search/issues'),
1340+
params={'order':'asc',
1341+
'per_page':100,
1342+
'q':'windows label:bug language:python state:open',
1343+
'sort':'created'},
1344+
headers={}
1345+
)
1346+
1347+
deftest_search_repositories(self):
1348+
"""Verify the request to search for repositories."""
1349+
i=self.instance.search_repositories(
1350+
'tetris language:assembly',
1351+
sort='stars',order='asc')
1352+
self.get_next(i)
1353+
1354+
self.session.get.assert_called_once_with(
1355+
url_for('search/repositories'),
1356+
params={'order':'asc',
1357+
'per_page':100,
1358+
'q':'tetris language:assembly',
1359+
'sort':'stars'},
1360+
headers={}
1361+
)
1362+
1363+
deftest_search_users(self):
1364+
"""Verify the request to search for users."""
1365+
i=self.instance.search_users(
1366+
'tom repos:>42 followers:>1000')
1367+
self.get_next(i)
1368+
1369+
self.session.get.assert_called_once_with(
1370+
url_for('search/users'),
1371+
params={'per_page':100,
1372+
'q':'tom repos:>42 followers:>1000'},
1373+
headers={}
1374+
)
1375+
1376+
12981377
classTestGitHubRequiresAuthentication(
12991378
helper.UnitRequiresAuthenticationHelper):
13001379

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp