コード例 #1
0
def test_get_throws():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 500

        client = ReliableHttpClient("http://url.com", {}, "username", "password", retry_policy)

        client.get("r", [200])
コード例 #2
0
def test_get_throws():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 500

        client = ReliableHttpClient(endpoint, {}, retry_policy)

        client.get("r", [200])
コード例 #3
0
def test_get_throws():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 500

        client = ReliableHttpClient(endpoint, {}, retry_policy)

        client.get("r", [200])
コード例 #4
0
def test_get_throws():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 500

        client = ReliableHttpClient("http://url.com", {}, "username", "password", retry_policy)

        client.get("r", [200])
コード例 #5
0
def test_will_retry_error_no():
    global sequential_values, retry_policy
    retry_policy = MagicMock()
    retry_policy.should_retry.return_value = False
    retry_policy.seconds_to_sleep.return_value = 0.01

    with patch('requests.get') as patched_get:
        patched_get.side_effect = requests.exceptions.ConnectionError()
        client = ReliableHttpClient(endpoint, {}, retry_policy)

        try:
            client.get("r", [200])
            assert False
        except ValueError:
            retry_policy.should_retry.assert_called_once_with(None, True, 0)
コード例 #6
0
def test_will_retry_error_no():
    global sequential_values, retry_policy
    retry_policy = MagicMock()
    retry_policy.should_retry.return_value = False
    retry_policy.seconds_to_sleep.return_value = 0.01

    with patch('requests.get') as patched_get:
        patched_get.side_effect = requests.exceptions.ConnectionError()
        client = ReliableHttpClient(endpoint, {}, retry_policy)

        try:
            client.get("r", [200])
            assert False
        except HttpClientException:
            retry_policy.should_retry.assert_called_once_with(None, True, 0)
コード例 #7
0
def test_get():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 200

        client = ReliableHttpClient(endpoint, {}, retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
コード例 #8
0
def test_get():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 200

        client = ReliableHttpClient(endpoint, {}, retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
コード例 #9
0
def test_get():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 200

        client = ReliableHttpClient("http://url.com", {}, "username", "password", retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
コード例 #10
0
def test_get():
    with patch('requests.get') as patched_get:
        type(patched_get.return_value).status_code = 200

        client = ReliableHttpClient("http://url.com", {}, "username", "password", retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
コード例 #11
0
def test_get_will_retry():
    global sequential_values, retry_policy
    retry_policy = MagicMock()
    retry_policy.should_retry.return_value = True
    retry_policy.seconds_to_sleep.return_value = 0.01

    with patch('requests.get') as patched_get:
        # When we call assert_equals in this unit test, the side_effect is executed.
        # So, the last status_code should be repeated.
        sequential_values = [500, 200, 200]
        pm = PropertyMock()
        pm.side_effect = return_sequential
        type(patched_get.return_value).status_code = pm
        client = ReliableHttpClient(endpoint, {}, retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
        retry_policy.should_retry.assert_called_once_with(500, False, 0)
        retry_policy.seconds_to_sleep.assert_called_once_with(0)
コード例 #12
0
def test_get_will_retry():
    global sequential_values, retry_policy
    retry_policy = MagicMock()
    retry_policy.should_retry.return_value = True
    retry_policy.seconds_to_sleep.return_value = 0.01

    with patch('requests.get') as patched_get:
        # When we call assert_equals in this unit test, the side_effect is executed.
        # So, the last status_code should be repeated.
        sequential_values = [500, 200, 200]
        pm = PropertyMock()
        pm.side_effect = return_sequential
        type(patched_get.return_value).status_code = pm
        client = ReliableHttpClient(endpoint, {}, retry_policy)

        result = client.get("r", [200])

        assert_equals(200, result.status_code)
        retry_policy.should_retry.assert_called_once_with(500, False, 0)
        retry_policy.seconds_to_sleep.assert_called_once_with(0)