aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/tests/utils/core.py
blob: 677347ac647bcefef3f6714ac15eab6876134ed3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

try:
    from unittest2 import TestCase  # Python 2.6
except ImportError:
    from unittest import TestCase  # Python >2.7

from .base import Mock, DummyRequest

request = DummyRequest()
# Working without json but name it json-related to not confuse
json_content = [dict(name='dummy')]


# To smart results

def mock_paginate_github_in_GET(request, page):
    def header(page):
        return {'link': '<https://d.com/d?page=%s>; rel="last"' % page}

    def content(page):
        if page >= 3:
            return json_content
        return json_content * 2

    response = Mock()
    response.headers = header(3)
    response.content = content(page)
    return response


def mock_no_paginate_github_in_GET(request, page):
    response = Mock()
    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': '<https://d.com/d?page=%s>; rel="next"' % self.counter}

    def __call__(self, *args, **kwargs):
        response = Mock()
        response.headers = self.header()
        response.content = self.content()
        self.counter += 1
        return response