30 lines
880 B
Python
30 lines
880 B
Python
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()
|