Show full Wikipedia 429 error message
This commit is contained in:
parent
fd59e2a9a4
commit
3ba7eaefd0
3 changed files with 45 additions and 4 deletions
30
test_api.py
Normal file
30
test_api.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from simplejson.scanner import JSONDecodeError
|
||||
|
||||
from add_links import api
|
||||
|
||||
|
||||
class ApiGetTests(unittest.TestCase):
|
||||
def test_429_error_preserves_full_message(self) -> None:
|
||||
response = Mock()
|
||||
response.status_code = 429
|
||||
response.text = (
|
||||
"Too many requests. If you are a tool operator, contact "
|
||||
"noc@example.org for help."
|
||||
)
|
||||
response.json.side_effect = JSONDecodeError("bad json", "", 0)
|
||||
|
||||
session = Mock()
|
||||
session.get.return_value = response
|
||||
|
||||
with patch("add_links.api._get_active_session", return_value=session):
|
||||
with self.assertRaises(api.MediawikiError) as ctx:
|
||||
api.api_get({"action": "query"})
|
||||
|
||||
self.assertEqual(str(ctx.exception), response.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue