Skip to content
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

exception names shortened #111

Merged
merged 2 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cloudevents/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class CloudEventMissingRequiredFields(Exception):
class MissingRequiredFields(Exception):
pass


class CloudEventTypeErrorRequiredFields(Exception):
class InvalidRequiredFields(Exception):
pass


Expand Down
4 changes: 2 additions & 2 deletions cloudevents/http/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def __init__(
).isoformat()

if self._attributes["specversion"] not in _required_by_version:
raise cloud_exceptions.CloudEventMissingRequiredFields(
raise cloud_exceptions.MissingRequiredFields(
f"Invalid specversion: {self._attributes['specversion']}. "
)
# There is no good way to default 'source' and 'type', so this
# checks for those (or any new required attributes).
required_set = _required_by_version[self._attributes["specversion"]]
if not required_set <= self._attributes.keys():
raise cloud_exceptions.CloudEventMissingRequiredFields(
raise cloud_exceptions.MissingRequiredFields(
f"Missing required keys: {required_set - self._attributes.keys()}. "
)

Expand Down
12 changes: 7 additions & 5 deletions cloudevents/http/http_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def from_http(
specversion = raw_ce.get("specversion", None)

if specversion is None:
raise cloud_exceptions.CloudEventMissingRequiredFields(
"Specversion was set to None in HTTP request. "
raise cloud_exceptions.MissingRequiredFields(
"Failed to find specversion in HTTP request. "
)

event_handler = _obj_by_version.get(specversion, None)

if event_handler is None:
raise cloud_exceptions.CloudEventTypeErrorRequiredFields(
raise cloud_exceptions.InvalidRequiredFields(
f"Found invalid specversion {specversion}. "
)

Expand Down Expand Up @@ -95,7 +95,7 @@ def _to_http(
data_marshaller = _marshaller_by_format[format]

if event._attributes["specversion"] not in _obj_by_version:
raise cloud_exceptions.CloudEventTypeErrorRequiredFields(
raise cloud_exceptions.InvalidRequiredFields(
f"Unsupported specversion: {event._attributes['specversion']}. "
)

Expand All @@ -113,7 +113,9 @@ def to_structured(
event: CloudEvent, data_marshaller: types.MarshallerType = None,
) -> (dict, typing.Union[bytes, str]):
"""
Returns a tuple of HTTP headers/body dicts representing this cloudevent
Returns a tuple of HTTP headers/body dicts representing this cloudevent. If
event.data is a byte object, body will have a data_base64 field instead of
data.

:param event: CloudEvent to cast into http data
:type event: CloudEvent
Expand Down
4 changes: 2 additions & 2 deletions cloudevents/sdk/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def UnmarshalJSON(

missing_fields = self._ce_required_fields - raw_ce.keys()
if len(missing_fields) > 0:
raise cloud_exceptions.CloudEventMissingRequiredFields(
raise cloud_exceptions.MissingRequiredFields(
f"Missing required attributes: {missing_fields}"
)

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

if len(missing_fields) > 0:
raise cloud_exceptions.CloudEventMissingRequiredFields(
raise cloud_exceptions.MissingRequiredFields(
f"Missing required attributes: {missing_fields}"
)

Expand Down
2 changes: 1 addition & 1 deletion cloudevents/tests/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@pytest.mark.parametrize("event_class", [v1.Event, v03.Event])
def test_unmarshall_binary_missing_fields(event_class):
event = event_class()
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields) as e:
with pytest.raises(cloud_exceptions.MissingRequiredFields) as e:
event.UnmarshalBinary({}, "", lambda x: x)
assert "Missing required attributes: " in str(e.value)

Expand Down
6 changes: 3 additions & 3 deletions cloudevents/tests/test_http_cloudevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ def test_http_cloudevent_mutates_equality(specversion):

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


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

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

Expand Down
10 changes: 5 additions & 5 deletions cloudevents/tests/test_http_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def echo(request):

@pytest.mark.parametrize("body", invalid_cloudevent_request_body)
def test_missing_required_fields_structured(body):
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
with pytest.raises(cloud_exceptions.MissingRequiredFields):
# 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
Expand All @@ -102,7 +102,7 @@ def test_missing_required_fields_structured(body):

@pytest.mark.parametrize("headers", invalid_test_headers)
def test_missing_required_fields_binary(headers):
with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
with pytest.raises(cloud_exceptions.MissingRequiredFields):
# 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
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_missing_ce_prefix_binary_event(specversion):
# breaking prefix e.g. e-id instead of ce-id
prefixed_headers[key[1:]] = headers[key]

with pytest.raises(cloud_exceptions.CloudEventMissingRequiredFields):
with pytest.raises(cloud_exceptions.MissingRequiredFields):
# 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
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_wrong_specversion():
"source": "<my-source>",
}
)
with pytest.raises(cloud_exceptions.CloudEventTypeErrorRequiredFields) as e:
with pytest.raises(cloud_exceptions.InvalidRequiredFields) as e:
from_http(headers, data)
assert "Found invalid specversion 0.2" in str(e.value)

Expand All @@ -425,7 +425,7 @@ def test_invalid_data_format_structured_from_http():

def test_wrong_specversion_to_request():
event = CloudEvent({"source": "s", "type": "t"}, None)
with pytest.raises(cloud_exceptions.CloudEventTypeErrorRequiredFields) as e:
with pytest.raises(cloud_exceptions.InvalidRequiredFields) as e:
event["specversion"] = "0.2"
to_binary(event)
assert "Unsupported specversion: 0.2" in str(e.value)
Expand Down