diff options
author | MIDORIBIN <aquarion123@gmail.com> | 2023-07-28 12:07:17 +0200 |
---|---|---|
committer | MIDORIBIN <aquarion123@gmail.com> | 2023-08-14 04:46:32 +0200 |
commit | f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd (patch) | |
tree | c8bc44917ea03909cf586140f984ff0814bc30ea /g4f/.v1/gpt4free/quora/tests/test_api.py | |
parent | ~ | small fixes & new pypi version | v-0.0.1.9 (diff) | |
download | gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar.gz gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar.bz2 gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar.lz gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar.xz gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.tar.zst gpt4free-f6ef3cb2237d8c336e915ef77ddbe6f37934c4fd.zip |
Diffstat (limited to 'g4f/.v1/gpt4free/quora/tests/test_api.py')
-rw-r--r-- | g4f/.v1/gpt4free/quora/tests/test_api.py | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/g4f/.v1/gpt4free/quora/tests/test_api.py b/g4f/.v1/gpt4free/quora/tests/test_api.py deleted file mode 100644 index 2a4bb41b..00000000 --- a/g4f/.v1/gpt4free/quora/tests/test_api.py +++ /dev/null @@ -1,38 +0,0 @@ -import unittest -import requests -from unittest.mock import MagicMock -from gpt4free.quora.api import retry_request - - -class TestRetryRequest(unittest.TestCase): - def test_successful_request(self): - # Mock a successful request with a 200 status code - mock_response = MagicMock() - mock_response.status_code = 200 - requests.get = MagicMock(return_value=mock_response) - - # Call the function and assert that it returns the response - response = retry_request(requests.get, "http://example.com", max_attempts=3) - self.assertEqual(response.status_code, 200) - - def test_exponential_backoff(self): - # Mock a failed request that succeeds after two retries - mock_response = MagicMock() - mock_response.status_code = 200 - requests.get = MagicMock(side_effect=[requests.exceptions.RequestException] * 2 + [mock_response]) - - # Call the function and assert that it retries with exponential backoff - with self.assertLogs() as logs: - response = retry_request(requests.get, "http://example.com", max_attempts=3, delay=1) - self.assertEqual(response.status_code, 200) - self.assertGreaterEqual(len(logs.output), 2) - self.assertIn("Retrying in 1 seconds...", logs.output[0]) - self.assertIn("Retrying in 2 seconds...", logs.output[1]) - - def test_too_many_attempts(self): - # Mock a failed request that never succeeds - requests.get = MagicMock(side_effect=requests.exceptions.RequestException) - - # Call the function and assert that it raises an exception after the maximum number of attempts - with self.assertRaises(RuntimeError): - retry_request(requests.get, "http://example.com", max_attempts=3) |