33"""
44
55import unittest
6- from flask import Flask , Request , jsonify as _jsonify
6+ from flask import Flask , Request
77from werkzeug .test import EnvironBuilder
88
99from firebase_functions import core , https_fn
@@ -71,13 +71,14 @@ def func(_):
7171
7272 self .assertEqual ("world" , hello )
7373
74+
7475 def test_callable_encoding (self ):
7576 app = Flask (__name__ )
7677
7778 @https_fn .on_call ()
7879 def add (req : https_fn .CallableRequest [int ]):
7980 return req .data + 1
80-
81+
8182 with app .test_request_context ("/" ):
8283 environ = EnvironBuilder (
8384 method = "POST" ,
@@ -90,18 +91,23 @@ def add(req: https_fn.CallableRequest[int]):
9091 response = add (request )
9192 self .assertEqual (response .status_code , 200 )
9293 self .assertEqual (response .get_json (), { "result" : 2 })
93-
94+
95+
9496 def test_callable_errors (self ):
9597 app = Flask (__name__ )
9698
9799 @https_fn .on_call ()
98100 def throw_generic_error (req ):
101+ # pylint: disable=broad-exception-raised
99102 raise Exception ("Invalid type" )
100103
101104 @https_fn .on_call ()
102105 def throw_access_denied (req ):
103- raise https_fn .HttpsError (https_fn .FunctionsErrorCode .PERMISSION_DENIED , "Permission is denied" )
104-
106+ raise https_fn .HttpsError (
107+ https_fn .FunctionsErrorCode .PERMISSION_DENIED ,
108+ "Permission is denied"
109+ )
110+
105111 with app .test_request_context ("/" ):
106112 environ = EnvironBuilder (
107113 method = "POST" ,
@@ -113,11 +119,18 @@ def throw_access_denied(req):
113119
114120 response = throw_generic_error (request )
115121 self .assertEqual (response .status_code , 500 )
116- self .assertEqual (response .get_json (), { "error" : { "message" : "INTERNAL" , "status" : "INTERNAL" } })
122+ self .assertEqual (response .get_json (), {
123+ "error" : { "message" : "INTERNAL" , "status" : "INTERNAL" }
124+ })
117125
118126 response = throw_access_denied (request )
119127 self .assertEqual (response .status_code , 403 )
120- self .assertEqual (response .get_json (), { "error" : { "message" : "Permission is denied" , "status" : "PERMISSION_DENIED" }})
128+ self .assertEqual (response .get_json (), {
129+ "error" : {
130+ "message" : "Permission is denied" ,
131+ "status" : "PERMISSION_DENIED"
132+ }
133+ })
121134
122135 def test_yielding_without_streaming (self ):
123136 app = Flask (__name__ )
@@ -130,7 +143,10 @@ def yielder(req: https_fn.CallableRequest[int]):
130143 @https_fn .on_call ()
131144 def yield_thrower (req : https_fn .CallableRequest [int ]):
132145 yield from range (req .data )
133- raise https_fn .HttpsError (https_fn .FunctionsErrorCode .PERMISSION_DENIED , "Can't read anymore" )
146+ raise https_fn .HttpsError (
147+ https_fn .FunctionsErrorCode .PERMISSION_DENIED ,
148+ "Can't read anymore"
149+ )
134150
135151 with app .test_request_context ("/" ):
136152 environ = EnvironBuilder (
@@ -158,7 +174,9 @@ def yield_thrower(req: https_fn.CallableRequest[int]):
158174 response = yield_thrower (request )
159175
160176 self .assertEqual (response .status_code , 403 )
161- self .assertEqual (response .get_json (), { "error" : { "message" : "Can't read anymore" , "status" : "PERMISSION_DENIED" }})
177+ self .assertEqual (response .get_json (), {
178+ "error" : { "message" : "Can't read anymore" , "status" : "PERMISSION_DENIED" }
179+ })
162180
163181
164182 def test_yielding_with_streaming (self ):
@@ -190,7 +208,12 @@ def yield_thrower(req: https_fn.CallableRequest[int]):
190208
191209 self .assertEqual (response .status_code , 200 )
192210 chunks = list (response .response )
193- self .assertEqual (chunks , ['data: {"message": 0}\n \n ' , 'data: {"message": 1}\n \n ' , 'data: {"result": "OK"}\n \n ' , "END" ])
211+ self .assertEqual (chunks , [
212+ 'data: {"message": 0}\n \n ' ,
213+ 'data: {"message": 1}\n \n ' ,
214+ 'data: {"result": "OK"}\n \n ' ,
215+ "END"
216+ ])
194217
195218 with app .test_request_context ("/" ):
196219 environ = EnvironBuilder (
@@ -208,4 +231,9 @@ def yield_thrower(req: https_fn.CallableRequest[int]):
208231
209232 self .assertEqual (response .status_code , 200 )
210233 chunks = list (response .response )
211- self .assertEqual (chunks , ['data: {"message": 0}\n \n ' , 'data: {"message": 1}\n \n ' , 'error: {"error": {"status": "INTERNAL", "message": "Throwing"}}\n \n ' , "END" ])
234+ self .assertEqual (chunks , [
235+ 'data: {"message": 0}\n \n ' ,
236+ 'data: {"message": 1}\n \n ' ,
237+ 'error: {"error": {"status": "INTERNAL", "message": "Throwing"}}\n \n ' ,
238+ "END"
239+ ])
0 commit comments