def test_normalize_api_params_ignores_unknown_params(self): '''normalize_api_params shouldn't transform unknown params.''' self.assertEqual({'foo': u'bar'}, normalize_api_params({'foo': u'bar'})) self.assertEqual({'order': u'desc', 'foo': u'bar'}, normalize_api_params({'foo': u'bar', 'direction': u'desc'}))
def test_normalize_api_params_ignores_unknown_params(self): """Ignore unknown parameters in normalize_api_params.""" self.assertEqual({'foo': 'bar'}, normalize_api_params({'foo': 'bar'})) self.assertEqual({'order': 'desc', 'foo': 'bar'}, normalize_api_params({'foo': 'bar', 'direction': 'desc'}))
def test_normalize_api_params_ignores_unknown_params(self): """Ignore unknown parameters in normalize_api_params.""" self.assertEqual({'foo': u'bar'}, normalize_api_params({'foo': u'bar'})) self.assertEqual({'order': u'desc', 'foo': u'bar'}, normalize_api_params({'foo': u'bar', 'direction': u'desc'}))
def test_normalize_api_params_converts_correctly(self): '''Test that API params are correctly converted to Search API.''' self.assertEqual(normalize_api_params({'direction': u'desc'}), {'order': u'desc'}) self.assertNotIn('direction', normalize_api_params({'direction': u'desc'})) self.assertEqual(normalize_api_params({'state': u'closed', 'q': 'hi'}), {'q': u'hi state:closed'}) self.assertNotIn('state', normalize_api_params({'state': u'closed', 'q': 'hi'})) self.assertEqual(normalize_api_params({'mentioned': u'coolguy', 'q': 'hi'}), {'q': u'hi mentions:coolguy'}) self.assertNotIn('mentioned', normalize_api_params({'mentioned': u'coolguy', 'q': 'hi'})) self.assertEqual(normalize_api_params({'creator': u'coolguy', 'q': 'hi'}), {'q': u'hi author:coolguy'}) self.assertNotIn('creator', normalize_api_params({'creator': u'coolguy', 'q': 'hi'})) multi_before = {'direction': u'desc', 'state': u'closed', 'mentioned': u'coolguy', 'creator': u'coolguy', 'per_page': u'1', 'q': u'hi'} multi_after = {'order': u'desc', 'q': u'hi state:closed author:coolguy mentions:coolguy', 'per_page': u'1'} self.assertEqual(normalize_api_params(multi_before), multi_after)
def get_search_results(query_string=None, params=None): """XHR endpoint to get results from GitHub's Search API. We're specifically searching "issues" here, which seems to make the most sense. Note that the rate limit is different for Search: 30 requests per minute. If a user hits the rate limit, the Flask Limiter extension will send a 429. See @app.error_handler(429) in views.py. This method can take a query_string argument, to be called from other endpoints, or the query_string can be passed in via the Request object. """ params = params or request.args.copy() query_string = query_string or params.get('q') # Fail early if no appropriate query_string if not query_string: abort(404) # restrict results to our repo. query_string += " repo:{0}".format(REPO_PATH) params['q'] = query_string # convert issues api to search api params here. params = normalize_api_params(params) path = 'search/issues' return api_request('get', path, params=params, mime_type=JSON_MIME_HTML)
def get_search_results(query_string=None, params=None): """XHR endpoint to get results from GitHub's Search API. We're specifically searching "issues" here, which seems to make the most sense. Note that the rate limit is different for Search: 30 requests per minute. If a user hits the rate limit, the Flask Limiter extension will send a 429. See @app.error_handler(429) in views.py. This method can take a query_string argument, to be called from other endpoints, or the query_string can be passed in via the Request object. Not cached. """ params = params or request.args.copy() query_string = query_string or params.get("q") search_uri = "https://api.github.com/search/issues" # restrict results to our repo. query_string += " repo:{0}".format(REPO_PATH) params["q"] = query_string # convert issues api to search api params here. params = normalize_api_params(params) request_headers = get_request_headers(g.request_headers) if g.user: results = github.raw_request("GET", "search/issues", params=params, headers=request_headers) else: results = proxy_request("get", params=params, uri=search_uri, headers=request_headers) return (results.content, results.status_code, get_headers(results))
def get_search_results(query_string=None, params=None): '''XHR endpoint to get results from GitHub's Search API. We're specifically searching "issues" here, which seems to make the most sense. Note that the rate limit is different for Search: 30 requests per minute. If a user hits the rate limit, the Flask Limiter extension will send a 429. See @app.error_handler(429) in views.py. This method can take a query_string argument, to be called from other endpoints, or the query_string can be passed in via the Request object. Not cached. ''' params = params or request.args.copy() query_string = query_string or params.get('q') search_uri = 'https://api.github.com/search/issues' # restrict results to our repo. query_string += " repo:{0}".format(REPO_PATH) params['q'] = query_string # convert issues api to search api params here. params = normalize_api_params(params) request_headers = get_request_headers(g.request_headers) if g.user: results = github.raw_request('GET', 'search/issues', params=params, headers=request_headers) else: results = proxy_request('get', params=params, uri=search_uri, headers=request_headers) return (results.content, results.status_code, get_headers(results))