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

Removed _http suffix from http_methods #108

Merged
merged 7 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Below we will provide samples on how to send cloudevents using the popular
### Binary HTTP CloudEvent

```python
from cloudevents.http import CloudEvent, to_binary_http
from cloudevents.http import CloudEvent, to_binary
import requests


Expand All @@ -36,7 +36,7 @@ attributes = {
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_binary_http(event)
headers, body = to_binary(event)

# POST
requests.post("<some-url>", data=body, headers=headers)
Expand All @@ -45,7 +45,7 @@ requests.post("<some-url>", data=body, headers=headers)
### Structured HTTP CloudEvent

```python
from cloudevents.http import CloudEvent, to_structured_http
from cloudevents.http import CloudEvent, to_structured
import requests


Expand All @@ -56,7 +56,7 @@ attributes = {
}
data = {"message": "Hello World!"}
event = CloudEvent(attributes, data)
headers, body = to_structured_http(event)
headers, body = to_structured(event)

# POST
requests.post("<some-url>", data=body, headers=headers)
Expand Down
2 changes: 1 addition & 1 deletion cloudevents/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.2"
6 changes: 1 addition & 5 deletions cloudevents/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@

from cloudevents.http.event import CloudEvent
from cloudevents.http.event_type import is_binary, is_structured
from cloudevents.http.http_methods import (
from_http,
to_binary_http,
to_structured_http,
)
from cloudevents.http.http_methods import from_http, to_binary, to_structured
from cloudevents.http.json_methods import from_json, to_json
4 changes: 2 additions & 2 deletions cloudevents/http/http_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _to_http(
)


