Ejemplo n.º 1
0
def test_get_image_list_retries_with_none_response():
    with patch.object(
            europeana.delayed_requester,
            'get',
            return_value=None
    ) as mock_get:
        europeana._get_image_list('1234', '5678', 'test_cursor', max_tries=3)

    assert mock_get.call_count == 3
Ejemplo n.º 2
0
def test_get_image_list_retries_with_non_ok_response():
    response_json = _get_resource_json('europeana_example.json')
    r = requests.Response()
    r.status_code = 504
    r.json = MagicMock(return_value=response_json)
    with patch.object(europeana.delayed_requester, 'get',
                      return_value=r) as mock_get:
        europeana._get_image_list('1234', '5678', 'test_cursor', max_tries=3)

    assert mock_get.call_count == 3
Ejemplo n.º 3
0
def test_get_image_list_for_last_page():
    response_json = _get_resource_json('europeana_example.json')
    response_json['items'] = []
    response_json.pop('nextCursor', None)

    r = requests.Response()
    r.status_code = 200
    r.json = MagicMock(return_value=response_json)

    with patch.object(europeana.delayed_requester, 'get',
                      return_value=r) as mock_get:
        europeana._get_image_list('1234', '5678', 'test_cursor')

    mock_get.assert_called_once()
Ejemplo n.º 4
0
def test_get_image_list_with_realistic_response():
    response_json = _get_resource_json('europeana_example.json')
    r = requests.Response()
    r.status_code = 200
    r.json = MagicMock(return_value=response_json)
    with patch.object(europeana.delayed_requester, 'get',
                      return_value=r) as mock_get:
        image_list, next_cursor, total_number_of_images = (
            europeana._get_image_list('1234',
                                      '5678',
                                      'test_cursor',
                                      max_tries=3))
    expect_image_list = _get_resource_json('europeana_image_list.json')

    assert mock_get.call_count == 1
    assert image_list == expect_image_list