Commit Graph

138 Commits

Author SHA1 Message Date
David Lord 1351d0a565
Merge branch '1.0.x' 2019-06-23 16:57:52 -07:00
David Lord e666f7a69c
standardize license and copyright 2019-06-22 13:09:09 -07:00
Elad Moshe 1ff98a2d21
wait until app ctx is ready before matching url
`RequestContext.match_request` is moved from `__init__` to `push`. This
causes matching to happen later, when the app context is available.
This enables URL converters that use things such as the database.
2019-06-13 08:32:23 -07:00
David Lord 29111a3259
Merge branch '1.0.x' 2019-06-12 10:41:11 -07:00
David Lord dbd4520ccb
fix tests failing with server name warnings
After pallets/werkzeug#1577, mismatched configured and real server
names will show a warning in addition to raising 404. This caused
tests that did this deliberately to fail.

This patch removes the pytest fixture we were using to fail on
warnings, instead using the standard `-Werror` option. This speeds
up the tests by ~3x.
2019-06-10 14:05:33 -07:00
David Lord 53c893b646
fix string concats left over by black 2019-06-01 09:22:20 -07:00
David Lord 43483683b2
apply reorder-python-imports pre-commit config 2019-06-01 09:07:20 -07:00
Jon S. Stumpf b46f5942a5
address flake8 issues 2019-06-01 06:31:35 -07:00
John Zeringue 8bb7185284 Better error message when view return type is not supported
Before, returning a `bool` from a route caused the error

```
[2019-05-31 10:08:42,216] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2070, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 26, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
    app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2393, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1906, in full_dispatch_request
    return self.finalize_request(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1921, in finalize_request
    response = self.make_response(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2078, in make_response
    reraise(TypeError, new_error, sys.exc_info()[2])
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/_compat.py", line 39, in reraise
    raise value.with_traceback(tb)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2070, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 26, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
    app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a bool.
```

Now, it returns the more readable

```
[2019-05-31 10:36:19,500] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2400, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1907, in full_dispatch_request
    return self.finalize_request(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1922, in finalize_request
    response = self.make_response(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2085, in make_response
    " {rv.__class__.__name__}.".format(rv=rv))
TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a bool.
```

Fixes #3214
2019-05-31 11:58:49 -04:00
Daniel Pope a5ff3cd01b Fix style issues on master using Black 2019-05-31 11:57:28 +01:00
David Lord ed9ab2d3b6
strip static url trailing slash at assignment 2019-05-25 11:18:40 -07:00
Pete Beardmore a12bf290da
fix 'static_url_path' defaulting for empty paths
-prefix a path delimiter iff there's a path to delimit
-ensures a valid default static route rule is created on application
intialisation for the case 'static_folder=""' and implicit
'static_url_path'
2019-05-25 07:03:36 -07:00
pgjones 7bf8366970
Allow dictionary return values as JSON
This supports an increasingly common usecase whereby JSON is the
primary response (rather than a templated string). Given Flask has a
short syntax for HTML reponses, it seems fitting that it should also
do so for JSON responses. In practice it allows,

     @app.route("/")
     def index():
         return {
             "api_stuff": "values",
         }
