8000 Update for compatibility with flask v2.3.2 by dsakagi · Pull Request #153 · flask-api/flask-api · GitHub
[go: up one dir, main page]

Skip to content

Update for compatibility with flask v2.3.2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update for compatibility with flask v2.3.2
In version 2.3.0 of flask, the JSONEncoder class was removed and the
app.json_encoder attribute was removed. The result that a run of
the tests using flask==2.3.0 would fail. This change updates the
use of flask's json mechanisms to be in line with the new standard,
and similarly updates the tests to utilize those mechanisms correctly.
  • Loading branch information
dsakagi committed Jun 2, 2023
commit 67d798e65cc9b50cd2a37a39622eacadc5456695
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
global:
- RANDOM_SEED=0
matrix:
- FLASK_VERSION=2.0.1
- FLASK_VERSION=2.3.2

before_install:
- pip install pipenv
Expand Down
4 changes: 2 additions & 2 deletions flask_api/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def render(self, data, media_type, **options):
indent = None
# Indent may be set explicitly, eg when rendered by the browsable API.
indent = options.get("indent", indent)
return json.dumps(
data, cls=current_app.json_encoder, ensure_ascii=False, indent=indent
return current_app.json.dumps(
data, ensure_ascii=False, indent=indent
)


Expand Down
6 changes: 3 additions & 3 deletions flask_api/tests/test_renderers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from datetime import datetime

from flask.json import JSONEncoder
from flask.json.provider import DefaultJSONProvider

from flask_api import FlaskAPI, renderers, status
from flask_api.decorators import set_renderers
Expand Down Expand Up @@ -39,14 +39,14 @@ def test_render_json_with_indent(self):
self.assertEqual(content, expected)

def test_render_json_with_custom_encoder(self):
class CustomJsonEncoder(JSONEncoder):
class CustomJsonProvider(DefaultJSONProvider):
def default(self, o):
if isinstance(o, datetime):
return o.isoformat()
return super().default(o)

app = self._make_app()
app.json_encoder = CustomJsonEncoder
app.json = CustomJsonProvider(app)
renderer = renderers.JSONRenderer()
date = datetime(2017, 10, 5, 15, 22)
with app.app_context():
Expand Down
0