def test_get_response_json_retries_with_error_json():
    r = requests.Response()
    r.status_code = 200
    r.json = MagicMock(return_value={'error': ''})
    with patch.object(wmc.delayed_requester, 'get',
                      return_value=r) as mock_get:
        wmc._get_response_json({}, retries=2)

    assert mock_get.call_count == 3
예제 #2
0
def test_get_response_json_retries_with_none_response():
    with patch.object(wmc.delayed_requester, 'get',
                      return_value=None) as mock_get:
        with pytest.raises(Exception):
            assert wmc._get_response_json({}, retries=2)

    assert mock_get.call_count == 3
예제 #3
0
def test_get_response_json_retries_with_non_ok():
    r = requests.Response()
    r.status_code = 504
    r.json = MagicMock(return_value={'batchcomplete': ''})
    with patch.object(wmc.delayed_requester, 'get',
                      return_value=r) as mock_get:
        with pytest.raises(Exception):
            assert wmc._get_response_json({}, retries=2)

    assert mock_get.call_count == 3
예제 #4
0
def test_get_response_json_returns_response_json_when_all_ok():
    expect_response_json = {'batchcomplete': ''}
    r = requests.Response()
    r.status_code = 200
    r.json = MagicMock(return_value=expect_response_json)
    with patch.object(wmc.delayed_requester, 'get',
                      return_value=r) as mock_get:
        actual_response_json = wmc._get_response_json({}, retries=2)

    assert mock_get.call_count == 1
    assert actual_response_json == expect_response_json