mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Add 4 (failing) tests for legacy search API (issue #49)
Naïve implementation done in this commit will not work: - pagination is managed another way - users, repositories and issues do not have the standard format
This commit is contained in:
+35
-3
@@ -17,6 +17,7 @@ import NamedUser
|
||||
import Organization
|
||||
import Gist
|
||||
import PaginatedList
|
||||
import Repository
|
||||
|
||||
class Github( object ):
|
||||
def __init__( self, login_or_token = None, password = None ):
|
||||
@@ -66,10 +67,41 @@ class Github( object ):
|
||||
)
|
||||
|
||||
def search_repos( self, keyword ):
|
||||
pass
|
||||
assert isinstance( keyword, ( str, unicode ) ), keyword
|
||||
headers, data = self.__requester.requestAndCheck(
|
||||
"GET",
|
||||
"https://api.github.com/legacy/repos/search/" + keyword,
|
||||
None,
|
||||
None
|
||||
)
|
||||
return PaginatedList.PaginatedList(
|
||||
Repository.Repository,
|
||||
self.__requester,
|
||||
headers,
|
||||
data[ "repositories" ]
|
||||
)
|
||||
|
||||
def search_users( self, keyword ):
|
||||
pass
|
||||
assert isinstance( keyword, ( str, unicode ) ), keyword
|
||||
headers, data = self.__requester.requestAndCheck(
|
||||
"GET",
|
||||
"https://api.github.com/legacy/user/search/" + keyword,
|
||||
None,
|
||||
None
|
||||
)
|
||||
return PaginatedList.PaginatedList(
|
||||
NamedUser.NamedUser,
|
||||
self.__requester,
|
||||
headers,
|
||||
data[ "users" ]
|
||||
)
|
||||
|
||||
def search_user_by_email( self, email ):
|
||||
pass
|
||||
assert isinstance( email, ( str, unicode ) ), email
|
||||
headers, data = self.__requester.requestAndCheck(
|
||||
"GET",
|
||||
"https://api.github.com/legacy/user/email/" + email,
|
||||
None,
|
||||
None
|
||||
)
|
||||
return NamedUser.NamedUser( self.__requester, data[ "user" ], completed = False )
|
||||
|
||||
+14
-1
@@ -1003,7 +1003,20 @@ class Repository( GithubObject.GithubObject ):
|
||||
)
|
||||
|
||||
def search_issues( self, state, keyword ):
|
||||
pass
|
||||
assert state in [ "open", "closed" ], state
|
||||
assert isinstance( keyword, ( str, unicode ) ), keyword
|
||||
headers, data = self._requester.requestAndCheck(
|
||||
"GET",
|
||||
"https://api.github.com/legacy/issues/search/" + self.owner.login + "/" + self.name + "/" + state + "/" + keyword,
|
||||
None,
|
||||
None
|
||||
)
|
||||
return PaginatedList.PaginatedList(
|
||||
Issue.Issue,
|
||||
self._requester,
|
||||
headers,
|
||||
data[ "issues" ]
|
||||
)
|
||||
|
||||
@property
|
||||
def _identity( self ):
|
||||
|
||||
@@ -16,3 +16,13 @@ import Framework
|
||||
class Github( Framework.TestCase ):
|
||||
def testGetGists( self ):
|
||||
self.assertListKeyBegin( self.g.get_gists(), lambda g: g.id, [ "2729695", "2729656", "2729597", "2729584", "2729569", "2729554", "2729543", "2729537", "2729536", "2729533", "2729525", "2729522", "2729519", "2729515", "2729506", "2729487", "2729484", "2729482", "2729441", "2729432", "2729420", "2729398", "2729372", "2729371", "2729351", "2729346", "2729316", "2729304", "2729296", "2729276", "2729272", "2729265", "2729195", "2729160", "2729143", "2729127", "2729119", "2729113", "2729103", "2729069", "2729059", "2729051", "2729029", "2729027", "2729026", "2729022", "2729002", "2728985", "2728979", "2728964", "2728937", "2728933", "2728884", "2728869", "2728866", "2728855", "2728854", "2728853", "2728846", "2728825", "2728814", "2728813", "2728812", "2728805", "2728802", "2728800", "2728798", "2728797", "2728796", "2728793", "2728758", "2728754", "2728751", "2728748", "2728721", "2728716", "2728715", "2728705", "2728701", "2728699", "2728697", "2728688", "2728683", "2728677", "2728649", "2728640", "2728625", "2728620", "2728615", "2728614", "2728565", "2728564", "2728554", "2728523", "2728519", "2728511", "2728497", "2728496", "2728495", "2728487" ] )
|
||||
|
||||
def testSearchRepos( self ):
|
||||
self.assertListKeyBegin( self.g.search_repos( "github api v3" ), lambda r: r.full_name, [ "pengwynn/octokit", "jwilger/github-v3-api", "acoulton/github_v3_api" ] )
|
||||
|
||||
def testSearchUsers( self ):
|
||||
self.assertListKeyBegin( self.g.search_users( "vincent" ), lambda u: u.login, [ "nvie", "obra", "lusis" ] )
|
||||
|
||||
def testSearchUserByEmail( self ):
|
||||
user = self.g.search_user_by_email( "vincent@vincent-jacques.net" )
|
||||
self.assertEqual( user.login, "jacquev6" )
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
GET /legacy/user/email/vincent@vincent-jacques.net {'Authorization': 'Basic login_and_password_removed'} null
|
||||
200
|
||||
[('status', '200 OK'), ('x-ratelimit-remaining', '4981'), ('content-length', '395'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"baf55235e157428f731c446efe6d6cba"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Thu, 28 Jun 2012 20:58:11 GMT'), ('content-type', 'application/json; charset=utf-8')]
|
||||
{"user":{"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","type":"User","location":"Paris, France","blog":"http://vincent-jacques.net","name":"Vincent Jacques","permission":null,"public_repo_count":11,"login":"jacquev6","email":"vincent@vincent-jacques.net","public_gist_count":3,"created_at":"2010-07-08T23:10:06-07:00","id":327146,"followers_count":13,"following_count":24,"company":"Criteo"}}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
GET /legacy/issues/search/jacquev6/PyGithub/open/search {'Authorization': 'Basic login_and_password_removed'} null
|
||||
200
|
||||
[('status', '200 OK'), ('content-length', '875'), ('x-ratelimit-limit', '5000'), ('x-ratelimit-remaining', '4985'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('etag', '"2e397de657b33283e77ef12a21326d0d"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Thu, 28 Jun 2012 20:39:57 GMT'), ('content-type', 'application/json; charset=utf-8')]
|
||||
{"issues":[{"title":"Support new Search API","number":49,"user":"kukuts","html_url":"https://github.com/jacquev6/PyGithub/issues/49","labels":["Functionalities","RequestedByUser"],"body":"New API ported from v2 but i have trouble with adopting ask's library for v2 API to support v3 style for searching. \nhttp://developer.github.com/v3/search/\n\nIts not described in the page about parameters that search for repos API supports.\nThey are same as in v2 API, you can look them in ask's library.\nIn v2 was like that https://github.com/api/v2/json/repos/search/testing?start_page=2&language=Python\nIn v3 is https://api.github.com/legacy/repos/search/testing?start_page=2&language=Python","votes":0,"comments":2,"updated_at":"2012-06-25T12:31:14-07:00","gravatar_id":"9be6ba907be1740213b69422fdf52b57","position":1.0,"state":"open","created_at":"2012-06-21T05:27:38-07:00"}]}
|
||||
|
||||
@@ -332,3 +332,6 @@ class Repository( Framework.TestCase ):
|
||||
|
||||
def testGetPullsWithArguments( self ):
|
||||
self.assertListKeyEqual( self.repo.get_pulls( "closed" ), lambda p: p.id, [ 1448168, 1436310, 1436215 ] )
|
||||
|
||||
def testSearchIssues( self ):
|
||||
self.assertListKeyEqual( self.repo.search_issues( "open", "search" ), lambda i: i.title, [ "Support new Search API" ] )
|
||||
|
||||
Reference in New Issue
Block a user