From 14ef05b1ffef24fae97ae3e79567ab612a75ff11 Mon Sep 17 00:00:00 2001 From: David Medina Date: Sun, 4 Mar 2012 16:58:08 +0100 Subject: Refactor result. Now it's a package result.smart => Paginate iterator with 'page' behaviour. result.normal => Paginate iterator with 'next' behaviour. --- pygithub3/tests/utils/core.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'pygithub3/tests/utils') diff --git a/pygithub3/tests/utils/core.py b/pygithub3/tests/utils/core.py index 32170e4..677347a 100644 --- a/pygithub3/tests/utils/core.py +++ b/pygithub3/tests/utils/core.py @@ -13,6 +13,8 @@ request = DummyRequest() json_content = [dict(name='dummy')] +# To smart results + def mock_paginate_github_in_GET(request, page): def header(page): return {'link': '; rel="last"' % page} @@ -33,3 +35,27 @@ def mock_no_paginate_github_in_GET(request, page): response.headers = {} response.content = [json_content * 3] return response + + +# To normal results +class MockPaginate(object): + + def __init__(self): + self.counter = 1 + + def content(self): + if self.counter >= 3: + return json_content + return json_content * 2 + + def header(self): + if self.counter >= 3: + return {} + return {'link': '; rel="next"' % self.counter} + + def __call__(self, *args, **kwargs): + response = Mock() + response.headers = self.header() + response.content = self.content() + self.counter += 1 + return response -- cgit v1.2.3-59-g8ed1b