mirror of
https://github.com/khornberg/octokit.py
synced 2026-05-17 00:06:59 +03:00
@@ -21,7 +21,7 @@ def read(*names, **kwargs):
|
||||
|
||||
setup(
|
||||
name='octokitpy',
|
||||
version='0.11.0',
|
||||
version='0.11.1',
|
||||
license='MIT license',
|
||||
description='Python client for GitHub API',
|
||||
long_description='%s\n%s' % (
|
||||
|
||||
@@ -11,7 +11,7 @@ from octokit import errors
|
||||
from octokit import utils
|
||||
from routes import specifications
|
||||
|
||||
page_regex = re.compile(r'[\?\&]page=(\d+)[_&=\w\d]*>; rel="(\w+)"')
|
||||
page_regex = re.compile(r'[\?\&]page=(\d+)[_&=%+\w\d]*>; rel="(\w+)"')
|
||||
|
||||
|
||||
class Base(object):
|
||||
@@ -250,6 +250,7 @@ class Octokit(Base):
|
||||
def paginate(self, obj, page=1, **kwargs):
|
||||
response = self.set_pages(obj(page=page, **kwargs))
|
||||
yield response.json
|
||||
while not response.is_last_page:
|
||||
response = self.set_pages(obj(page=response.next_page, **kwargs), response.next_page)
|
||||
yield response.json
|
||||
if hasattr(response, 'is_last_page'):
|
||||
while not response.is_last_page:
|
||||
response = self.set_pages(obj(page=response.next_page, **kwargs), response.next_page)
|
||||
yield response.json
|
||||
|
||||
+20
-7
@@ -1,23 +1,28 @@
|
||||
import pytest
|
||||
|
||||
|
||||
class MockHeaders(object):
|
||||
|
||||
def __init__(self, requested_page):
|
||||
Link = 'Links <https://api.github.com/installation/repositories?page={}>; rel="next", <https://api.github.com/installation/repositories?page=4>; rel="last"'.format( # noqa E501
|
||||
def __init__(self, requested_page, **kwargs):
|
||||
link = 'Links <https://api.github.com/installation/repositories?page={}another=%2Cwith+a+space>; rel="next", <https://api.github.com/installation/repositories?page=4>; rel="last"'.format( # noqa E501
|
||||
min(requested_page + 1, 4)
|
||||
)
|
||||
self.headers = {'Link': Link}
|
||||
self.headers = {'Link': kwargs.get('link', link)}
|
||||
|
||||
|
||||
class MockObject(object):
|
||||
|
||||
def __init__(self, page, kwargs):
|
||||
self._response = MockHeaders(page)
|
||||
self._response = MockHeaders(page, **kwargs)
|
||||
self.json = {'page': page, 'kwargs': kwargs}
|
||||
# self.is_last_page = True if page == 4 else False
|
||||
# self.next_page = min(page + 1, 4) if page else 2
|
||||
|
||||
|
||||
def MockResponse(page=None, **kwargs):
|
||||
print('mr', page, kwargs)
|
||||
return MockObject(page, kwargs)
|
||||
|
||||
|
||||
def MockResponseWithoutLinks(page=None, **kwargs):
|
||||
kwargs['link'] = ''
|
||||
return MockObject(page, kwargs)
|
||||
|
||||
|
||||
@@ -48,6 +53,14 @@ class TestOctokit(object):
|
||||
assert next(p) == {'page': 3, 'kwargs': {'param': 'value'}}
|
||||
assert next(p) == {'page': 4, 'kwargs': {'param': 'value'}}
|
||||
|
||||
def test_pagination_does_break_when_iterating_over_a_single_page(self):
|
||||
from octokit import Octokit
|
||||
sut_obj = MockResponseWithoutLinks
|
||||
p = Octokit().paginate(sut_obj, param='value')
|
||||
assert next(p) == {'page': 1, 'kwargs': {'param': 'value', 'link': ''}}
|
||||
with pytest.raises(StopIteration):
|
||||
assert next(p)
|
||||
|
||||
def test_can_speficy_the_route_specifications_used(self):
|
||||
from octokit import Octokit
|
||||
octokit = Octokit(routes='ghe-2.15')
|
||||
|
||||
Reference in New Issue
Block a user