Esempio n. 1
0
async def test_fetch_page_with_no_meta(mocker):
    """Tests that no meta object in response is not an issue"""
    dataset = 'calls'
    fake_data = {'data': {'stuff': 'stuff'}}
    fake_data = helpers.build_future(fake_data)
    fake_fetch = mocker.patch(fetch_fn_name, return_value=fake_data)
    # despite there being a limit of 10 runs, only one run should occur
    res = await fetch_page(dataset, [], {}, 10, 0)
    assert len(res) == 1
    assert_called_with(fake_fetch, expected_count=1)
Esempio n. 2
0
async def test_fetch_page_with_no_next(mocker):
    """Bearer version: tests that no next page returns an array of one response"""
    dataset = 'tags'
    fake_data = {'data': {'stuff': 'stuff'}, 'meta': {'next_page_link': None, 'current_page': 1}}
    fake_data = helpers.build_future(fake_data)
    fake_fetch = mocker.patch(fetch_fn_name, return_value=fake_data)
    result = await fetch_page(dataset, [], {}, 10, 0)
    assert len(result) == 1
    first_dict = result[0]
    assert 'data' in first_dict
    assert 'meta' in first_dict

    assert_called_with(
        fake_fetch, ['https://proxy.bearer.sh/aircall_oauth/tags?per_page=50&page=1', {}]
    )
Esempio n. 3
0
async def test_fetch_page_with_low_limit(mocker):
    """Test fetch_page to see limit and current pass stopping recursion"""
    dataset = 'users'
    data_list = [
        {
            'data': {
                'stuff': 'stuff'
            },
            'meta': {
                'next_page_link': '/users?page=2',
                'current_page': 1
            },
        },
        {
            'data': {
                'stuff': 'stuff'
            },
            'meta': {
                'next_page_link': '/users?page=3',
                'current_page': 2
            },
        },
        {
            'data': {
                'stuff': 'stuff'
            },
            'meta': {
                'next_page_link': None,
                'current_page': 3
            }
        },
    ]
    data_list = [item for item in data_list]
    fake_fetch = mocker.patch(fetch_fn_name, side_effect=data_list)
    # limit is only 1 and run is 0 i.e. this is the first run
    res = await fetch_page(dataset, [], {}, 1, 0)
    assert len(res) == 1

    assert_called_with(
        fake_fetch, ['https://api.aircall.io/v1/users?per_page=50&page=1', {}])
Esempio n. 4
0
async def test_fetch_page_with_next_page(mocker):
    """Test fetch_page to see multiple pages"""
    dataset = 'calls'
    data_list = [
        {
            'data': {'stuff': 'stuff'},
            'meta': {'next_page_link': '/calls?page=2', 'current_page': 1},
        },
        {'data': {'stuff': 'stuff'}, 'meta': {'next_page_link': None, 'current_page': 2}},
    ]
    data_list = [helpers.build_future(item) for item in data_list]
    fake_fetch = mocker.patch(fetch_fn_name, side_effect=data_list)

    # limit is 10 and run is 0 i.e. this is the first run
    # want to see that, despite the limit being set to 10,
    # only two objects are sent in the array because no next_page_link
    # on second object means that there is no more to be fetched
    fake_res = await fetch_page(dataset, [], {}, 10, 0)
    assert len(fake_res) == 2

    assert_called_with(
        fake_fetch, ['https://proxy.bearer.sh/aircall_oauth/calls?per_page=50&page=2', {}], 2
    )
Esempio n. 5
0
async def test_fetch_page_with_next_page_negative_limit(mocker):
    """Test fetch_page to see multiple pages with a negative limit, it's not supposed to happen
    as with have a validation on limit which must be > 0"""
    dataset = 'calls'
    data_list = [
        {
            'data': {
                'stuff': 'stuff'
            },
            'meta': {
                'next_page_link': '/calls?page=2',
                'current_page': 1
            },
        },
        {
            'data': {
                'stuff': 'stuff'
            },
            'meta': {
                'next_page_link': '/calls?page=3',
                'current_page': 2
            },
        },
        {
            'data': {
                'stuff': 'stuff'
            }
        },
    ]
    data_list = [item for item in data_list]
    fake_fetch = mocker.patch(fetch_fn_name, side_effect=data_list)
    fake_res = await fetch_page(dataset, [], {}, -1, 0)
    assert len(fake_res) == 3

    assert_called_with(
        fake_fetch, ['https://api.aircall.io/v1/calls?per_page=50&page=3', {}],
        3)