-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let the user choose a custom json serializer through the RESTPLUS_JSO…
…N_SERIALIZER config option
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ pytest-mock==1.6.3 | |
pytest-profiling==1.2.11 | ||
pytest-sugar==0.9.0 | ||
tzlocal | ||
ujson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import flask_restplus.representations as rep | ||
|
||
from json import dumps, loads | ||
from ujson import dumps as udumps, loads as uloads | ||
|
||
from flask import current_app | ||
|
||
|
||
def test_representations(api): | ||
payload = { | ||
'id': 1, | ||
'name': 'toto', | ||
'address': 'test', | ||
} | ||
r = rep.output_json(payload, 200) | ||
assert loads(r.get_data(True)) == loads(dumps(payload)) | ||
# now reset serializer | ||
rep.serializer = None | ||
# then enforce a custom serializer | ||
current_app.config['RESTPLUS_JSON_SERIALIZER'] = 'ujson' | ||
r2 = rep.output_json(payload, 200) | ||
assert uloads(r2.get_data(True)) == uloads(udumps(payload)) |