def to_structured_http(
def to_structured(
event: CloudEvent, data_marshaller: types.MarshallerType = None,
) -> (dict, typing.Union[bytes, str]):
"""
Expand All @@ -107,7 +107,7 @@ def to_structured_http(
return _to_http(event=event, data_marshaller=data_marshaller)


def to_binary_http(
def to_binary(
event: CloudEvent, data_marshaller: types.MarshallerType = None,
) -> (dict, typing.Union[bytes, str]):
"""
Expand Down
4 changes: 2 additions & 2 deletions cloudevents/http/json_methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing

from cloudevents.http.event import CloudEvent
from cloudevents.http.http_methods import from_http, to_structured_http
from cloudevents.http.http_methods import from_http, to_structured
from cloudevents.sdk import types


Expand All @@ -17,7 +17,7 @@ def to_json(
:type data_marshaller: typing.Callable
:returns: json object representing the given event
"""
return to_structured_http(event, data_marshaller=data_marshaller)[1]
return to_structured(event, data_marshaller=data_marshaller)[1]


def from_json(
Expand Down
11 changes: 3 additions & 8 deletions cloudevents/tests/test_event_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

import pytest

from cloudevents.http import (
CloudEvent,
from_http,
to_binary_http,
to_structured_http,
)
from cloudevents.http import CloudEvent, from_http, to_binary, to_structured

test_data = json.dumps({"data-key": "val"})
test_attributes = {
Expand All @@ -39,7 +34,7 @@ def test_cloudevent_access_extensions(specversion):
@pytest.mark.parametrize("specversion", ["0.3", "1.0"])
def test_to_binary_extensions(specversion):
event = CloudEvent(test_attributes, test_data)
headers, body = to_binary_http(event)
headers, body = to_binary(event)

assert "ce-ext1" in headers
assert headers.get("ce-ext1") == test_attributes["ext1"]
Expand All @@ -65,7 +60,7 @@ def test_from_binary_extensions(specversion):
@pytest.mark.parametrize("specversion", ["0.3", "1.0"])
def test_to_structured_extensions(specversion):
event = CloudEvent(test_attributes, test_data)
headers, body = to_structured_http(event)
headers, body = to_structured(event)

body = json.loads(body)

Expand Down
16 changes: 8 additions & 8 deletions cloudevents/tests/test_http_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
CloudEvent,
from_http,
is_binary,
to_binary_http,
to_structured_http,
to_binary,
to_structured,
)
from cloudevents.sdk import converters

Expand Down Expand Up @@ -177,9 +177,9 @@ def test_roundtrip_non_json_event(converter, specversion):
event = CloudEvent(attrs, compressed_data)

if converter == converters.TypeStructured:
headers, data = to_structured_http(event, data_marshaller=lambda x: x)
headers, data = to_structured(event, data_marshaller=lambda x: x)
elif converter == converters.TypeBinary:
headers, data = to_binary_http(event, data_marshaller=lambda x: x)
headers, data = to_binary(event, data_marshaller=lambda x: x)

headers["binary-payload"] = "true" # Decoding hint for server
_, r = app.test_client.post("/event", headers=headers, data=data)
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_structured_to_request(specversion):
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body_bytes = to_structured_http(event)
headers, body_bytes = to_structured(event)
assert isinstance(body_bytes, bytes)
body = json.loads(body_bytes)

Expand All @@ -267,7 +267,7 @@ def test_binary_to_request(specversion):
}
data = {"message": "Hello World!"}
event = CloudEvent(attributes, data)
headers, body_bytes = to_binary_http(event)
headers, body_bytes = to_binary(event)
body = json.loads(body_bytes)

for key in data:
Expand Down Expand Up @@ -398,5 +398,5 @@ def test_none_data_cloudevent(specversion):
"specversion": specversion,
}
)
to_binary_http(event)
to_structured_http(event)
to_binary(event)
to_structured(event)
8 changes: 4 additions & 4 deletions samples/http-image-cloudevents/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import requests

from cloudevents.http import CloudEvent, to_binary_http, to_structured_http
from cloudevents.http import CloudEvent, to_binary, to_structured

resp = requests.get(
"https://raw.githubusercontent.com/cncf/artwork/master/projects/cloudevents/horizontal/color/cloudevents-horizontal-color.png"
Expand All @@ -33,7 +33,7 @@ def send_binary_cloud_event(url: str):
event = CloudEvent(attributes, image_bytes)

# Create cloudevent HTTP headers and content
headers, body = to_binary_http(event)
headers, body = to_binary(event)

# Send cloudevent
requests.post(url, headers=headers, data=body)
Expand All @@ -50,10 +50,10 @@ def send_structured_cloud_event(url: str):
event = CloudEvent(attributes, image_bytes)

# Create cloudevent HTTP headers and content
# Note that to_structured_http will create a data_base64 data field in
# Note that to_structured will create a data_base64 data field in
# specversion 1.0 (default specversion) if given
# an event whose data field is of type bytes.
headers, body = to_structured_http(event)
headers, body = to_structured(event)

# Send cloudevent
requests.post(url, headers=headers, data=body)
Expand Down
17 changes: 6 additions & 11 deletions samples/http-image-cloudevents/image_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
from image_sample_server import app
from PIL import Image

from cloudevents.http import (
CloudEvent,
from_http,
to_binary_http,
to_structured_http,
)
from cloudevents.http import CloudEvent, from_http, to_binary, to_structured

image_fileobj = io.BytesIO(image_bytes)
image_expected_shape = (1880, 363)
Expand All @@ -35,7 +30,7 @@ def test_create_binary_image():
event = CloudEvent(attributes, image_bytes)

# Create http headers/body content
headers, body = to_binary_http(event)
headers, body = to_binary(event)

# Unmarshall CloudEvent and re-create image
reconstruct_event = from_http(
Expand All @@ -62,7 +57,7 @@ def test_create_structured_image():
event = CloudEvent(attributes, image_bytes)

# Create http headers/body content
headers, body = to_structured_http(event)
headers, body = to_structured(event)

# Structured has cloudevent attributes marshalled inside the body. For this
# reason we must load the byte object to create the python dict containing
Expand Down Expand Up @@ -92,10 +87,10 @@ def test_server_structured(client):
event = CloudEvent(attributes, image_bytes)

# Create cloudevent HTTP headers and content
# Note that to_structured_http will create a data_base64 data field in
# Note that to_structured will create a data_base64 data field in
# specversion 1.0 (default specversion) if given
# an event whose data field is of type bytes.
headers, body = to_structured_http(event)
headers, body = to_structured(event)

# Send cloudevent
r = client.post("/", headers=headers, data=body)
Expand All @@ -113,7 +108,7 @@ def test_server_binary(client):
event = CloudEvent(attributes, image_bytes)

# Create cloudevent HTTP headers and content
headers, body = to_binary_http(event)
headers, body = to_binary(event)

# Send cloudevent
r = client.post("/", headers=headers, data=body)
Expand Down
6 changes: 3 additions & 3 deletions samples/http-json-cloudevents/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import requests

from cloudevents.http import CloudEvent, to_binary_http, to_structured_http
from cloudevents.http import CloudEvent, to_binary, to_structured


def send_binary_cloud_event(url):
Expand All @@ -28,7 +28,7 @@ def send_binary_cloud_event(url):
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_binary_http(event)
headers, body = to_binary(event)

# send and print event
requests.post(url, headers=headers, data=body)
Expand All @@ -44,7 +44,7 @@ def send_structured_cloud_event(url):
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_structured_http(event)
headers, body = to_structured(event)

# send and print event
requests.post(url, headers=headers, data=body)
Expand Down
6 changes: 3 additions & 3 deletions samples/http-json-cloudevents/json_sample_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from json_sample_server import app

from cloudevents.http import CloudEvent, to_binary_http, to_structured_http
from cloudevents.http import CloudEvent, to_binary, to_structured


@pytest.fixture
Expand All @@ -19,7 +19,7 @@ def test_binary_request(client):
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_binary_http(event)
headers, body = to_binary(event)

r = client.post("/", headers=headers, data=body)
assert r.status_code == 204
Expand All @@ -34,7 +34,7 @@ def test_structured_request(client):
data = {"message": "Hello World!"}

event = CloudEvent(attributes, data)
headers, body = to_structured_http(event)
headers, body = to_structured(event)

r = client.post("/", headers=headers, data=body)
assert r.status_code == 204