Skip to content

Commit 7f6d6eb

Browse files
authored
exception names shortened (cloudevents#111)
* exception names shortened Signed-off-by: Curtis Mason <cumason@google.com> * to_structured documentation Signed-off-by: Curtis Mason <cumason@google.com>
1 parent be80247 commit 7f6d6eb

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

cloudevents/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
class CloudEventMissingRequiredFields(Exception):
14+
class MissingRequiredFields(Exception):
1515
pass
1616

1717

18-
class CloudEventTypeErrorRequiredFields(Exception):
18+
class InvalidRequiredFields(Exception):
1919
pass
2020

2121

cloudevents/http/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def __init__(
5858
).isoformat()
5959

6060
if self._attributes["specversion"] not in _required_by_version:
61-
raise cloud_exceptions.CloudEventMissingRequiredFields(
61+
raise cloud_exceptions.MissingRequiredFields(
6262
f"Invalid specversion: {self._attributes['specversion']}. "
6363
)
6464
# There is no good way to default 'source' and 'type', so this
6565
# checks for those (or any new required attributes).
6666
required_set = _required_by_version[self._attributes["specversion"]]
6767
if not required_set <= self._attributes.keys():
68-
raise cloud_exceptions.CloudEventMissingRequiredFields(
68+
raise cloud_exceptions.MissingRequiredFields(
6969
f"Missing required keys: {required_set - self._attributes.keys()}. "
7070
)
7171

cloudevents/http/http_methods.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def from_http(
5454
specversion = raw_ce.get("specversion", None)
5555

5656
if specversion is None:
57-
raise cloud_exceptions.CloudEventMissingRequiredFields(
58-
"Specversion was set to None in HTTP request. "
57+
raise cloud_exceptions.MissingRequiredFields(
58+
"Failed to find specversion in HTTP request. "
5959
)
6060

6161
event_handler = _obj_by_version.get(specversion, None)
6262

6363
if event_handler is None:
64-
raise cloud_exceptions.CloudEventTypeErrorRequiredFields(
64+
raise cloud_exceptions.InvalidRequiredFields(
6565
f"Found invalid specversion {specversion}. "
6666
)
6767

@@ -95,7 +95,7 @@ def _to_http(
9595
data_marshaller = _marshaller_by_format[format]
9696

9797
if event._attributes["specversion"] not in _obj_by_version:
98-
raise cloud_exceptions.CloudEventTypeErrorRequiredFields(
98+
raise cloud_exceptions.InvalidRequiredFields(
9999
f"Unsupported specversion: {event._attributes['specversion']}. "
100100
)
101101

@@ -113,7 +113,9 @@ def to_structured(
113113
event: CloudEvent, data_marshaller: types.MarshallerType = None,
114114
) -> (dict, typing.Union[bytes, str]):
115115
"""
116-
Returns a tuple of HTTP headers/body dicts representing this cloudevent
116+
Returns a tuple of HTTP headers/body dicts representing this cloudevent. If
117+
event.data is a byte object, body will have a data_base64 field instead of
118+
data.
117119
118120
:param event: CloudEvent to cast into http data
119121
:type event: CloudEvent

cloudevents/sdk/event/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def UnmarshalJSON(
220220

221221
missing_fields = self._ce_required_fields - raw_ce.keys()
222222
if len(missing_fields) > 0:
223-
raise cloud_exceptions.CloudEventMissingRequiredFields(
223+
raise cloud_exceptions.MissingRequiredFields(
224224
f"Missing required attributes: {missing_fields}"
225225
)
226226

@@ -246,7 +246,7 @@ def UnmarshalBinary(
246246
missing_fields = required_binary_fields - headers.keys()
247247

248248
if len(missing_fields) > 0:
249-
raise cloud_exceptions.CloudEventMissingRequiredFields(
249+
raise cloud_exceptions.MissingRequiredFields(
250250
f"Missing required attributes: {missing_fields}"
251251
)
252252

cloudevents/tests/test_base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@pytest.mark.parametrize("event_class", [v1.Event, v03.Event])
2121
def test_unmarshall_binary_missing_fields(event_class):
2222
event = event_class()
23-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields) as e:
23+
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
2424
event.UnmarshalBinary({}, "", lambda x: x)
2525
assert "Missing required attributes: " in str(e.value)
2626

cloudevents/tests/test_http_cloudevent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ def test_http_cloudevent_mutates_equality(specversion):
7474

7575
def test_cloudevent_missing_specversion():
7676
attributes = {"specversion": "0.2", "source": "s", "type": "t"}
77-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields) as e:
77+
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
7878
event = CloudEvent(attributes, None)
7979
assert "Invalid specversion: 0.2" in str(e.value)
8080

8181

8282
def test_cloudevent_missing_minimal_required_fields():
8383
attributes = {"type": "t"}
84-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields) as e:
84+
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
8585
event = CloudEvent(attributes, None)
8686
assert f"Missing required keys: {set(['source'])}" in str(e.value)
8787

8888
attributes = {"source": "s"}
89-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields) as e:
89+
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
9090
event = CloudEvent(attributes, None)
9191
assert f"Missing required keys: {set(['type'])}" in str(e.value)
9292

cloudevents/tests/test_http_events.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def echo(request):
9090

9191
@pytest.mark.parametrize("body", invalid_cloudevent_request_body)
9292
def test_missing_required_fields_structured(body):
93-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
93+
with pytest.raises(cloud_exceptions.MissingRequiredFields):
9494
# CloudEvent constructor throws TypeError if missing required field
9595
# and NotImplementedError because structured calls aren't
9696
# implemented. In this instance one of the required keys should have
@@ -102,7 +102,7 @@ def test_missing_required_fields_structured(body):
102102

103103
@pytest.mark.parametrize("headers", invalid_test_headers)
104104
def test_missing_required_fields_binary(headers):
105-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
105+
with pytest.raises(cloud_exceptions.MissingRequiredFields):
106106
# CloudEvent constructor throws TypeError if missing required field
107107
# and NotImplementedError because structured calls aren't
108108
# implemented. In this instance one of the required keys should have
@@ -202,7 +202,7 @@ def test_missing_ce_prefix_binary_event(specversion):
202202
# breaking prefix e.g. e-id instead of ce-id
203203
prefixed_headers[key[1:]] = headers[key]
204204

205-
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
205+
with pytest.raises(cloud_exceptions.MissingRequiredFields):
206206
# CloudEvent constructor throws TypeError if missing required field
207207
# and NotImplementedError because structured calls aren't
208208
# implemented. In this instance one of the required keys should have
@@ -410,7 +410,7 @@ def test_wrong_specversion():
410410
"source": "<my-source>",
411411
}
412412
)
413-
with pytest.raises(cloud_exceptions.CloudEventTypeErrorRequiredFields) as e:
413+
with pytest.raises(cloud_exceptions.InvalidRequiredFields) as e:
414414
from_http(headers, data)
415415
assert "Found invalid specversion 0.2" in str(e.value)
416416

@@ -425,7 +425,7 @@ def test_invalid_data_format_structured_from_http():
425425

426426
def test_wrong_specversion_to_request():
427427
event = CloudEvent({"source": "s", "type": "t"}, None)
428-
with pytest.raises(cloud_exceptions.CloudEventTypeErrorRequiredFields) as e:
428+
with pytest.raises(cloud_exceptions.InvalidRequiredFields) as e:
429429
event["specversion"] = "0.2"
430430
to_binary(event)
431431
assert "Unsupported specversion: 0.2" in str(e.value)

0 commit comments

Comments
 (0)