From cc02f339cef970d05d92b2dea727a73760a9e366 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Thu, 18 Jun 2020 18:02:10 -0400 Subject: [PATCH 01/12] Added SetCloudEventVersion Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index a8bb099e..cd6ae808 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -66,6 +66,9 @@ def ContentType(self) -> str: # CloudEvent attribute constructors # Each setter return an instance of its class # in order to build a pipeline of setter + def SetCloudEventVersion(self, specversion: str) -> object: + raise Exception("not implemented") + def SetEventType(self, eventType: str) -> object: raise Exception("not implemented") From ba7976303770e826b33e5bd1062f282ba43e2887 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Thu, 18 Jun 2020 19:26:42 -0400 Subject: [PATCH 02/12] began adding python properties Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 54 ++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index cd6ae808..3518bab0 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -33,30 +33,73 @@ # TODO(slinkydeveloper) is this really needed? -class EventGetterSetter(object): - +class EventGetterSetter(object): + + # ce-specversion def CloudEventVersion(self) -> str: raise Exception("not implemented") - # CloudEvent attribute getters + def SetCloudEventVersion(self, specversion: str) -> object: + raise Exception("not implemented") + + @property + def specversion(self): + return self.CloudEventVersion() + + @specversion.setter + def specversion(self, value: str): + self.SetCloudEventVersion(value) + + # ce-type def EventType(self) -> str: raise Exception("not implemented") + def SetEventType(self, eventType: str) -> object: + raise Exception("not implemented") + + @property + def type(self): + return self.EventType() + + # ce-source def Source(self) -> str: raise Exception("not implemented") + @property + def source(self): + return self.Source() + + # ce-id def EventID(self) -> str: raise Exception("not implemented") + @property + def id(self): + return self.EventId() + + # ce-time def EventTime(self) -> str: raise Exception("not implemented") + @property + def time(self): + return self.EventTime() + + # ce-schema def SchemaURL(self) -> str: raise Exception("not implemented") + @property + def schema(self) -> str: + return self.SchemaURL() + def Data(self) -> object: raise Exception("not implemented") + @property + def data(self) -> obbject: + return self.Data() + def Extensions(self) -> dict: raise Exception("not implemented") @@ -66,11 +109,8 @@ def ContentType(self) -> str: # CloudEvent attribute constructors # Each setter return an instance of its class # in order to build a pipeline of setter - def SetCloudEventVersion(self, specversion: str) -> object: - raise Exception("not implemented") - def SetEventType(self, eventType: str) -> object: - raise Exception("not implemented") + def SetSource(self, source: str) -> object: raise Exception("not implemented") From 2536b14217adf7d621d9809afea6538a72cb628d Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Thu, 18 Jun 2020 19:52:04 -0400 Subject: [PATCH 03/12] added pythonic properties to base class Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 94 ++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index 3518bab0..723a875f 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -39,13 +39,13 @@ class EventGetterSetter(object): def CloudEventVersion(self) -> str: raise Exception("not implemented") - def SetCloudEventVersion(self, specversion: str) -> object: - raise Exception("not implemented") - @property def specversion(self): return self.CloudEventVersion() + def SetCloudEventVersion(self, specversion: str) -> object: + raise Exception("not implemented") + @specversion.setter def specversion(self, value: str): self.SetCloudEventVersion(value) @@ -54,13 +54,17 @@ def specversion(self, value: str): def EventType(self) -> str: raise Exception("not implemented") - def SetEventType(self, eventType: str) -> object: - raise Exception("not implemented") - @property def type(self): return self.EventType() + def SetEventType(self, eventType: str) -> object: + raise Exception("not implemented") + + @type.setter + def type(self, value: str): + self.SetEventType(value) + # ce-source def Source(self) -> str: raise Exception("not implemented") @@ -68,6 +72,13 @@ def Source(self) -> str: @property def source(self): return self.Source() + + def SetSource(self, source: str) -> object: + raise Exception("not implemented") + + @source.setter + def source(self, value: str): + self.SetSource(value) # ce-id def EventID(self) -> str: @@ -76,6 +87,13 @@ def EventID(self) -> str: @property def id(self): return self.EventId() + + def SetEventID(self, eventID: str) -> object: + raise Exception("not implemented") + + @id.setter + def id(self, value: str): + self.SetEventID(value) # ce-time def EventTime(self) -> str: @@ -84,6 +102,13 @@ def EventTime(self) -> str: @property def time(self): return self.EventTime() + + def SetEventTime(self, eventTime: str) -> object: + raise Exception("not implemented") + + @time.setter + def time(self, value: str): + self.SetEventTime(value) # ce-schema def SchemaURL(self) -> str: @@ -92,46 +117,59 @@ def SchemaURL(self) -> str: @property def schema(self) -> str: return self.SchemaURL() + + def SetSchemaURL(self, schemaURL: str) -> object: + raise Exception("not implemented") + + @schema.setter + def schema(self, value: str): + self.SetSchemaURL(value) + # data def Data(self) -> object: raise Exception("not implemented") @property - def data(self) -> obbject: + def data(self) -> object: return self.Data() - def Extensions(self) -> dict: - raise Exception("not implemented") - - def ContentType(self) -> str: - raise Exception("not implemented") - - # CloudEvent attribute constructors - # Each setter return an instance of its class - # in order to build a pipeline of setter - - - - def SetSource(self, source: str) -> object: - raise Exception("not implemented") - - def SetEventID(self, eventID: str) -> object: + def SetData(self, data: object) -> object: raise Exception("not implemented") + + @data.setter + def data(self, value: object): + self.SetData(value) - def SetEventTime(self, eventTime: str) -> object: + + def Extensions(self) -> dict: raise Exception("not implemented") - def SetSchemaURL(self, schemaURL: str) -> object: - raise Exception("not implemented") + # ce-extensions + @property + def extensions(self) -> dict: + return self.Extensions() - def SetData(self, data: object) -> object: + def SetExtensions(self, extensions: dict) -> object: raise Exception("not implemented") + + @extensions.setter + def extensions(self, value: dict): + self.SetExtensions(value) - def SetExtensions(self, extensions: dict) -> object: + # Content-Type + def ContentType(self) -> str: raise Exception("not implemented") + + @property + def content_type(self) -> str: + return self.ContentType() def SetContentType(self, contentType: str) -> object: raise Exception("not implemented") + + @content_type.setter + def content_type(self, value: str): + self.SetContentType(value) class BaseEvent(EventGetterSetter): From 9107da695af73a78e08a23bb842eaaaf8ce57839 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Thu, 18 Jun 2020 20:02:56 -0400 Subject: [PATCH 04/12] began testing for getters/setters Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/tests/test_data_encaps_refs.py | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 cloudevents/tests/test_data_encaps_refs.py diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py new file mode 100644 index 00000000..6935279f --- /dev/null +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -0,0 +1,71 @@ +# 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 cloudevents.sdk import converters +from cloudevents.sdk import marshaller + +from cloudevents.sdk.converters import structured +from cloudevents.sdk.event import v01, v02, v03, v1 +from cloudevents.sdk.event import v02 + + +from cloudevents.tests import data + + +@pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) +def test_general_binary_getters(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(), + ) + + 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.TypeBinary, lambda x: x) + assert new_headers is not None + assert "ce-specversion" in new_headers + + +@pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) +def test_general_structured_getters(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() + ) + 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 From 0d2b50ffb336a882406f20ea89df451a7554229b Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Thu, 18 Jun 2020 20:10:51 -0400 Subject: [PATCH 05/12] added general setter tests Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 2 +- cloudevents/tests/test_data_encaps_refs.py | 48 +++++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index 723a875f..03606cd9 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -86,7 +86,7 @@ def EventID(self) -> str: @property def id(self): - return self.EventId() + return self.EventID() def SetEventID(self, eventID: str) -> object: raise Exception("not implemented") diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index 6935279f..b67fb49c 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -17,6 +17,8 @@ import copy import pytest +from uuid import uuid4 + from cloudevents.sdk import converters from cloudevents.sdk import marshaller @@ -29,7 +31,7 @@ @pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) -def test_general_binary_getters(event_class): +def test_general_binary_properties(event_class): m = marshaller.NewDefaultHTTPMarshaller() event = m.FromRequest( event_class(), @@ -37,26 +39,45 @@ def test_general_binary_getters(event_class): 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 - new_headers, _ = m.ToRequest(event, converters.TypeBinary, lambda x: x) - assert new_headers is not None - assert "ce-specversion" in new_headers + # Test setters + new_type = str(uuid4()) + new_id = str(uuid4()) + new_content_type = str(uuid4()) + new_source = 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 + assert event.id == new_id + assert event.content_type == new_content_type + assert event.source == new_source @pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) -def test_general_structured_getters(event_class): +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 @@ -69,3 +90,20 @@ def test_general_structured_getters(event_class): 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.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 + assert event.id == new_id + assert event.content_type == new_content_type + assert event.source == new_source From cc258dffa8349c6d5d7f4907da5c3824ca5deeac Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Fri, 19 Jun 2020 11:38:42 -0400 Subject: [PATCH 06/12] fixed spacing in base.py Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index 03606cd9..be821cb0 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -33,8 +33,8 @@ # TODO(slinkydeveloper) is this really needed? -class EventGetterSetter(object): - +class EventGetterSetter(object): + # ce-specversion def CloudEventVersion(self) -> str: raise Exception("not implemented") @@ -49,12 +49,12 @@ def SetCloudEventVersion(self, specversion: str) -> object: @specversion.setter def specversion(self, value: str): self.SetCloudEventVersion(value) - + # ce-type def EventType(self) -> str: raise Exception("not implemented") - @property + @property def type(self): return self.EventType() @@ -79,7 +79,7 @@ def SetSource(self, source: str) -> object: @source.setter def source(self, value: str): self.SetSource(value) - + # ce-id def EventID(self) -> str: raise Exception("not implemented") @@ -94,7 +94,7 @@ def SetEventID(self, eventID: str) -> object: @id.setter def id(self, value: str): self.SetEventID(value) - + # ce-time def EventTime(self) -> str: raise Exception("not implemented") @@ -109,7 +109,7 @@ def SetEventTime(self, eventTime: str) -> object: @time.setter def time(self, value: str): self.SetEventTime(value) - + # ce-schema def SchemaURL(self) -> str: raise Exception("not implemented") @@ -124,7 +124,7 @@ def SetSchemaURL(self, schemaURL: str) -> object: @schema.setter def schema(self, value: str): self.SetSchemaURL(value) - + # data def Data(self) -> object: raise Exception("not implemented") @@ -135,23 +135,22 @@ def data(self) -> object: def SetData(self, data: object) -> object: raise Exception("not implemented") - + @data.setter def data(self, value: object): self.SetData(value) - + # ce-extensions def Extensions(self) -> dict: raise Exception("not implemented") - # ce-extensions @property def extensions(self) -> dict: return self.Extensions() def SetExtensions(self, extensions: dict) -> object: raise Exception("not implemented") - + @extensions.setter def extensions(self, value: dict): self.SetExtensions(value) @@ -159,14 +158,14 @@ def extensions(self, value: dict): # Content-Type def ContentType(self) -> str: raise Exception("not implemented") - + @property def content_type(self) -> str: return self.ContentType() def SetContentType(self, contentType: str) -> object: raise Exception("not implemented") - + @content_type.setter def content_type(self, value: str): self.SetContentType(value) From ee12a18c0355c05abb8e2c0362187478a3357b02 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Fri, 19 Jun 2020 11:49:24 -0400 Subject: [PATCH 07/12] added __eq__ to option and datacontentencoding property to v03 Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/opt.py | 6 ++++++ cloudevents/sdk/event/v03.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/cloudevents/sdk/event/opt.py b/cloudevents/sdk/event/opt.py index 2a18a52a..bf630c32 100644 --- a/cloudevents/sdk/event/opt.py +++ b/cloudevents/sdk/event/opt.py @@ -35,3 +35,9 @@ def get(self): def required(self): return self.is_required + + def __eq__(self, obj): + return isinstance(obj, Option) and \ + obj.name == self.name and \ + obj.value == self.value and \ + obj.is_required == self.is_required diff --git a/cloudevents/sdk/event/v03.py b/cloudevents/sdk/event/v03.py index 4207e400..492e9c62 100644 --- a/cloudevents/sdk/event/v03.py +++ b/cloudevents/sdk/event/v03.py @@ -68,6 +68,11 @@ def ContentType(self) -> str: def ContentEncoding(self) -> str: return self.ce__datacontentencoding.get() + @property + def datacontentencoding(self): + return self.ContentEncoding() + + def SetEventType(self, eventType: str) -> base.BaseEvent: self.Set("type", eventType) return self @@ -107,3 +112,7 @@ def SetContentType(self, contentType: str) -> base.BaseEvent: def SetContentEncoding(self, contentEncoding: str) -> base.BaseEvent: self.Set("datacontentencoding", contentEncoding) return self + + @datacontentencoding.setter + def datacontentencoding(self, value: str): + self.SetContentEncoding(value) From eba7e6803b506d44720970ef027c845b42eec566 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Fri, 19 Jun 2020 12:39:08 -0400 Subject: [PATCH 08/12] lint fixes Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/v03.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cloudevents/sdk/event/v03.py b/cloudevents/sdk/event/v03.py index 492e9c62..00ff67f8 100644 --- a/cloudevents/sdk/event/v03.py +++ b/cloudevents/sdk/event/v03.py @@ -71,7 +71,6 @@ def ContentEncoding(self) -> str: @property def datacontentencoding(self): return self.ContentEncoding() - def SetEventType(self, eventType: str) -> base.BaseEvent: self.Set("type", eventType) From 6fd0e93604f39ee7c65bd027478898a729c90cd1 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Fri, 19 Jun 2020 13:15:17 -0400 Subject: [PATCH 09/12] testing extensions and old getters Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/sdk/event/base.py | 1 - cloudevents/tests/test_data_encaps_refs.py | 26 +++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cloudevents/sdk/event/base.py b/cloudevents/sdk/event/base.py index be821cb0..4ad32a5d 100644 --- a/cloudevents/sdk/event/base.py +++ b/cloudevents/sdk/event/base.py @@ -200,7 +200,6 @@ def Set(self, key: str, value: object): attr.set(value) setattr(self, formatted_key, attr) return - exts = self.Extensions() exts.update({key: value}) self.Set("extensions", exts) diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index b67fb49c..b06b849a 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -56,17 +56,20 @@ def test_general_binary_properties(event_class): 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 - assert event.id == new_id - assert event.content_type == new_content_type - assert event.source == new_source + 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", [v02.Event, v03.Event, v1.Event]) @@ -97,13 +100,16 @@ def test_general_structured_properties(event_class): 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 - assert event.id == new_id - assert event.content_type == new_content_type - assert event.source == new_source + 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()) From b4fc9586c920524e63e3198da60eec59fd46e86f Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Tue, 23 Jun 2020 13:18:46 -0400 Subject: [PATCH 10/12] removed versions v01 and v02 from test_data_encaps_refs.py Signed-off-by: Curtis Mason Signed-off-by: Dustin Ingram --- cloudevents/tests/test_data_encaps_refs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index b06b849a..84bc91ef 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -23,14 +23,13 @@ from cloudevents.sdk import marshaller from cloudevents.sdk.converters import structured -from cloudevents.sdk.event import v01, v02, v03, v1 -from cloudevents.sdk.event import v02 +from cloudevents.sdk.event import v03, v1 from cloudevents.tests import data -@pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) +@pytest.mark.parametrize("event_class", [ v03.Event, v1.Event]) def test_general_binary_properties(event_class): m = marshaller.NewDefaultHTTPMarshaller() event = m.FromRequest( @@ -72,7 +71,7 @@ def test_general_binary_properties(event_class): assert (event.specversion == event.CloudEventVersion()) -@pytest.mark.parametrize("event_class", [v02.Event, v03.Event, v1.Event]) +@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() From 8db3123c9b031f85f708979e0fa7b56fcdd46047 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Wed, 24 Jun 2020 13:55:17 -0400 Subject: [PATCH 11/12] fixed inheritance issue in CloudEvent Signed-off-by: Curtis Mason --- cloudevents/sdk/http_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudevents/sdk/http_events.py b/cloudevents/sdk/http_events.py index 4c5de1c2..8d8e7fa1 100644 --- a/cloudevents/sdk/http_events.py +++ b/cloudevents/sdk/http_events.py @@ -22,7 +22,7 @@ from cloudevents.sdk.event import v03, v1 -class CloudEvent(base.BaseEvent): +class CloudEvent(): """ Python-friendly cloudevent class supporting v1 events Currently only supports binary content mode CloudEvents From 9bf2317712e829e164682a8f8c10843c2fc5bfd5 Mon Sep 17 00:00:00 2001 From: Curtis Mason Date: Wed, 24 Jun 2020 14:00:54 -0400 Subject: [PATCH 12/12] added prefixed_headers dict to test Signed-off-by: Curtis Mason --- cloudevents/tests/test_http_events.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cloudevents/tests/test_http_events.py b/cloudevents/tests/test_http_events.py index 943e219e..843eb75f 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -101,6 +101,7 @@ def test_emit_binary_event(specversion): @pytest.mark.parametrize("specversion", ['1.0', '0.3']) def test_missing_ce_prefix_binary_event(specversion): + prefixed_headers = {} headers = { "ce-id": "my-id", "ce-source": "", @@ -108,16 +109,16 @@ def test_missing_ce_prefix_binary_event(specversion): "ce-specversion": specversion } for key in headers: - val = headers.pop(key) - + # breaking prefix e.g. e-id instead of ce-id - headers[key[1:]] = val + prefixed_headers[key[1:]] = headers[key] + with pytest.raises((TypeError, NotImplementedError)): # CloudEvent constructor throws TypeError if missing required field # and NotImplementedError because structured calls aren't # implemented. In this instance one of the required keys should have # prefix e-id instead of ce-id therefore it should throw - _ = CloudEvent(headers, test_data) + _ = CloudEvent(prefixed_headers, test_data) @pytest.mark.parametrize("specversion", ['1.0', '0.3'])