| 92 | |
| 93 | |
| 94 | def test_provide_automatic_options_kwarg(app, client): |
| 95 | def index(): |
| 96 | return flask.request.method |
| 97 | |
| 98 | def more(): |
| 99 | return flask.request.method |
| 100 | |
| 101 | app.add_url_rule("/", view_func=index, provide_automatic_options=False) |
| 102 | app.add_url_rule( |
| 103 | "/more", |
| 104 | view_func=more, |
| 105 | methods=["GET", "POST"], |
| 106 | provide_automatic_options=False, |
| 107 | ) |
| 108 | assert client.get("/").data == b"GET" |
| 109 | |
| 110 | rv = client.post("/") |
| 111 | assert rv.status_code == 405 |
| 112 | assert sorted(rv.allow) == ["GET", "HEAD"] |
| 113 | |
| 114 | rv = client.open("/", method="OPTIONS") |
| 115 | assert rv.status_code == 405 |
| 116 | |
| 117 | rv = client.head("/") |
| 118 | assert rv.status_code == 200 |
| 119 | assert not rv.data # head truncates |
| 120 | assert client.post("/more").data == b"POST" |
| 121 | assert client.get("/more").data == b"GET" |
| 122 | |
| 123 | rv = client.delete("/more") |
| 124 | assert rv.status_code == 405 |
| 125 | assert sorted(rv.allow) == ["GET", "HEAD", "POST"] |
| 126 | |
| 127 | rv = client.open("/more", method="OPTIONS") |
| 128 | assert rv.status_code == 405 |
| 129 | |
| 130 | |
| 131 | def test_request_dispatching(app, client): |