Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbf20f1

Browse files
Ace Nassribusunkim96
Ace Nassri
authored andcommitted
Add missing tests for functions/http (GoogleCloudPlatform#2560)
1 parent 8d17455 commit bbf20f1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

functions/http/main_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import flask
1616
import pytest
17+
import os
1718

1819
import main
1920

@@ -24,6 +25,41 @@ def app():
2425
return flask.Flask(__name__)
2526

2627

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+
2763
def test_cors_enabled_function_preflight(app):
2864
with app.test_request_context(method='OPTIONS'):
2965
res = main.cors_enabled_function(flask.request)

0 commit comments

Comments
 (0)