forked from cloudevents/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented python properties in base.py (cloudevents#41)
* Added SetCloudEventVersion Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * began adding python properties Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * added pythonic properties to base class Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * began testing for getters/setters Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * added general setter tests Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * fixed spacing in base.py Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * added __eq__ to option and datacontentencoding property to v03 Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * lint fixes Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * testing extensions and old getters Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * removed versions v01 and v02 from test_data_encaps_refs.py Signed-off-by: Curtis Mason <cumason@google.com> Signed-off-by: Dustin Ingram <di@users.noreply.github.com> * fixed inheritance issue in CloudEvent Signed-off-by: Curtis Mason <cumason@google.com> * added prefixed_headers dict to test Signed-off-by: Curtis Mason <cumason@google.com>
- Loading branch information
1 parent
30931df
commit d73731e
Showing
6 changed files
with
232 additions
and
24 deletions.
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
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,114 @@ | ||
# All Rights Reserved. | ||
# | ||
# 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 io | ||
import json | ||
import copy | ||
import pytest | ||
|
||
from uuid import uuid4 | ||
|
||
from cloudevents.sdk import converters | ||
from cloudevents.sdk import marshaller | ||
|
||
from cloudevents.sdk.converters import structured | ||
from cloudevents.sdk.event import v03, v1 | ||
|
||
|
||
from cloudevents.tests import data | ||
|
||
|
||
@pytest.mark.parametrize("event_class", [ v03.Event, v1.Event]) | ||
def test_general_binary_properties(event_class): | ||
m = marshaller.NewDefaultHTTPMarshaller() | ||
event = m.FromRequest( | ||
event_class(), | ||
{"Content-Type": "application/cloudevents+json"}, | ||
io.StringIO(json.dumps(data.json_ce[event_class])), | ||
lambda x: x.read(), | ||
) | ||
|
||
new_headers, _ = m.ToRequest(event, converters.TypeBinary, lambda x: x) | ||
assert new_headers is not None | ||
assert "ce-specversion" in new_headers | ||
|
||
# Test properties | ||
assert event is not None | ||
assert event.type == data.ce_type | ||
assert event.id == data.ce_id | ||
assert event.content_type == data.contentType | ||
assert event.source == data.source | ||
|
||
# Test setters | ||
new_type = str(uuid4()) | ||
new_id = str(uuid4()) | ||
new_content_type = str(uuid4()) | ||
new_source = str(uuid4()) | ||
|
||
event.extensions = {'test': str(uuid4)} | ||
event.type = new_type | ||
event.id = new_id | ||
event.content_type = new_content_type | ||
event.source = new_source | ||
|
||
assert event is not None | ||
assert (event.type == new_type) and (event.type == event.EventType()) | ||
assert (event.id == new_id) and (event.id == event.EventID()) | ||
assert (event.content_type == new_content_type) and (event.content_type == event.ContentType()) | ||
assert (event.source == new_source) and (event.source == event.Source()) | ||
assert event.extensions['test'] == event.Extensions()['test'] | ||
assert (event.specversion == event.CloudEventVersion()) | ||
|
||
|
||
@pytest.mark.parametrize("event_class", [v03.Event, v1.Event]) | ||
def test_general_structured_properties(event_class): | ||
copy_of_ce = copy.deepcopy(data.json_ce[event_class]) | ||
m = marshaller.NewDefaultHTTPMarshaller() | ||
http_headers = {"content-type": "application/cloudevents+json"} | ||
event = m.FromRequest( | ||
event_class(), http_headers, io.StringIO(json.dumps(data.json_ce[event_class])), lambda x: x.read() | ||
) | ||
# Test python properties | ||
assert event is not None | ||
assert event.type == data.ce_type | ||
assert event.id == data.ce_id | ||
assert event.content_type == data.contentType | ||
assert event.source == data.source | ||
|
||
new_headers, _ = m.ToRequest(event, converters.TypeStructured, lambda x: x) | ||
for key in new_headers: | ||
if key == "content-type": | ||
assert new_headers[key] == http_headers[key] | ||
continue | ||
assert key in copy_of_ce | ||
|
||
# Test setters | ||
new_type = str(uuid4()) | ||
new_id = str(uuid4()) | ||
new_content_type = str(uuid4()) | ||
new_source = str(uuid4()) | ||
|
||
event.extensions = {'test': str(uuid4)} | ||
event.type = new_type | ||
event.id = new_id | ||
event.content_type = new_content_type | ||
event.source = new_source | ||
|
||
assert event is not None | ||
assert (event.type == new_type) and (event.type == event.EventType()) | ||
assert (event.id == new_id) and (event.id == event.EventID()) | ||
assert (event.content_type == new_content_type) and (event.content_type == event.ContentType()) | ||
assert (event.source == new_source) and (event.source == event.Source()) | ||
assert event.extensions['test'] == event.Extensions()['test'] | ||
assert (event.specversion == event.CloudEventVersion()) |
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