コード例 #1
0
def test_get_image_batch_returns_correctly_without_continue(monkeypatch):
    with open(os.path.join(RESOURCES,
                           'response_small_missing_continue.json')) as f:
        resp_dict = json.load(f)

    with patch.object(wmc, '_get_response_json',
                      return_value=resp_dict) as mock_response_json:
        actual_result, actual_continue = wmc._get_image_batch('2019-01-01',
                                                              '2019-01-02',
                                                              retries=2)

    expect_result = resp_dict
    expect_continue = {}

    mock_response_json.assert_called_once()
    assert actual_continue == expect_continue
    assert actual_result == expect_result
コード例 #2
0
def test_get_image_batch(monkeypatch):
    with open(
            os.path.join(RESOURCES, 'continuation', 'wmc_pretty1.json')
    ) as f:
        first_response = json.load(f)
    with open(
            os.path.join(RESOURCES, 'continuation', 'wmc_pretty2.json')
    ) as f:
        second_response = json.load(f)
    with open(
            os.path.join(RESOURCES, 'continuation', 'wmc_pretty3.json')
    ) as f:
        third_response = json.load(f)

    def mock_get_response_json(endpoint, retries, query_params, **kwargs):
        continue_one = 'Edvard_Munch_-_Night_in_Nice_(1891).jpg|nowiki|1281339'
        continue_two = 'Niedercunnersdorf_Gartenweg_12.JPG|dewiki|9849507'
        if 'continue' not in query_params:
            return first_response
        elif query_params['gucontinue'] == continue_one:
            return second_response
        elif query_params['gucontinue'] == continue_two:
            return third_response
        else:
            return None

    with open(
            os.path.join(RESOURCES, 'continuation', 'wmc_pretty123.json')
    ) as f:
        expect_image_batch = json.load(f)
    expect_image_batch.pop('continue')
    expect_continue_token = {
        'gaicontinue': "20151031230201|Lancelot_'Capability'_BROWN_-_Wilderness_House_Moat_Lane_Hampton_Court_Palace_Hampton_Court_London_KT8_9AR.jpg",
        'continue': 'gaicontinue||'
    }

    monkeypatch.setattr(wmc.delayed_requester, 'get_response_json',
                        mock_get_response_json)
    actual_image_batch, actual_continue_token = wmc._get_image_batch(
        '2019-01-01', '2019-01-02'
    )
    assert actual_image_batch == expect_image_batch
    assert actual_continue_token == expect_continue_token