14
14
15
15
import flask
16
16
import pytest
17
+ import os
17
18
18
19
import main
19
20
@@ -24,6 +25,41 @@ def app():
24
25
return flask .Flask (__name__ )
25
26
26
27
28
+ def test_parse_xml (app ):
29
+ with app .test_request_context (method = 'GET' , data = "<baz>foo</baz>" ):
30
+ res = main .parse_xml (flask .request )
31
+ assert res == "{\n \" baz\" : \" foo\" \n }"
32
+
33
+
34
+ def test_parse_multipart_data (app , capsys ):
35
+ with app .test_request_context (method = 'POST' , data = {'foo' : 'bar' }):
36
+ res = main .parse_multipart (flask .request )
37
+ out , _ = capsys .readouterr ()
38
+ assert res == 'Done!'
39
+ assert out == 'Processed field: foo\n '
40
+
41
+
42
+ def test_parse_multipart_files (app , capsys ):
43
+ with open (__file__ , 'rb' ) as file :
44
+ with app .test_request_context (method = 'POST' , data = {'test.py' : file }):
45
+ res = main .parse_multipart (flask .request )
46
+ out , _ = capsys .readouterr ()
47
+ assert res == 'Done!'
48
+ assert out == 'Processed file: test.py\n '
49
+
50
+
51
+ def test_get_signed_url (app , capsys ):
52
+ json = {
53
+ 'bucket' : os .getenv ('GCLOUD_PROJECT' ),
54
+ 'filename' : 'test.txt' ,
55
+ 'contentType' : 'text/plain'
56
+ }
57
+
58
+ with app .test_request_context (method = 'POST' , json = json ):
59
+ url = main .get_signed_url (flask .request )
60
+ assert 'https://storage.googleapis.com/' in url
61
+
62
+
27
63
def test_cors_enabled_function_preflight (app ):
28
64
with app .test_request_context (method = 'OPTIONS' ):
29
65
res = main .cors_enabled_function (flask .request )
0 commit comments