Skip to content

Commit 7410abf

Browse files
committed
Use a RepositorySearchResult
Fix up the tests
1 parent 2b9aa01 commit 7410abf

6 files changed

Lines changed: 34 additions & 10 deletions

File tree

github3/github.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from github3.models import GitHubCore
1818
from github3.orgs import Organization
1919
from github3.repos import Repository
20-
from github3.search import CodeSearchResult
20+
from github3.search import CodeSearchResult, RepositorySearchResult
2121
from github3.structs import SearchIterator
2222
from github3.users import User, Key
2323
from github3.notifications import Thread
@@ -1099,8 +1099,8 @@ def search_repositories(self, query, sort=None, order=None,
10991099
}
11001100

11011101
url = self._build_url('search', 'repositories')
1102-
return SearchIterator(number, url, Repository, self, params, etag,
1103-
headers)
1102+
return SearchIterator(number, url, RepositorySearchResult, self,
1103+
params, etag, headers)
11041104

11051105
def set_client_id(self, id, secret):
11061106
"""Allows the developer to set their client_id and client_secret for

github3/search/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .code import CodeSearchResult
2+
from .repository import RepositorySearchResult
23

34

4-
__all__ = [CodeSearchResult]
5+
__all__ = [CodeSearchResult, RepositorySearchResult]

github3/search/repository.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
from github3.models import GitHubCore
3+
from github3.repos import Repository
4+
5+
6+
class RepositorySearchResult(GitHubCore):
7+
def __init__(self, data, session=None):
8+
result = data.copy()
9+
#: Score of the result
10+
self.score = result.pop('score')
11+
#: Text matches
12+
self.text_matches = result.pop('text_matches', [])
13+
#: Repository object
14+
self.repository = Repository(result, self)

tests/cassettes/GitHub_search_repositories_text_match.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/integration/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ def test_search_repositories(self):
1010
cls='GitHub')
1111
with self.recorder.use_cassette(cassette_name):
1212
repos = self.gh.search_repositories('github3 language:python')
13-
assert isinstance(next(repos), github3.repos.repo.Repository)
13+
assert isinstance(next(repos),
14+
github3.search.RepositorySearchResult)

tests/integration/test_github.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818

1919
class TestGitHub(IntegrationHelper):
20+
match_on = ['method', 'uri', 'headers']
21+
2022
def test_create_gist(self):
2123
"""Test the ability of a GitHub instance to create a new gist"""
2224
self.token_login()
@@ -209,7 +211,8 @@ def test_search_code(self):
209211
def test_search_code_with_text_match(self):
210212
"""Test the ability to use the code search endpoint"""
211213
cassette_name = self.cassette_name('search_code_with_text_match')
212-
with self.recorder.use_cassette(cassette_name):
214+
with self.recorder.use_cassette(cassette_name,
215+
match_requests_on=self.match_on):
213216
result_iterator = self.gh.search_code(
214217
('HTTPAdapter in:file language:python'
215218
' repo:kennethreitz/requests'),
@@ -225,20 +228,25 @@ def test_search_repositories(self):
225228
cassette_name = self.cassette_name('search_repositories')
226229
with self.recorder.use_cassette(cassette_name):
227230
repos = self.gh.search_repositories('github3 language:python')
228-
assert isinstance(next(repos), github3.repos.repo.Repository)
231+
assert isinstance(next(repos),
232+
github3.search.RepositorySearchResult)
229233

230234
assert isinstance(repos, github3.structs.SearchIterator)
231235

232236
def test_search_repositories_with_text_match(self):
233237
"""Test the ability to use the repository search endpoint"""
234238
self.token_login()
235239
cassette_name = self.cassette_name('search_repositories_text_match')
236-
with self.recorder.use_cassette(cassette_name):
240+
with self.recorder.use_cassette(cassette_name,
241+
match_requests_on=self.match_on):
237242
repos = self.gh.search_repositories('github3 language:python',
238243
text_match=True)
239-
assert isinstance(next(repos), github3.repos.repo.Repository)
244+
repo_result = next(repos)
245+
assert isinstance(repo_result,
246+
github3.search.RepositorySearchResult)
240247

241248
assert isinstance(repos, github3.structs.SearchIterator)
249+
assert len(repo_result.text_matches) > 0
242250

243251
def test_user(self):
244252
"""Test the ability to retrieve a User"""

0 commit comments

Comments
 (0)