aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-04-02 21:49:24 +0100
committerGravatar Chris Lovering <[email protected]>2022-04-02 21:56:18 +0100
commit50fab95a8e87dd1bf293e3503d82533d26c43b41 (patch)
treea490bad5ea678e29330a3321fc8d529d4deb8a38 /tests
parentMerge pull request #50 from python-discord/update-all-deps (diff)
Migrate site_api tests from bot
Co-authored-by: Joe Banks <[email protected]> Co-authored-by: Mark <[email protected]> Co-authored-by: Sebastiaan Zeeff <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/botcore/test_api.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/botcore/test_api.py b/tests/botcore/test_api.py
new file mode 100644
index 00000000..86c9e5f3
--- /dev/null
+++ b/tests/botcore/test_api.py
@@ -0,0 +1,69 @@
+import unittest
+from unittest.mock import MagicMock
+
+from botcore import site_api
+
+
+class APIClientTests(unittest.IsolatedAsyncioTestCase):
+ """Tests for botcore's site API client."""
+
+ @classmethod
+ def setUpClass(cls):
+ """Sets up the shared fixtures for the tests."""
+ cls.error_api_response = MagicMock()
+ cls.error_api_response.status = 999
+
+ def test_response_code_error_default_initialization(self):
+ """Test the default initialization of `ResponseCodeError` without `text` or `json`"""
+ error = site_api.ResponseCodeError(response=self.error_api_response)
+
+ self.assertIs(error.status, self.error_api_response.status)
+ self.assertEqual(error.response_json, {})
+ self.assertEqual(error.response_text, None)
+ self.assertIs(error.response, self.error_api_response)
+
+ def test_response_code_error_string_representation_default_initialization(self):
+ """Test the string representation of `ResponseCodeError` initialized without text or json."""
+ error = site_api.ResponseCodeError(response=self.error_api_response)
+ self.assertEqual(
+ str(error),
+ f"Status: {self.error_api_response.status} Response: {None}"
+ )
+
+ def test_response_code_error_initialization_with_json(self):
+ """Test the initialization of `ResponseCodeError` with json."""
+ json_data = {'hello': 'world'}
+ error = site_api.ResponseCodeError(
+ response=self.error_api_response,
+ response_json=json_data,
+ )
+ self.assertEqual(error.response_json, json_data)
+ self.assertEqual(error.response_text, None)
+
+ def test_response_code_error_string_representation_with_nonempty_response_json(self):
+ """Test the string representation of `ResponseCodeError` initialized with json."""
+ json_data = {'hello': 'world'}
+ error = site_api.ResponseCodeError(
+ response=self.error_api_response,
+ response_json=json_data
+ )
+ self.assertEqual(str(error), f"Status: {self.error_api_response.status} Response: {json_data}")
+
+ def test_response_code_error_initialization_with_text(self):
+ """Test the initialization of `ResponseCodeError` with text."""
+ text_data = 'Lemon will eat your soul'
+ error = site_api.ResponseCodeError(
+ response=self.error_api_response,
+ response_text=text_data,
+ )
+ self.assertEqual(error.response_text, text_data)
+ self.assertEqual(error.response_json, {})
+
+ def test_response_code_error_string_representation_with_nonempty_response_text(self):
+ """Test the string representation of `ResponseCodeError` initialized with text."""
+ text_data = 'Lemon will eat your soul'
+ error = site_api.ResponseCodeError(
+ response=self.error_api_response,
+ response_text=text_data
+ )
+ self.assertEqual(str(error), f"Status: {self.error_api_response.status} Response: {text_data}")