示例#1
0
    def test_internalservererror_500_backoff_behaviour(
            self, mocked_session, mocked_internalservererror_500_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except (requests.HTTPError, client_.TypeformInternalError) as e:
            pass

        self.assertEqual(mocked_internalservererror_500_error.call_count, 3)
        self.assertEqual(mocked_session.call_count, 3)
示例#2
0
 def test_connection_error_backoff(self, mocked_request, mock_send, mock_sleep):
     """
         Verify request function is backoff for 5 times on ConnectionError exceeption
     """
     config = {'token': '123'}
     client = client_.Client(config)
     url = client.build_url(self.endpoint)
     try:
         client.request('GET', url)
     except requests.exceptions.ConnectionError as e:
         # Verify that request.Session.send called 5 times
         self.assertEqual(mock_send.call_count, 5)
示例#3
0
    def test_too_many_requests_429_backoff_behavior(self, mocked_session,
                                                    mocked_failed_429_request):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except (requests.HTTPError, client_.TypeformTooManyError) as e:
            pass

        #Verify daily limit should not backoff
        self.assertEqual(mocked_failed_429_request.call_count, 3)
        self.assertEqual(mocked_session.call_count, 3)
示例#4
0
    def test_too_many_requests_429(self, mocked_session,
                                   mocked_failed_429_request):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformTooManyError as e:
            expected_error_message = "HTTP-error-code: 429, Error: The API rate limit for your organisation/application pairing has been exceeded"

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#5
0
    def test_not_available_503_error(self, mocked_session,
                                     mocked_not_available_503_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformNotAvailableError as e:
            expected_error_message = "HTTP-error-code: 503, Error: API service is currently unavailable."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#6
0
    def test_internalservererror_500_error(
            self, mocked_session, mocked_internalservererror_500_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformInternalError as e:
            expected_error_message = "HTTP-error-code: 500, Error: An unhandled error with the Typeform API. Contact the Typeform API team if problems persist."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#7
0
    def test_notfound_404_error(self, mocked_session,
                                mocked_notfound_404_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformNotFoundError as e:
            expected_error_message = "HTTP-error-code: 404, Error: The resource you have specified cannot be found."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#8
0
    def test_forbidden_403_exception(self, mocked_session,
                                     mocked_forbidden_403_exception):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformForbiddenError as e:
            expected_error_message = "HTTP-error-code: 403, Error: User doesn't have permission to access the resource."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#9
0
    def test_unauthorized_401_error(self, mocked_session,
                                    mocked_unauthorized_401_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformUnauthorizedError as e:
            expected_error_message = "HTTP-error-code: 401, Error: Invalid authorization credentials."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#10
0
    def test_badrequest_400_error(self, mocked_session,
                                  mocked_badrequest_400_error):
        config = {'token': '123'}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        try:
            client.request('GET', url)
        except client_.TypeformBadRequestError as e:
            expected_error_message = "HTTP-error-code: 400, Error: A validation exception has occurred."

            # Verifying the message formed for the custom exception
            self.assertEqual(str(e), expected_error_message)
            pass
示例#11
0
    def test_request_timeout_for_zero_int_value_in_config(self, mocked_request, mock_send, mock_sleep):
        """
            Verify that if request_timeout is provided in config with zero value then default value is used
        """       
        config = {'token': '123', "request_timeout": 0}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        # Call request method which call requests.Session.send with timeout
        client.request('GET', url)

        # Verify requests.Session.send is called with expected timeout
        args, kwargs = mock_send.call_args
        self.assertEqual(kwargs.get('timeout'), REQUEST_TIMEOUT_INT) # Verify timeout argument
示例#12
0
    def test_request_timeout_for_string_value_in_config(self, mocked_request, mock_send, mock_sleep):
        """
            Verify that if request_timeout is provided in config(string value) then it should be use
        """
        config = {'token': '123', "request_timeout": REQUEST_TIMEOUT_STR}
        client = client_.Client(config)
        url = client.build_url(self.endpoint)
        
        # Call request method which call requests.Session.request with timeout
        client.request('GET', url)

        # Verify requests.Session.send is called with expected timeout
        args, kwargs = mock_send.call_args
        self.assertEqual(kwargs.get('timeout'), REQUEST_TIMEOUT_FLOAT) # Verify timeout argument