Skip to content

Commit 2f53151

Browse files
diasriniva
andauthored
Updates from v1.5.0 and v1.6.0 (#82)
* Version 1.5.0 (#69) * Revert "Version 2.0.0 (#67)" This reverts commit f2471b4. * Revert "Add Cloud Events support for #55 (#56) (#64)" This reverts commit 8f3fe35. * Version 1.5.0 * Add legacy GCF Python 3.7 behavior (#77) * Add legacy GCF Python 3.7 behavior * Add test * Modify tests * Version 1.6.0 (#81) Co-authored-by: Arjun Srinivasan <[email protected]>
1 parent 6c91563 commit 2f53151

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313
- Support `cloudevent` signature type ([#55], [#56])
1414

15+
## [1.6.0] - 2020-08-19
16+
### Changed
17+
- Add legacy GCF Python 3.7 behavior ([#77])
18+
19+
### Added
20+
- Improve documentation around Dockerfiles ([#70])
21+
22+
## [1.5.0] - 2020-07-06
1523
### Changed
1624
- Framework will consume entire request before responding ([#66])
1725

@@ -74,6 +82,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7482

7583
[Unreleased]: https://github.com/GoogleCloudPlatform/functions-framework-python/compare/v2.0.0...HEAD
7684
[2.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v2.0.0
85+
[1.6.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.6.0
86+
[1.5.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.5.0
7787
[1.4.4]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.4.4
7888
[1.4.3]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.4.3
7989
[1.4.2]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.4.2
@@ -86,7 +96,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8696
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
8797
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0
8898

99+
[#77]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/77
89100
[#76]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/76
101+
[#70]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/70
90102
[#66]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/66
91103
[#61]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/61
92104
[#56]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/56

src/functions_framework/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ def create_app(target=None, source=None, signature_type=None):
233233
with app.app_context():
234234
spec.loader.exec_module(source_module)
235235

236+
# Handle legacy GCF Python 3.7 behavior
237+
if os.environ.get("ENTRY_POINT"):
238+
os.environ["FUNCTION_TRIGGER_TYPE"] = signature_type
239+
os.environ["FUNCTION_NAME"] = os.environ.get("K_SERVICE", target)
240+
app.make_response_original = app.make_response
241+
242+
def handle_none(rv):
243+
if rv is None:
244+
rv = "OK"
245+
return app.make_response_original(rv)
246+
247+
app.make_response = handle_none
248+
236249
# Extract the target function from the source file
237250
try:
238251
function = getattr(source_module, target)

tests/test_functions.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
import os
1416
import pathlib
1517
import re
1618
import time
@@ -318,3 +320,42 @@ def test_flask_current_app_is_available():
318320
resp = client.get("/")
319321

320322
assert resp.status_code == 200
323+
324+
325+
def test_function_returns_none():
326+
source = TEST_FUNCTIONS_DIR / "returns_none" / "main.py"
327+
target = "function"
328+
329+
client = create_app(target, source).test_client()
330+
resp = client.get("/")
331+
332+
assert resp.status_code == 500
333+
334+
335+
def test_legacy_function_check_env(monkeypatch):
336+
source = TEST_FUNCTIONS_DIR / "http_check_env" / "main.py"
337+
target = "function"
338+
339+
monkeypatch.setenv("ENTRY_POINT", target)
340+
341+
client = create_app(target, source).test_client()
342+
resp = client.post("/", json={"mode": "FUNCTION_TRIGGER_TYPE"})
343+
assert resp.status_code == 200
344+
assert resp.data == b"http"
345+
346+
resp = client.post("/", json={"mode": "FUNCTION_NAME"})
347+
assert resp.status_code == 200
348+
assert resp.data.decode("utf-8") == target
349+
350+
351+
def test_legacy_function_returns_none(monkeypatch):
352+
source = TEST_FUNCTIONS_DIR / "returns_none" / "main.py"
353+
target = "function"
354+
355+
monkeypatch.setenv("ENTRY_POINT", target)
356+
357+
client = create_app(target, source).test_client()
358+
resp = client.get("/")
359+
360+
assert resp.status_code == 200
361+
assert resp.data == b"OK"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def function(request):
17+
"""Test HTTP function when using legacy GCF behavior.
18+
19+
The function returns None, which should be a 200 response.
20+
21+
Args:
22+
request: The HTTP request which triggered this function.
23+
24+
Returns:
25+
None.
26+
"""
27+
return None

0 commit comments

Comments
 (0)