Commit Graph

45 Commits

Author SHA1 Message Date
Sander Steffann
d71bd57b64 SchemaJSRenderer renders invalid Javascript (#5607)
* SchemaJSRenderer renders invalid Javascript

Under Py3 the base64.b64encode() method returns a binary object, which gets rendered as `b'...'` in schema.js. This results in the output becoming:

    var coreJSON = window.atob('b'eyJf...'');

which is invalid Javascript. Because base64 only uses ASCII characters it is safe to decode('ascii') it. Under Py2 this will result in a unicode object, which is fine. Under Py3 it results in a string, which is also fine. This solves the problem and results in a working schema.js output.

* Add regression test for #5608

* Add regression test for #5608

* Apparently the linter on Travis wants the imports in a different order than on my box...
2017-11-22 15:47:03 +01:00
Jon Dufresne
0552810410 Use dict and set literals instead of calls to dict() and set() (#5559)
Set literals are available on all supported Python versions. They are
idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop

$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop
2017-11-06 10:03:01 +01:00
Jon Dufresne
f77e794dc8 Fix all BytesWarning caught during tests (#5561)
Running the tests with bytes warning enabled shows some bytes/str
mixups. Fix them all.

Some examples of mixing usage:

str(b'foo') -- calling str() on bytes
b'foo' == 'foo' -- compare str with bytes
'foo' + b'bar' -- concatenating str and bytes
2017-11-06 10:02:48 +01:00
Carlton Gibson
dc4a98fbe8 Fix documentation data rendering (#5472)
* Add failing test for #5395

* Add data filter for use in templates

Closes #5395

* Fix isort
2017-10-02 13:26:44 +02:00
Ryan P Kilby
8ab75a2f01 Add 'STRICT_JSON' API setting.
STRICT_JSON controls the renderer & parser behavior on whether or not
to accept non-standard float values (NaN, Infinity).
2017-09-25 09:08:20 +02:00
Ryan P Kilby
d740bae95a Update json imports 2017-09-25 09:08:20 +02:00
Bekhzod Tillakhanov
84e22cc2f3 Scheme fix when unauth and Flask8 lint fix 2017-05-30 00:15:07 +05:00
José Padilla
c1f31492ae
Update links after moving to encode org 2017-04-07 10:28:35 -04:00
Tim Watts
8df340908b Add failing tests and fix for dict that have a key items #4931 (#4932) 2017-03-03 09:23:09 +00:00
Artem Muterko
b6b2c4bb5b Renderer tests (#4791) 2017-01-08 16:33:43 +00:00
Tom Christie
8105a4ac5a Resolve form display with ChoiceField, MultipleChoiceField and non-string choices. (#4374)
* Add tests for html-form-rendering choice fields
* Resolve issues with ChoiceField, MultipleChoiceField and non-string options
* Ensure None template comparisons don't match string None
2016-08-10 12:02:33 +01:00
Mads Jensen
6defb8da47 lookup_type is deprecated in favor of lookup_expr (#4259)
* lookup_type is deprecated in favor of lookup_expr
* assertEquals is deprecated in favor of assertEqual
* app_name is a required keyword as of Django 1.10
2016-07-13 14:40:42 +01:00
Tom Christie
994e1ba927 Django 1.10 support. (#4158)
* Added TEMPLATES setting to tests
* Remove deprecated view-string in URL conf
* Replace 'urls = ...' in test classes with override_settings('ROOT_URLCONF=...')
* Refactor UsingURLPatterns to use override_settings(ROOT_URLCONF=...) style
* Get model managers and names in a version-compatible manner.
* Apply override_settings to a TestCase, not a mixin class
* Use '.callback' property instead of private attributes when inspecting urlpatterns
* Pass 'user' to template explicitly
* Correct sorting of import statements.
* Remove unused TEMPLATE_LOADERS setting, in favor of TEMPLATES.
* Remove code style issue
* BaseFilter test requires a concrete model
* Resolve tox.ini issues
* Resolve isort differences between local and tox environments
2016-06-01 15:31:00 +01:00
Mikalay Radchuk
714607307e Fixes AttributeError in HTMLFormRenderer.render
If `HTMLFormRenderer.render` will be called with default arguments,
`AttributeError: 'NoneType' object has no attribute 'get'` will be raised.
2016-01-26 21:26:30 +03:00
Tom Christie
c64896c849 More cleanup of browser overrides 2015-09-28 15:33:55 +01:00
Carlton Gibson
45ace5010e Remove OrderedDict fallback 2015-09-22 16:35:38 +02:00
Tom Christie
c203ca4c64 Deprecations 2015-07-30 15:26:42 +01:00
José Padilla
7351a3f6ca Sort imports with isort 2015-06-25 16:55:51 -04:00
Xavier Ordoquy
9f1805f2f0 Removed unused imports. 2015-06-11 00:51:33 +02:00
Xavier Ordoquy
1e51230f1b Remove django.conf.urls.pattern as it'll be removed in Django 2.0 2015-06-11 00:45:23 +02:00
José Padilla
777f4e8212 Failing test for #2552 2015-02-19 12:23:44 -04:00
Tom Christie
fbb21caaaa Merge master 2015-02-09 20:43:50 +00:00
Tom Christie
b2939c157d Fixes for latest version of pep8 2015-02-09 17:43:20 +00:00
Tom Christie
39f26c9eca Merge master 2015-01-23 14:28:59 +00:00
Tom Christie
f3b6eedb8a More sensible response caching. 2015-01-23 12:56:55 +00:00
Tom Christie
4f3c3a06cf Drop trailing whitespace on indented JSON output. Closes #2429. 2015-01-19 14:41:10 +00:00
Tom Christie
baaa356489 Merge master 2014-12-12 15:37:43 +00:00
Tom Christie
65d6cba75f Merge pull request #2200 from maryokhin/master
Clean up compat code
2014-12-05 13:14:14 +00:00
Tymur Maryokhin
d54c67d79d Removed custom StringIO, force_text, smart_text compat 2014-12-04 03:11:42 +01:00
Tom Christie
3d6620c72a Merge 2014-12-03 23:24:06 +00:00
Tom Christie
f74e52b31e Merge 2014-12-03 23:14:58 +00:00
Tom Christie
23fa6e54ce Escape \u2028 and \u2029 in JSON output.
Closes #2169.
2014-12-03 22:33:34 +00:00
José Padilla
7f9dc73672 Remove XML support from core 2014-11-29 14:57:51 -04:00
José Padilla
fe745b9616 Remove JSONP support from core 2014-11-29 14:55:33 -04:00
José Padilla
731c8421af Remove YAML support from core 2014-11-29 14:43:05 -04:00
Xavier Ordoquy
767414439b Be nicer with __closable_objects. 2014-11-26 22:20:14 +01:00
Xavier Ordoquy
f5e5ed0077 Merge remote-tracking branch 'reference/master' into bugfix/1850 2014-11-26 16:36:56 +01:00
José Padilla
653d626b3c Fix failing YAML tests 2014-11-25 11:33:18 -04:00
Xavier Ordoquy
311d315a73 Reverted 59d0a0387d and fixed the tests 2014-10-08 08:33:28 +02:00
Tom Christie
5e39e159ee UNICODE_JSON and COMPACT_JSON settings 2014-09-12 11:38:22 +01:00
Tom Christie
63d02dbea8 Drop six from compat. 1.4.2 is now the lowest supported version. 2014-08-19 17:06:55 +01:00
Tom Christie
bf09c32de8 Code linting and added runtests.py 2014-08-19 13:28:07 +01:00
Xavier Ordoquy
7b4463f739 Merge remote-tracking branch 'reference/2.4.0' into feature/pytest
Conflicts:
	rest_framework/runtests/urls.py
	tests/test_response.py
	tox.ini
2014-05-01 08:01:38 +02:00
Xavier Ordoquy
1797a74e82 Merge remote-tracking branch 'pelme/pytest' into feature/pytest
Conflicts:
	.travis.yml
	rest_framework/runtests/runtests.py
	tests/test_filters.py
	tests/test_pagination.py
	tox.ini
2014-04-17 09:53:44 +02:00
Andreas Pelme
971578ca34 Support for running the test suite with py.test
* Get rid of runtests.py
 * Moved test code  from rest_framework/tests and rest_framework/runtests to tests
 * Invoke py.test from setup.py
 * Invoke py.test from Travis
 * Invoke py.test from tox
 * Changed setUpClass to be just plain setUp in test_permissions.py
 * Updated contribution guideline to show how to invoke py.test
2014-03-02 12:40:30 +01:00