2019-05-24 09:48:55 -07:00
vorelq e1cc16f8be
Fix 0 port value being overriden by default
By explicitly comparing port value with None,
instead of using its bool() value.
2019-05-19 11:36:47 -07:00
Eruvanos 6af14f058b
support dataclass in JSONEncoder 2019-05-18 21:37:54 -07:00
Frankie Liu 2039e2e3b6
Remove ending slash from static_url_path 2019-05-18 21:23:14 -07:00
David Baumgold 025589ee76 Reformat with black
https://github.com/python/black
2019-05-06 16:28:58 -04:00
David Lord 49efc44233
clear KeyError in production for Werkzeug 0.15 2019-01-05 12:49:59 -08:00
David Lord b573a86977
trap key errors in debug, not all 400 errors 2018-04-28 06:51:08 -07:00
David Lord 1ed756a523
add Response.max_cookie_size config 2018-04-10 11:17:18 -07:00
David Lord 82f0d120de
use subdomain arg in url_map.bind_to_environ
rename new subdomain test, parametrize
test allowing subdomains as well as ips
add subdomain_matching param to docs
add some references to docs
add version changed to create_url_adapter
2018-02-23 08:39:31 -08:00
Armin Ronacher 8cec2010c0
Do not enable subdomain matching by default
Updated tests for new subdomain matching
Added a test to validate matching behavior
2018-02-23 07:53:27 -08:00
David Lord 310fbfcf64
revert copyright year to project start
add copyright header to files
2018-02-08 12:43:30 -08:00
David Lord 382b13581e
clean up samesite docs 2018-01-23 15:11:50 -08:00
Fadhel_Chaabane a1d9ebe4ab New Feature: Added Support for cookie's SameSite attribute. 2018-01-23 13:57:50 +00:00
David Lord 0a33954555
improve documentation for session attributes
add test for session attributes
2018-01-04 12:56:18 -08:00
David Lord 66b1b752da
simplify logging configuration
single default handler and formatter
don't remove handlers
configure level once using setLevel
document logging
reorganize logging tests
2017-07-31 12:49:03 -07:00
William Horton 5909e26fba Remove unused import from test_basic (#2403) 2017-06-30 17:28:48 +02:00
David Lord 465922e5f1
clean up secret key docs
consistent key across docs and examples
consistent key across tests, set in conftest
2017-06-28 07:58:06 -07:00
David Lord d63c2bc417
remove deprecated Flask.static_path 2017-06-26 07:45:29 -07:00
David Lord 5c12acefbb
failing test 2017-06-05 06:14:13 -07:00
David Lord fd8b95952c
add tests for flask.json.tag 2017-06-02 10:01:30 -07:00
David Lord ea2e9609bc
Merge branch 'master' into json-object-hook 2017-06-01 06:40:27 -07:00
David Lord 859d9a9d5c
show nice message when registering error handler for unknown code
clean up error handler docs
closes #1837
2017-05-31 18:04:08 -07:00
David Lord 42905b8a55
set description for trap as well as debug
test for key error description
2017-05-29 19:41:07 -07:00
David Lord b8eba0a3fa
use existing response.vary property to set vary header
closes #2345
2017-05-29 10:09:24 -07:00
Kenneth Reitz d911c897ee Merge branch 'master' into master 2017-05-25 14:22:53 -07:00
Nina Zakharenko e7cd68ba58 Don't overwrite Vary header when setting for cookie access #2317 2017-05-24 20:05:11 -07:00
Christian Stade-Schuldt 4ec1fbc9f5 More DRYing up the test suite (#2325) 2017-05-24 17:27:36 -07:00
Christian Stade-Schuldt 5b0b9717da DRYing up the test suite using pytest fixtures (#2306)
* add fixtures to conftest.py

* use fixtures in test_appctx.py

* use fixtures in test_blueprints.py

* use fixtures in test_depreciations.py

* use fixtures in test_regressions.py

* use fixtures in test_reqctx.py

* use fixtures in test_templating.py

* use fixtures in test_user_error_handler.py

* use fixtures in test_views.py

* use fixtures in test_basics.py

* use fixtures in test_helpers.py

* use fixtures in test_testing.py

* update conftest.py

* make docstrings  PEP-257 compliant

* cleanup

* switch dictonary format

* use pytest parameterization for test_json_as_unicode
2017-05-23 15:18:39 -07:00
David Lord 5d9dd0b379
set session accessed for setdefault 2017-05-20 13:00:17 -07:00
David Lord e2f4c0ac16
Merge branch 'master' into vary-cookies 2017-05-19 09:44:06 -07:00
David Lord f75ad9fca2
refactor session cookie domain logic
cache result of session cookie domain
add warnings for session cookie domain issues
add changelog
2017-05-13 21:59:00 -07:00
David Lord 697f7b9365
refactor make_response to be easier to follow
* be explicit about how tuples are unpacked
* allow bytes for status value
* allow Headers for headers value
* use TypeError instead of ValueError
* errors are more descriptive
* document that view must not return None
* update documentation about return values
* test more response types
* test error messages

closes #1676
2017-04-25 08:30:48 -07:00
David Lord 97e2cd0a5a
update changelog
move test next to existing test, rename
reword / reflow param doc
2017-04-21 07:26:30 -07:00
David Lord 8ad4f476aa
Merge branch 'master' into jrmccarthy-master 2017-04-21 07:03:46 -07:00
David Lord e50767cfca
add test for build error special values 2017-04-20 08:52:37 -07:00
jab 00d6e339ec Change Flask.__init__ to accept two new keyword arguments, host_matching and static_host. (#1560)
This enables host_matching to be set properly by the time the constructor adds
the static route, and enables the static route to be properly associated with
the required host.

Previously, you could only enable host_matching once your app was already
instantiated (e.g. app.url_map.host_matching = True), but at that point
the constructor would have already added the static route without host matching
and an associated host, leaving the static route in a broken state.

Fixes #1559.
2017-04-07 16:31:54 +02:00
Markus Unterwaditzer de555c82ce Merge branch '0.12-maintenance' 2017-03-31 18:44:33 +02:00
Markus Unterwaditzer c935eaceaf Revert "Handle BaseExceptions (#2222)"
This reverts commit 1d4448abe3.
2017-03-31 18:44:14 +02:00
Diggory Blake 6f7847e3c4 Make test more idiomatic 2017-03-31 18:40:46 +02:00
Diggory Blake d0e2e7b66c Add test and changes 2017-03-31 18:40:46 +02:00
Diggory Blake 1d4448abe3 Handle BaseExceptions (#2222)
* Handle BaseExceptions

* Add test and changes

* Make test more idiomatic
2017-03-31 18:07:43 +02:00
Hsiaoming Yang a7f1a21c12 Don't rely on X-Requested-With for pretty print json response (#2193)
* Don't rely on X-Requested-With for pretty print json response

* Fix test cases for pretty print json patch

* Fix gramma error in docs for pretty print json config

* Add changelog for JSONIFY_PRETTYPRINT_REGULAR
2017-03-07 10:09:46 +09:00
Josh Rowe 8a8a608152 Move object_hook outside loads method so class can be extend and reused 2017-02-23 15:25:52 +00:00
David Lord 42fbbb4cbb
add test and changelog for SERVER_NAME app.run default
ref #2152
2017-01-17 14:08:33 -08:00
Andrew Arendt 01b992b1a1 Added python3.6 support for tests 2017-01-10 11:20:53 -06:00
Armin Ronacher 9cd32cac32 Corrected after response for error handlers
Before this change after request functions were not correctly
invoked for error handlers.
2016-09-08 11:56:02 +03:00
Markus Unterwaditzer c4ec6954e5 Don't passthrough_errors unless instructed. (#2006)
Fix #2005

Revert #1679 and #1996
2016-09-06 22:32:34 +02:00
Markus Unterwaditzer 098ea0c8ca Only passthrough_errors if PROPAGATE_EXCEPTIONS
See pallets/werkzeug#954
2016-08-27 14:38:13 +02:00
dawran6 e048aa4e19 Add negative test for json.jsonify (#1876)
Test if jsonify function raises TypeError when both args and kwargs are
passed in.
Check the TypeError's message
2016-06-03 10:58:39 -07:00
Markus Unterwaditzer 6c359e0f53 Eliminate some resource warnings 2016-06-03 14:29:27 +02:00
Markus Unterwaditzer d393597c50 Use recwarn everywhere
...instead of custom fixture. Also assert that no warnings are left over
after the test.
2016-06-03 13:59:47 +02:00
jphilipsen05 047efac537 Coverage for test_static_path_deprecated and test_static_url_path (#1860) 2016-06-02 17:56:08 -07:00
Steven Loria 2bf477cfea Add JSONIFY_MIMETYPE configuration variable (#1728)
Allow jsonify responses' mimetype to be configured
2016-04-08 15:30:47 -07:00
Reuven 4dc2ef19ea Use pytest.raises() instead of try/catch with asser 0
This is somehow more readable, and enable using the features of pytest's ExeptionInfo (such as errisinstance).
2016-03-04 13:30:40 +02:00
Miguel Grinberg 952a6c8989 Werkzeug should not block propagated exceptions from Flask 2016-01-02 14:18:36 -08:00
Jimmy McCarthy 04a3eeee3b Merge branch 'master' of github.com:mitsuhiko/flask 2015-09-14 13:06:54 -05:00
Markus Unterwaditzer 81ae94a5fd Merge branch '0.10-maintenance' 2015-07-16 12:05:07 +02:00
Jimmy McCarthy 011b129b6b Add kwarg to disable auto OPTIONS on add_url_rule
Adds support for a kwarg `provide_automatic_options` on `add_url_rule`, which
lets you turn off the automatic OPTIONS response on a per-URL basis even if
your view functions are functions, not classes (so you can't provide attrs
on them).
2015-07-07 13:20:53 -05:00
Brandon Sandrowicz 20f62e828b Fix Possible Typo
Looks like that was meant to be `config_key`. It works by accident because the function is defined in the same scope as the look that passes `config_key` to `apprunner`.
2015-04-02 01:48:48 +02:00
Markus Unterwaditzer 1577e1386e Revert "Don't use threads in this test"
This reverts commit 78cd4161f0.
2015-03-29 23:03:38 +02:00
Markus Unterwaditzer 78cd4161f0 Don't use threads in this test
I think test failures would've been ignored if there were some.

Fixes #1401
2015-03-29 13:40:35 +02:00
Chris Rebert 6d2c076a3b make test_request_preprocessing_early_return more thorough 2015-02-06 13:11:23 -08:00
Markus Unterwaditzer 1158e22958 Fix test under Python 3 2015-02-06 18:20:17 +01:00
Markus Unterwaditzer 5fa76f6800 Add testcase for behavior described in #1338 2015-02-05 22:13:19 +01:00
Parkayun 33534bb4a9 Happy New Year 2015 2015-01-02 11:35:00 +09:00
Michael Hall 98b155c65d Fixed #1288: app.add_url_rule() should look for OPTIONS methods in a case-insensitive manner 2014-12-26 08:58:35 -05:00
Marc Abramowitz d9402fc0c0 Make `jsonify` terminate responses with a newline
This came up in the context of
https://github.com/kennethreitz/httpbin/issues/168
2014-12-07 14:37:26 -08:00
Markus Unterwaditzer bd232e5c82 PEP8 2014-10-21 19:11:54 +02:00
Gilman Callsen d425279650 Improve compression by removing whitespace from separators when using jsonify() and JSONIFY_PRETTYPRINT_REGULAR is False.
Commit includes Changelog entry and two new tests in test_basic.py.
2014-10-21 19:11:06 +02:00
Paulo Bu 3f67fe94f1 Adds 2 tests for Flask.run method 2014-09-14 17:27:19 +02:00
Markus Unterwaditzer a4931ff3a7 Kill class in test_basic 2014-09-11 22:09:52 +02:00
Markus Unterwaditzer af4cb0ff2b Remove flask superclass 2014-09-11 22:09:51 +02:00
Markus Unterwaditzer af41dbe0c4 Remove useless classes 2014-09-11 22:09:51 +02:00
Markus Unterwaditzer 5da2c00419 Rewrite assertion methods 2014-09-11 22:09:51 +02:00
Markus Unterwaditzer 8fa5e32d9a Tests pass now. 2014-09-11 22:09:50 +02:00
Markus Unterwaditzer 961db8ad72 Made tests recognizable 2014-09-11 22:09:50 +02:00