8000 Added unit tests for changes in Parsers and Request · flask-api/flask-api@6dcb9dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 6dcb9dd

Browse files
coddersauvipy
authored andcommitted
Added unit tests for changes in Parsers and Request
1 parent 9c99889 commit 6dcb9dd

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

flask_api/tests/test_parsers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def test_valid_json(self):
3131
data = parser.parse(stream, "application/json")
3232
self.assertEqual(data, {"key": 1, "other": "two"})
3333

34+
def test_parse_urlencoded(self):
35+
parser = parsers.URLEncodedParser()
36+
stream = io.BytesIO(b'next=http://www.example.com&test1=val1&test%5c=val%2f')
37+
data = parser.parse(stream, "application/x-www-form-urlencoded")
38+
self.assertEqual(data, {"next": "http://www.example.com", "test1": "val1", "test\\": "val/"})
39+
3440
def test_invalid_json(self):
3541
parser = parsers.JSONParser()
3642
stream = io.BytesIO(b'{key: 1, "other": "two"}')

flask_api/tests/test_request.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ def test_json_request(self):
1919
with app.test_request_context(**kwargs):
2020
self.assertEqual(request.data, {"key": 1, "other": "two"})
2121

22+
def test_urlencoded_post_request(self):
23+
kwargs = {
24+
"method": "POST",
25+
"input_stream": io.BytesIO(b'next=http://www.example.com&test1=val1&test%5c=val%2f'),
26+
"content_type": "application/x-www-form-urlencoded",
27+
}
28+
with app.test_request_context(**kwargs):
29+
self.assertEqual(request.data, {"next": "http://www.example.com", "test1": "val1", "test\\": "val/"})
30+
2231
def test_invalid_content_type_request(self):
2332
kwargs = {
2433
"method": "PUT",

0 commit comments

Comments
 (0)
0