forked from rhyselsmore/flask-modus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flask_modus.py
More file actions
53 lines (39 loc) · 1.28 KB
/
test_flask_modus.py
File metadata and controls
53 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from flask import Flask, request
from flask_modus import Modus
class MethodOverrideTestCase(unittest.TestCase):
def setUp(self):
""" Construct our Flask Test App """
def index():
return "get"
def put():
return "put"
self.app = Flask(__name__)
modus = Modus()
modus.init_app(self.app)
self.app.add_url_rule('/', 'index', index, methods=['GET'])
self.app.add_url_rule('/', 'put', put, methods=['PUT'])
self.client = self.app.test_client()
def test_get(self):
""" Test get """
assert "get" in self.client.get('/').data
def test_query_string(self):
""" Test put """
rv = self.client.put('/')
assert "put" in rv.data
rv = self.client.post('/?_method=put')
assert "put" in rv.data
with self.app.test_client() as c:
c.post('/?_method=put')
assert request.method == 'PUT'
def test_x_header(self):
with self.app.test_client() as c:
c.post(
'/',
headers=[('X-HTTP-Method-Override', 'put')]
)
assert request.method == 'PUT'
if __name__ == '__main__':
unittest.main()