def test_max_attempts(self):
        self.checker = retryhandler.MaxAttemptsDecorator(
            retryhandler.HTTPStatusCodeChecker(500), max_attempts=3)
        response = {'ResponseMetadata': {}}

        # Retry up to three times.
        self.assert_should_be_retried((HTTP_500_RESPONSE, response),
                                      attempt_number=1)
        self.assert_should_be_retried((HTTP_500_RESPONSE, {}),
                                      attempt_number=2)
        # On the third failed response, we've reached the
        # max attempts so we should return False.
        self.assert_should_not_be_retried((HTTP_500_RESPONSE, response),
                                          attempt_number=3)
        self.assertTrue(response['ResponseMetadata']['MaxAttemptsReached'])
    def test_max_attempts_successful(self):
        self.checker = retryhandler.MaxAttemptsDecorator(
            retryhandler.HTTPStatusCodeChecker(500), max_attempts=3)

        self.assert_should_be_retried((HTTP_500_RESPONSE, {}),
                                      attempt_number=1)
        # The second retry is successful.
        self.assert_should_not_be_retried((HTTP_200_RESPONSE, {}),
                                          attempt_number=2)

        # But now we can reuse this object.
        self.assert_should_be_retried((HTTP_500_RESPONSE, {}),
                                      attempt_number=1)
        self.assert_should_be_retried((HTTP_500_RESPONSE, {}),
                                      attempt_number=2)
        self.assert_should_not_be_retried((HTTP_500_RESPONSE, {}),
                                          attempt_number=3)