-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Cloud Events support for #55 #56
Merged
Merged
Changes from 18 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
86723ec
Ignore IDE files.
b0cd71a
Use the test file directory as a basis instead of cwd. Allows tests t…
joelgerard f1ebf4a
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
64d8e3d
Add support for Cloud Events. Rough draft.
joelgerard bbf6d35
Return the functions return value. Test Cloud Events SDK 0.3. Add som…
joelgerard 3bcb69d
Minor cleanup. Split test code.
joelgerard 42ea896
Clean up unused paths, split large test files into two, ensure functi…
joelgerard 4b3a10e
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
joelgerard a1dddbb
Fix lint errors with black.
joelgerard 4407259
Fix lint errors with black.
joelgerard 47acff6
Merge remote-tracking branch 'origin/master'
joelgerard d40f4a0
Update setup.py
joelgerard 1d83d3c
Update tests/test_cloudevent_functions.py
joelgerard 7c46f60
Update tests/test_cloudevent_functions.py
joelgerard 8832081
Update src/functions_framework/__init__.py
joelgerard 7a16331
Update tests/test_functions/cloudevents/main.py
joelgerard 16a6858
Clearer imports.
joelgerard bdbf5e2
don't factor out routes.
joelgerard ea2e28c
Add a TODO for testing the different combinations of events and signa…
joelgerard 9e8d874
Add cloudevent as a signature type in the argument list.
joelgerard 06ffc2d
Clarify import.
joelgerard ecb0b61
Clarify import.
joelgerard fa727f1
Merge remote-tracking branch 'origin/master'
joelgerard 209a8d6
A sample that shows how to use a CloudEvent.
joelgerard f573a1e
In the case of a sig type / event type mismatch throw a 400
joelgerard 7212640
Update the docs to use CloudEvent sig type instead of Event sig type.…
joelgerard 974d52b
Lint fixes.
joelgerard 9b87a6e
Tests for checking correct event type corresponds to correct function…
joelgerard 8d33033
Sort imports.
joelgerard c297097
Remove old example.
joelgerard 5176b8c
Readme to explain how to run the sample locally.
joelgerard f499790
Rename cloud_event to cloudevent
joelgerard 973beaf
For legacy docs, add a notice to the new docs.
joelgerard 30b9259
There is no 1.1 event type.
joelgerard 48e939e
remove uneeded git installation.
joelgerard 2532cec
use the term cloudevent rather than event everywhere where we are tal…
joelgerard 7928d5d
Update examples/cloudevents/README.md
joelgerard a38b480
Update examples/cloudevents/README.md
joelgerard 154de1c
Update examples/cloudevents/README.md
joelgerard 2a92d9c
Update examples/cloudevents/main.py
joelgerard a2b3c67
Update tests/test_view_functions.py
joelgerard dbc44a3
Add legacy event back to docs.
joelgerard eafa781
Add legacy event back to docs.
joelgerard 6ce6f63
Use abort from flask for consistency and fix return in event test.
joelgerard 18432e8
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
joelgerard c2ba64d
update docs and error messages to better mirror the other runtimes.
joelgerard 6889f54
Minor fixes to docs w.r.t. naming.
joelgerard 271e976
Update src/functions_framework/__init__.py
joelgerard 7cb1d88
Fix enum per reviewer suggestion.
joelgerard 2e34e8b
Rename text event => strucuture event.
joelgerard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,108 @@ | ||||||
# Copyright 2020 Google LLC | ||||||
# | ||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
# you may not use this file except in compliance with the License. | ||||||
# You may obtain a copy of the License at | ||||||
# | ||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||
# | ||||||
# Unless required by applicable law or agreed to in writing, software | ||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
import json | ||||||
import pathlib | ||||||
import pytest | ||||||
import cloudevents.sdk | ||||||
import cloudevents.sdk.event.v1 | ||||||
import cloudevents.sdk.event.v03 | ||||||
import cloudevents.sdk.marshaller | ||||||
|
||||||
from functions_framework import LazyWSGIApp, create_app, exceptions | ||||||
|
||||||
TEST_FUNCTIONS_DIR = pathlib.Path(__file__).resolve().parent / "test_functions" | ||||||
|
||||||
# Python 3.5: ModuleNotFoundError does not exist | ||||||
try: | ||||||
_ModuleNotFoundError = ModuleNotFoundError | ||||||
except: | ||||||
_ModuleNotFoundError = ImportError | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def event_1_10(): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
event = ( | ||||||
cloudevents.sdk.event.v1.Event() | ||||||
.SetContentType("application/json") | ||||||
.SetData('{"name":"john"}') | ||||||
.SetEventID("my-id") | ||||||
.SetSource("from-galaxy-far-far-away") | ||||||
.SetEventTime("tomorrow") | ||||||
.SetEventType("cloudevent.greet.you") | ||||||
) | ||||||
return event | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def event_0_3(): | ||||||
joelgerard marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
event = ( | ||||||
cloudevents.sdk.event.v03.Event() | ||||||
.SetContentType("application/json") | ||||||
.SetData('{"name":"john"}') | ||||||
.SetEventID("my-id") | ||||||
.SetSource("from-galaxy-far-far-away") | ||||||
.SetEventTime("tomorrow") | ||||||
.SetEventType("cloudevent.greet.you") | ||||||
) | ||||||
return event | ||||||
|
||||||
|
||||||
def test_event_1_0(event_1_10): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
source = TEST_FUNCTIONS_DIR / "cloudevents" / "main.py" | ||||||
target = "function" | ||||||
|
||||||
client = create_app(target, source, "cloudevent").test_client() | ||||||
|
||||||
m = cloudevents.sdk.marshaller.NewDefaultHTTPMarshaller() | ||||||
structured_headers, structured_data = m.ToRequest( | ||||||
event_1_10, cloudevents.sdk.converters.TypeStructured, json.dumps | ||||||
) | ||||||
|
||||||
resp = client.post("/", headers=structured_headers, data=structured_data.getvalue()) | ||||||
assert resp.status_code == 200 | ||||||
assert resp.data == b"OK" | ||||||
|
||||||
|
||||||
def test_binary_event_1_0(event_1_10): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
source = TEST_FUNCTIONS_DIR / "cloudevents" / "main.py" | ||||||
target = "function" | ||||||
|
||||||
client = create_app(target, source, "cloudevent").test_client() | ||||||
|
||||||
m = cloudevents.sdk.marshaller.NewDefaultHTTPMarshaller() | ||||||
|
||||||
binary_headers, binary_data = m.ToRequest( | ||||||
event_1_10, cloudevents.sdk.converters.TypeBinary, json.dumps | ||||||
) | ||||||
|
||||||
resp = client.post("/", headers=binary_headers, data=binary_data) | ||||||
|
||||||
assert resp.status_code == 200 | ||||||
assert resp.data == b"OK" | ||||||
|
||||||
|
||||||
def test_event_0_3(event_0_3): | ||||||
source = TEST_FUNCTIONS_DIR / "cloudevents" / "main.py" | ||||||
target = "function" | ||||||
|
||||||
client = create_app(target, source, "cloudevent").test_client() | ||||||
|
||||||
m = cloudevents.sdk.marshaller.NewDefaultHTTPMarshaller() | ||||||
structured_headers, structured_data = m.ToRequest( | ||||||
event_0_3, cloudevents.sdk.converters.TypeStructured, json.dumps | ||||||
) | ||||||
|
||||||
resp = client.post("/", headers=structured_headers, data=structured_data.getvalue()) | ||||||
assert resp.status_code == 200 | ||||||
assert resp.data == b"OK" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.