Skip to content
Myr

Adds provide_automatic_options to Class-based Views

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by kaveh · committed by kaveh · parent c8e56d5 · Browse files · 2 files+41 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+41 added−0 removed

  • tests:+37 added−0 removed
  • other:+4 added−0 removed

2 files+41 added−0 removed

modified:flask/views.py+4 added
49 unmodified lines
5051 #: A list of methods this view can handle.52 methods = None5354 #: Setting this disables or force-enables the automatic options handling.55 provide_automatic_options = None5657 #: The canonical way to decorate class-based views is to decorate the58 #: return value of as_view(). However since this moves parts of the59 #: logic from the class declaration to the place where it's hooked60 #: into the routing system.
40 unmodified lines
101 view.__name__ = name102 view.__doc__ = cls.__doc__103 view.__module__ = cls.__module__104 view.methods = cls.methods105 view.provide_automatic_options = cls.provide_automatic_options106 return view107108109class MethodViewType(type):
48 unmodified lines
modified:tests/test_views.py+37 added
107 unmodified lines
108 rv = c.get('/')109 assert rv.headers['X-Parachute'] == 'awesome'110 assert rv.data == b'Awesome'111112def test_view_provide_automatic_options_attr():113 app = flask.Flask(__name__)114115 class Index1(flask.views.View):116 provide_automatic_options = False117 def dispatch_request(self):118 return 'Hello World!'119120 app.add_url_rule('/', view_func=Index1.as_view('index'))121 c = app.test_client()122 rv = c.open('/', method='OPTIONS')123 assert rv.status_code == 405124125 app = flask.Flask(__name__)126127 class Index2(flask.views.View):128 methods = ['OPTIONS']129 provide_automatic_options = True130 def dispatch_request(self):131 return 'Hello World!'132133 app.add_url_rule('/', view_func=Index2.as_view('index'))134 c = app.test_client()135 rv = c.open('/', method='OPTIONS')136 assert sorted(rv.allow) == ['OPTIONS']137138 app = flask.Flask(__name__)139140 class Index3(flask.views.View):141 def dispatch_request(self):142 return 'Hello World!'143144 app.add_url_rule('/', view_func=Index3.as_view('index'))145 c = app.test_client()146 rv = c.open('/', method='OPTIONS')147 assert 'OPTIONS' in rv.allow148149def test_implicit_head():150 app = flask.Flask(__name__)151152 class Index(flask.views.MethodView):
89 unmodified lines