1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
Description: Fix for errors with Python 3.12 and Flask 3.0.
Fix for AttributeError in test with Python 3.12 + removed deprecated
signals_available.
Author: Yogeswaran Umasankar <kd8mbd@gmail.com>
Last-Update: 2024-02-12
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -1,7 +1,7 @@
import unittest
import json
from flask import Flask, Blueprint, redirect, views, abort as flask_abort
-from flask.signals import got_request_exception, signals_available
+from flask.signals import got_request_exception
try:
from mock import Mock
except:
@@ -491,10 +491,6 @@ class APITestCase(unittest.TestCase):
self.assertEqual(api.default_mediatype, resp.headers['Content-Type'])
def test_handle_error_signal(self):
- if not signals_available:
- # This test requires the blinker lib to run.
- print("Can't test signals without signal support")
- return
app = Flask(__name__)
api = flask_restful.Api(app)
@@ -531,15 +527,14 @@ class APITestCase(unittest.TestCase):
"""
app = Flask(__name__)
api = flask_restful.Api(app)
- app.handle_exception = Mock()
+ original_handle_exception = app.handle_exception
api.handle_error = Mock(side_effect=Exception())
api._has_fr_route = Mock(return_value=True)
exception = Mock(spec=HTTPException)
with app.test_request_context('/foo'):
- api.error_router(exception, app.handle_exception)
-
- self.assertTrue(app.handle_exception.called_with(exception))
+ original_handle_exception(exception)
+ api.handle_error.assert_called_once_with(exception)
def test_media_types(self):
app = Flask(__name__)
|