Move cloudevents to v1
Signed-off-by: Yurii Serhiichuk <savik.ne@gmail.com>
This commit is contained in:
parent
202338315f
commit
e6abc12470
|
@ -8,16 +8,14 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
- name: Install the latest version of rye
|
||||
uses: eifinger/setup-rye@v4
|
||||
with:
|
||||
python-version: '3.11'
|
||||
cache: 'pip'
|
||||
cache-dependency-path: 'requirements/*.txt'
|
||||
- name: Install dev dependencies
|
||||
run: python -m pip install -r requirements/dev.txt
|
||||
- name: Run linting
|
||||
run: python -m tox -e lint
|
||||
enable-cache: true
|
||||
- name: Sync dependencies
|
||||
run: rye sync
|
||||
- name: Lint
|
||||
run: rye lint
|
||||
|
||||
test:
|
||||
strategy:
|
||||
|
|
36
README.md
36
README.md
|
@ -32,15 +32,15 @@ Below we will provide samples on how to send cloudevents using the popular
|
|||
### Binary HTTP CloudEvent
|
||||
|
||||
```python
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents.conversion import to_binary
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
from cloudevents_v1.conversion import to_binary
|
||||
import requests
|
||||
|
||||
# Create a CloudEvent
|
||||
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
|
||||
attributes = {
|
||||
"type": "com.example.sampletype1",
|
||||
"source": "https://example.com/event-producer",
|
||||
"type": "com.example.sampletype1",
|
||||
"source": "https://example.com/event-producer",
|
||||
}
|
||||
data = {"message": "Hello World!"}
|
||||
event = CloudEvent(attributes, data)
|
||||
|
@ -55,15 +55,15 @@ requests.post("<some-url>", data=body, headers=headers)
|
|||
### Structured HTTP CloudEvent
|
||||
|
||||
```python
|
||||
from cloudevents.conversion import to_structured
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents_v1.conversion import to_structured
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
import requests
|
||||
|
||||
# Create a CloudEvent
|
||||
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
|
||||
attributes = {
|
||||
"type": "com.example.sampletype2",
|
||||
"source": "https://example.com/event-producer",
|
||||
"type": "com.example.sampletype2",
|
||||
"source": "https://example.com/event-producer",
|
||||
}
|
||||
data = {"message": "Hello World!"}
|
||||
event = CloudEvent(attributes, data)
|
||||
|
@ -86,7 +86,7 @@ The code below shows how to consume a cloudevent using the popular python web fr
|
|||
```python
|
||||
from flask import Flask, request
|
||||
|
||||
from cloudevents.http import from_http
|
||||
from cloudevents_v1.http import from_http
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
@ -94,20 +94,20 @@ app = Flask(__name__)
|
|||
# create an endpoint at http://localhost:/3000/
|
||||
@app.route("/", methods=["POST"])
|
||||
def home():
|
||||
# create a CloudEvent
|
||||
event = from_http(request.headers, request.get_data())
|
||||
# create a CloudEvent
|
||||
event = from_http(request.headers, request.get_data())
|
||||
|
||||
# you can access cloudevent fields as seen below
|
||||
print(
|
||||
f"Found {event['id']} from {event['source']} with type "
|
||||
f"{event['type']} and specversion {event['specversion']}"
|
||||
)
|
||||
# you can access cloudevent fields as seen below
|
||||
print(
|
||||
f"Found {event['id']} from {event['source']} with type "
|
||||
f"{event['type']} and specversion {event['specversion']}"
|
||||
)
|
||||
|
||||
return "", 204
|
||||
return "", 204
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(port=3000)
|
||||
app.run(port=3000)
|
||||
```
|
||||
|
||||
You can find a complete example of turning a CloudEvent into a HTTP request
|
||||
|
|
|
@ -4,7 +4,7 @@ This repository is configured to automatically publish the corresponding [PyPI
|
|||
package](https://pypi.org/project/cloudevents/) and GitHub Tag via GitHub Actions.
|
||||
|
||||
To release a new CloudEvents SDK, contributors should bump `__version__` in
|
||||
[cloudevents](cloudevents/__init__.py) to reflect the new release version. On merge, the action
|
||||
[cloudevents](cloudevents_v1/__init__.py) to reflect the new release version. On merge, the action
|
||||
will automatically build and release to PyPI using
|
||||
[this PyPI GitHub Action](https://github.com/pypa/gh-action-pypi-publish). This
|
||||
action gets called on all pushes to main (such as a version branch being merged
|
||||
|
@ -12,7 +12,7 @@ into main), but only releases a new version when the version number has changed.
|
|||
this action assumes pushes to main are version updates. Consequently,
|
||||
[pypi-release.yml](.github/workflows/pypi-release.yml) will fail if you attempt to
|
||||
push to main without updating `__version__` in
|
||||
[cloudevents](cloudevents/__init__.py) so don't forget to do so.
|
||||
[cloudevents](cloudevents_v1/__init__.py) so don't forget to do so.
|
||||
|
||||
After a version update is merged, the script [pypi_packaging.py](pypi_packaging.py)
|
||||
will create a GitHub tag for the new cloudevents version using `__version__`.
|
||||
|
|
|
@ -16,8 +16,8 @@ import sys
|
|||
|
||||
import requests
|
||||
|
||||
from cloudevents.conversion import to_binary, to_structured
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents_v1.conversion import to_binary, to_structured
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
|
||||
resp = requests.get(
|
||||
"https://raw.githubusercontent.com/cncf/artwork/master/projects/cloudevents/horizontal/color/cloudevents-horizontal-color.png" # noqa
|
||||
|
|
|
@ -17,7 +17,7 @@ import io
|
|||
from flask import Flask, request
|
||||
from PIL import Image
|
||||
|
||||
from cloudevents.http import from_http
|
||||
from cloudevents_v1.http import from_http
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ from client import image_bytes
|
|||
from image_sample_server import app
|
||||
from PIL import Image
|
||||
|
||||
from cloudevents.conversion import to_binary, to_structured
|
||||
from cloudevents.http import CloudEvent, from_http
|
||||
from cloudevents_v1.conversion import to_binary, to_structured
|
||||
from cloudevents_v1.http import CloudEvent, from_http
|
||||
|
||||
image_fileobj = io.BytesIO(image_bytes)
|
||||
image_expected_shape = (1880, 363)
|
||||
|
|
|
@ -16,8 +16,8 @@ import sys
|
|||
|
||||
import requests
|
||||
|
||||
from cloudevents.conversion import to_binary, to_structured
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents_v1.conversion import to_binary, to_structured
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
|
||||
|
||||
def send_binary_cloud_event(url):
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
from flask import Flask, request
|
||||
|
||||
from cloudevents.http import from_http
|
||||
from cloudevents_v1.http import from_http
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
import pytest
|
||||
from json_sample_server import app
|
||||
|
||||
from cloudevents.conversion import to_binary, to_structured
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents_v1.conversion import to_binary, to_structured
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.abstract.event import AnyCloudEvent, CloudEvent
|
||||
from cloudevents_v1.abstract.event import AnyCloudEvent, CloudEvent
|
||||
|
||||
__all__ = ["AnyCloudEvent", "CloudEvent"]
|
|
@ -16,11 +16,11 @@ import enum
|
|||
import json
|
||||
import typing
|
||||
|
||||
from cloudevents import exceptions as cloud_exceptions
|
||||
from cloudevents.abstract import AnyCloudEvent
|
||||
from cloudevents.sdk import converters, marshaller, types
|
||||
from cloudevents.sdk.converters import is_binary
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents_v1 import exceptions as cloud_exceptions
|
||||
from cloudevents_v1.abstract import AnyCloudEvent
|
||||
from cloudevents_v1.sdk import converters, marshaller, types
|
||||
from cloudevents_v1.sdk.converters import is_binary
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
|
||||
|
||||
def _best_effort_serialize_to_json( # type: ignore[no-untyped-def]
|
|
@ -13,16 +13,16 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
from cloudevents.http.conversion import from_dict, from_http, from_json
|
||||
from cloudevents.http.event import CloudEvent
|
||||
from cloudevents.http.event_type import is_binary, is_structured # deprecated
|
||||
from cloudevents.http.http_methods import ( # deprecated
|
||||
from cloudevents_v1.http.conversion import from_dict, from_http, from_json
|
||||
from cloudevents_v1.http.event import CloudEvent
|
||||
from cloudevents_v1.http.event_type import is_binary, is_structured # deprecated
|
||||
from cloudevents_v1.http.http_methods import ( # deprecated
|
||||
to_binary,
|
||||
to_binary_http,
|
||||
to_structured,
|
||||
to_structured_http,
|
||||
)
|
||||
from cloudevents.http.json_methods import to_json # deprecated
|
||||
from cloudevents_v1.http.json_methods import to_json # deprecated
|
||||
|
||||
__all__ = [
|
||||
"to_binary",
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
import typing
|
||||
|
||||
from cloudevents.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents.conversion import from_http as _abstract_from_http
|
||||
from cloudevents.conversion import from_json as _abstract_from_json
|
||||
from cloudevents.http.event import CloudEvent
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents_v1.conversion import from_http as _abstract_from_http
|
||||
from cloudevents_v1.conversion import from_json as _abstract_from_json
|
||||
from cloudevents_v1.http.event import CloudEvent
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
|
||||
def from_json(
|
|
@ -16,9 +16,9 @@ import datetime
|
|||
import typing
|
||||
import uuid
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents import abstract
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1 import abstract
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
|
||||
_required_by_version = {
|
||||
"1.0": v1.Event._ce_required_fields,
|
|
@ -15,8 +15,8 @@ import typing
|
|||
|
||||
from deprecation import deprecated
|
||||
|
||||
from cloudevents.sdk.converters import is_binary as _moved_is_binary
|
||||
from cloudevents.sdk.converters import is_structured as _moved_is_structured
|
||||
from cloudevents_v1.sdk.converters import is_binary as _moved_is_binary
|
||||
from cloudevents_v1.sdk.converters import is_structured as _moved_is_structured
|
||||
|
||||
# THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE
|
||||
|
|
@ -16,12 +16,12 @@ import typing
|
|||
|
||||
from deprecation import deprecated
|
||||
|
||||
from cloudevents.abstract import AnyCloudEvent
|
||||
from cloudevents.conversion import to_binary as _moved_to_binary
|
||||
from cloudevents.conversion import to_structured as _moved_to_structured
|
||||
from cloudevents.http.conversion import from_http as _moved_from_http
|
||||
from cloudevents.http.event import CloudEvent
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.abstract import AnyCloudEvent
|
||||
from cloudevents_v1.conversion import to_binary as _moved_to_binary
|
||||
from cloudevents_v1.conversion import to_structured as _moved_to_structured
|
||||
from cloudevents_v1.http.conversion import from_http as _moved_from_http
|
||||
from cloudevents_v1.http.event import CloudEvent
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
# THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE
|
||||
|
|
@ -16,11 +16,11 @@ import typing
|
|||
|
||||
from deprecation import deprecated
|
||||
|
||||
from cloudevents.abstract import AnyCloudEvent
|
||||
from cloudevents.conversion import to_json as _moved_to_json
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents.http.conversion import from_json as _moved_from_json
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.abstract import AnyCloudEvent
|
||||
from cloudevents_v1.conversion import to_json as _moved_to_json
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
from cloudevents_v1.http.conversion import from_json as _moved_from_json
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
# THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE
|
||||
|
|
@ -15,7 +15,7 @@ import typing
|
|||
|
||||
from deprecation import deprecated
|
||||
|
||||
from cloudevents.conversion import (
|
||||
from cloudevents_v1.conversion import (
|
||||
_best_effort_serialize_to_json as _moved_default_marshaller,
|
||||
)
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.kafka.conversion import (
|
||||
from cloudevents_v1.kafka.conversion import (
|
||||
KafkaMessage,
|
||||
KeyMapper,
|
||||
from_binary,
|
|
@ -15,11 +15,11 @@ import base64
|
|||
import json
|
||||
import typing
|
||||
|
||||
from cloudevents import exceptions as cloud_exceptions
|
||||
from cloudevents import http
|
||||
from cloudevents.abstract import AnyCloudEvent
|
||||
from cloudevents.kafka.exceptions import KeyMapperError
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1 import exceptions as cloud_exceptions
|
||||
from cloudevents_v1 import http
|
||||
from cloudevents_v1.abstract import AnyCloudEvent
|
||||
from cloudevents_v1.kafka.exceptions import KeyMapperError
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
DEFAULT_MARSHALLER: types.MarshallerType = json.dumps
|
||||
DEFAULT_UNMARSHALLER: types.MarshallerType = json.loads
|
|
@ -11,7 +11,7 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from cloudevents import exceptions as cloud_exceptions
|
||||
from cloudevents_v1 import exceptions as cloud_exceptions
|
||||
|
||||
|
||||
class KeyMapperError(cloud_exceptions.GenericException):
|
|
@ -14,24 +14,24 @@
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from cloudevents.exceptions import PydanticFeatureNotInstalled
|
||||
from cloudevents_v1.exceptions import PydanticFeatureNotInstalled
|
||||
|
||||
try:
|
||||
if TYPE_CHECKING:
|
||||
from cloudevents.pydantic.v2 import CloudEvent, from_dict, from_http, from_json
|
||||
from cloudevents_v1.pydantic.v2 import CloudEvent, from_dict, from_http, from_json
|
||||
else:
|
||||
from pydantic import VERSION as PYDANTIC_VERSION
|
||||
|
||||
pydantic_major_version = PYDANTIC_VERSION.split(".")[0]
|
||||
if pydantic_major_version == "1":
|
||||
from cloudevents.pydantic.v1 import (
|
||||
from cloudevents_v1.pydantic.v1 import (
|
||||
CloudEvent,
|
||||
from_dict,
|
||||
from_http,
|
||||
from_json,
|
||||
)
|
||||
else:
|
||||
from cloudevents.pydantic.v2 import (
|
||||
from cloudevents_v1.pydantic.v2 import (
|
||||
CloudEvent,
|
||||
from_dict,
|
||||
from_http,
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.sdk.event import attribute
|
||||
from cloudevents_v1.sdk.event import attribute
|
||||
|
||||
FIELD_DESCRIPTIONS = {
|
||||
"data": {
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.pydantic.v2.conversion import from_dict, from_http, from_json
|
||||
from cloudevents.pydantic.v2.event import CloudEvent
|
||||
from cloudevents_v1.pydantic.v1.conversion import from_dict, from_http, from_json
|
||||
from cloudevents_v1.pydantic.v1.event import CloudEvent
|
||||
|
||||
__all__ = ["CloudEvent", "from_json", "from_dict", "from_http"]
|
|
@ -13,11 +13,11 @@
|
|||
# under the License.
|
||||
import typing
|
||||
|
||||
from cloudevents.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents.conversion import from_http as _abstract_from_http
|
||||
from cloudevents.conversion import from_json as _abstract_from_json
|
||||
from cloudevents.pydantic.v1.event import CloudEvent
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents_v1.conversion import from_http as _abstract_from_http
|
||||
from cloudevents_v1.conversion import from_json as _abstract_from_json
|
||||
from cloudevents_v1.pydantic.v1.event import CloudEvent
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
|
||||
def from_http(
|
|
@ -15,8 +15,8 @@ import datetime
|
|||
import json
|
||||
import typing
|
||||
|
||||
from cloudevents.exceptions import PydanticFeatureNotInstalled
|
||||
from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS
|
||||
from cloudevents_v1.exceptions import PydanticFeatureNotInstalled
|
||||
from cloudevents_v1.pydantic.fields_docs import FIELD_DESCRIPTIONS
|
||||
|
||||
try:
|
||||
from pydantic import VERSION as PYDANTIC_VERSION
|
||||
|
@ -32,9 +32,9 @@ except ImportError: # pragma: no cover # hard to test
|
|||
"Install it using pip install cloudevents[pydantic]"
|
||||
)
|
||||
|
||||
from cloudevents import abstract, conversion, http
|
||||
from cloudevents.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents.sdk.event import attribute
|
||||
from cloudevents_v1 import abstract, conversion, http
|
||||
from cloudevents_v1.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents_v1.sdk.event import attribute
|
||||
|
||||
|
||||
def _ce_json_dumps( # type: ignore[no-untyped-def]
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.pydantic.v1.conversion import from_dict, from_http, from_json
|
||||
from cloudevents.pydantic.v1.event import CloudEvent
|
||||
from cloudevents_v1.pydantic.v2.conversion import from_dict, from_http, from_json
|
||||
from cloudevents_v1.pydantic.v2.event import CloudEvent
|
||||
|
||||
__all__ = ["CloudEvent", "from_json", "from_dict", "from_http"]
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
import typing
|
||||
|
||||
from cloudevents.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents.conversion import from_http as _abstract_from_http
|
||||
from cloudevents.conversion import from_json as _abstract_from_json
|
||||
from cloudevents.pydantic.v2.event import CloudEvent
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.conversion import from_dict as _abstract_from_dict
|
||||
from cloudevents_v1.conversion import from_http as _abstract_from_http
|
||||
from cloudevents_v1.conversion import from_json as _abstract_from_json
|
||||
from cloudevents_v1.pydantic.v2.event import CloudEvent
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
|
||||
def from_http(
|
|
@ -19,8 +19,8 @@ from typing import Any
|
|||
|
||||
from pydantic.deprecated import parse as _deprecated_parse
|
||||
|
||||
from cloudevents.exceptions import PydanticFeatureNotInstalled
|
||||
from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS
|
||||
from cloudevents_v1.exceptions import PydanticFeatureNotInstalled
|
||||
from cloudevents_v1.pydantic.fields_docs import FIELD_DESCRIPTIONS
|
||||
|
||||
try:
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_serializer
|
||||
|
@ -30,9 +30,9 @@ except ImportError: # pragma: no cover # hard to test
|
|||
"Install it using pip install cloudevents[pydantic]"
|
||||
)
|
||||
|
||||
from cloudevents import abstract, conversion
|
||||
from cloudevents.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents.sdk.event import attribute
|
||||
from cloudevents_v1 import abstract, conversion
|
||||
from cloudevents_v1.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents_v1.sdk.event import attribute
|
||||
|
||||
|
||||
class CloudEvent(abstract.CloudEvent, BaseModel): # type: ignore
|
|
@ -12,9 +12,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.sdk.converters import binary, structured
|
||||
from cloudevents.sdk.converters.binary import is_binary
|
||||
from cloudevents.sdk.converters.structured import is_structured
|
||||
from cloudevents_v1.sdk.converters import binary, structured
|
||||
from cloudevents_v1.sdk.converters.binary import is_binary
|
||||
from cloudevents_v1.sdk.converters.structured import is_structured
|
||||
|
||||
TypeBinary: str = binary.BinaryHTTPCloudEventConverter.TYPE
|
||||
TypeStructured: str = structured.JSONHTTPCloudEventConverter.TYPE
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk.event import base
|
||||
from cloudevents_v1.sdk.event import base
|
||||
|
||||
|
||||
class Converter(object):
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk import exceptions, types
|
||||
from cloudevents.sdk.converters import base
|
||||
from cloudevents.sdk.converters.util import has_binary_headers
|
||||
from cloudevents.sdk.event import base as event_base
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents_v1.sdk import exceptions, types
|
||||
from cloudevents_v1.sdk.converters import base
|
||||
from cloudevents_v1.sdk.converters.util import has_binary_headers
|
||||
from cloudevents_v1.sdk.event import base as event_base
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
|
||||
|
||||
class BinaryHTTPCloudEventConverter(base.Converter):
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents.sdk.converters import base
|
||||
from cloudevents.sdk.converters.util import has_binary_headers
|
||||
from cloudevents.sdk.event import base as event_base
|
||||
from cloudevents_v1.sdk import types
|
||||
from cloudevents_v1.sdk.converters import base
|
||||
from cloudevents_v1.sdk.converters.util import has_binary_headers
|
||||
from cloudevents_v1.sdk.event import base as event_base
|
||||
|
||||
|
||||
# TODO: Singleton?
|
|
@ -17,8 +17,8 @@ import json
|
|||
import typing
|
||||
from typing import Set
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.sdk import types
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
# TODO(slinkydeveloper) is this really needed?
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
# under the License.
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk.event import base, opt
|
||||
from cloudevents_v1.sdk.event import base, opt
|
||||
|
||||
|
||||
class Event(base.BaseEvent):
|
|
@ -13,7 +13,7 @@
|
|||
# under the License.
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk.event import base, opt
|
||||
from cloudevents_v1.sdk.event import base, opt
|
||||
|
||||
|
||||
class Event(base.BaseEvent):
|
|
@ -15,9 +15,9 @@
|
|||
import json
|
||||
import typing
|
||||
|
||||
from cloudevents.sdk import exceptions, types
|
||||
from cloudevents.sdk.converters import base, binary, structured
|
||||
from cloudevents.sdk.event import base as event_base
|
||||
from cloudevents_v1.sdk import exceptions, types
|
||||
from cloudevents_v1.sdk.converters import base, binary, structured
|
||||
from cloudevents_v1.sdk.event import base as event_base
|
||||
|
||||
|
||||
class HTTPMarshaller(object):
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
|
||||
content_type = "application/json"
|
||||
ce_type = "word.found.exclamation"
|
|
@ -13,8 +13,8 @@
|
|||
# under the License.
|
||||
import pytest
|
||||
|
||||
from cloudevents.conversion import _best_effort_serialize_to_json
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents_v1.conversion import _best_effort_serialize_to_json
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
@ -23,10 +23,10 @@ def dummy_event():
|
|||
|
||||
|
||||
def test_json_methods(dummy_event):
|
||||
from cloudevents.conversion import to_json
|
||||
from cloudevents.http.conversion import from_json
|
||||
from cloudevents.http.json_methods import from_json as deprecated_from_json
|
||||
from cloudevents.http.json_methods import to_json as deprecated_to_json
|
||||
from cloudevents_v1.conversion import to_json
|
||||
from cloudevents_v1.http.conversion import from_json
|
||||
from cloudevents_v1.http.json_methods import from_json as deprecated_from_json
|
||||
from cloudevents_v1.http.json_methods import to_json as deprecated_to_json
|
||||
|
||||
assert from_json(to_json(dummy_event)) == deprecated_from_json(
|
||||
deprecated_to_json(dummy_event)
|
||||
|
@ -34,10 +34,10 @@ def test_json_methods(dummy_event):
|
|||
|
||||
|
||||
def test_http_methods(dummy_event):
|
||||
from cloudevents.http import from_http, to_binary, to_structured
|
||||
from cloudevents.http.http_methods import from_http as deprecated_from_http
|
||||
from cloudevents.http.http_methods import to_binary as deprecated_to_binary
|
||||
from cloudevents.http.http_methods import to_structured as deprecated_to_structured
|
||||
from cloudevents_v1.http import from_http, to_binary, to_structured
|
||||
from cloudevents_v1.http.http_methods import from_http as deprecated_from_http
|
||||
from cloudevents_v1.http.http_methods import to_binary as deprecated_to_binary
|
||||
from cloudevents_v1.http.http_methods import to_structured as deprecated_to_structured
|
||||
|
||||
assert from_http(*to_binary(dummy_event)) == deprecated_from_http(
|
||||
*deprecated_to_binary(dummy_event)
|
||||
|
@ -48,17 +48,17 @@ def test_http_methods(dummy_event):
|
|||
|
||||
|
||||
def test_util():
|
||||
from cloudevents.http.util import default_marshaller # noqa
|
||||
from cloudevents_v1.http.util import default_marshaller # noqa
|
||||
|
||||
assert _best_effort_serialize_to_json(None) == default_marshaller(None)
|
||||
|
||||
|
||||
def test_event_type():
|
||||
from cloudevents.http.event_type import is_binary, is_structured # noqa
|
||||
from cloudevents_v1.http.event_type import is_binary, is_structured # noqa
|
||||
|
||||
|
||||
def test_http_module_imports():
|
||||
from cloudevents.http import ( # noqa
|
||||
from cloudevents_v1.http import ( # noqa
|
||||
CloudEvent,
|
||||
from_dict,
|
||||
from_http,
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
import pytest
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_class", [v1.Event, v03.Event])
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk import exceptions
|
||||
from cloudevents.sdk.converters import base, binary
|
||||
from cloudevents_v1.sdk import exceptions
|
||||
from cloudevents_v1.sdk.converters import base, binary
|
||||
|
||||
|
||||
def test_binary_converter_raise_unsupported():
|
|
@ -17,9 +17,9 @@ from uuid import uuid4
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk import converters, marshaller
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents.tests import data
|
||||
from cloudevents_v1.sdk import converters, marshaller
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
from cloudevents_v1.tests import data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_class", [v03.Event, v1.Event])
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.http import (
|
||||
from cloudevents_v1.http import (
|
||||
CloudEvent,
|
||||
to_binary,
|
||||
to_binary_http,
|
|
@ -16,7 +16,7 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.http import CloudEvent, from_http, to_binary, to_structured
|
||||
from cloudevents_v1.http import CloudEvent, from_http, to_binary, to_structured
|
||||
|
||||
test_data = json.dumps({"data-key": "val"})
|
||||
test_attributes = {
|
|
@ -16,10 +16,10 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk import marshaller
|
||||
from cloudevents.sdk.converters import binary, structured
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents.tests import data
|
||||
from cloudevents_v1.sdk import marshaller
|
||||
from cloudevents_v1.sdk.converters import binary, structured
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
from cloudevents_v1.tests import data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_class", [v03.Event, v1.Event])
|
|
@ -16,10 +16,10 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk import converters, marshaller
|
||||
from cloudevents.sdk.converters import structured
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents.tests import data
|
||||
from cloudevents_v1.sdk import converters, marshaller
|
||||
from cloudevents_v1.sdk.converters import structured
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
from cloudevents_v1.tests import data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_class", [v03.Event, v1.Event])
|
|
@ -16,9 +16,9 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk import converters, marshaller
|
||||
from cloudevents.sdk.event import v1, v03
|
||||
from cloudevents.tests import data
|
||||
from cloudevents_v1.sdk import converters, marshaller
|
||||
from cloudevents_v1.sdk.event import v1, v03
|
||||
from cloudevents_v1.tests import data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("event_class", [v03.Event, v1.Event])
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
import pytest
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.conversion import _json_or_string
|
||||
from cloudevents.http import CloudEvent
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.conversion import _json_or_string
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
|
||||
|
||||
@pytest.fixture(params=["0.3", "1.0"])
|
|
@ -18,9 +18,9 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.conversion import to_dict, to_json
|
||||
from cloudevents.http import CloudEvent, from_dict, from_json
|
||||
from cloudevents.sdk.event.attribute import SpecVersion
|
||||
from cloudevents_v1.conversion import to_dict, to_json
|
||||
from cloudevents_v1.http import CloudEvent, from_dict, from_json
|
||||
from cloudevents_v1.sdk.event.attribute import SpecVersion
|
||||
|
||||
test_data = json.dumps({"data-key": "val"})
|
||||
test_attributes = {
|
|
@ -20,13 +20,13 @@ import typing
|
|||
import pytest
|
||||
from sanic import Sanic, response
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.http import CloudEvent, from_http, to_binary, to_structured
|
||||
from cloudevents.http.event_type import is_binary as deprecated_is_binary
|
||||
from cloudevents.http.event_type import is_structured as deprecated_is_structured
|
||||
from cloudevents.sdk import converters
|
||||
from cloudevents.sdk.converters.binary import is_binary
|
||||
from cloudevents.sdk.converters.structured import is_structured
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.http import CloudEvent, from_http, to_binary, to_structured
|
||||
from cloudevents_v1.http.event_type import is_binary as deprecated_is_binary
|
||||
from cloudevents_v1.http.event_type import is_structured as deprecated_is_structured
|
||||
from cloudevents_v1.sdk import converters
|
||||
from cloudevents_v1.sdk.converters.binary import is_binary
|
||||
from cloudevents_v1.sdk.converters.structured import is_structured
|
||||
|
||||
invalid_test_headers = [
|
||||
{
|
|
@ -18,17 +18,17 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents import exceptions as cloud_exceptions
|
||||
from cloudevents.http import CloudEvent
|
||||
from cloudevents.kafka.conversion import (
|
||||
from cloudevents_v1 import exceptions as cloud_exceptions
|
||||
from cloudevents_v1.http import CloudEvent
|
||||
from cloudevents_v1.kafka.conversion import (
|
||||
KafkaMessage,
|
||||
from_binary,
|
||||
from_structured,
|
||||
to_binary,
|
||||
to_structured,
|
||||
)
|
||||
from cloudevents.kafka.exceptions import KeyMapperError
|
||||
from cloudevents.sdk import types
|
||||
from cloudevents_v1.kafka.exceptions import KeyMapperError
|
||||
from cloudevents_v1.sdk import types
|
||||
|
||||
|
||||
def simple_serialize(data: dict) -> bytes:
|
|
@ -16,11 +16,11 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.http import CloudEvent, from_http, to_binary, to_structured
|
||||
from cloudevents.sdk import exceptions, marshaller
|
||||
from cloudevents.sdk.converters import binary, structured
|
||||
from cloudevents.sdk.event import v1
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.http import CloudEvent, from_http, to_binary, to_structured
|
||||
from cloudevents_v1.sdk import exceptions, marshaller
|
||||
from cloudevents_v1.sdk.converters import binary, structured
|
||||
from cloudevents_v1.sdk.event import v1
|
||||
|
||||
|
||||
@pytest.fixture
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from cloudevents.sdk.event.opt import Option
|
||||
from cloudevents_v1.sdk.event.opt import Option
|
||||
|
||||
|
||||
def test_set_raise_error():
|
|
@ -18,11 +18,11 @@ import pytest
|
|||
from pydantic import ValidationError as PydanticV2ValidationError
|
||||
from pydantic.v1 import ValidationError as PydanticV1ValidationError
|
||||
|
||||
from cloudevents.conversion import _json_or_string
|
||||
from cloudevents.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents.sdk.event.attribute import SpecVersion
|
||||
from cloudevents_v1.conversion import _json_or_string
|
||||
from cloudevents_v1.exceptions import IncompatibleArgumentsError
|
||||
from cloudevents_v1.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents_v1.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents_v1.sdk.event.attribute import SpecVersion
|
||||
|
||||
_DUMMY_SOURCE = "dummy:source"
|
||||
_DUMMY_TYPE = "tests.cloudevents.override"
|
|
@ -20,14 +20,14 @@ import pytest
|
|||
from pydantic import ValidationError as PydanticV2ValidationError
|
||||
from pydantic.v1 import ValidationError as PydanticV1ValidationError
|
||||
|
||||
from cloudevents.conversion import to_json
|
||||
from cloudevents.pydantic.v1.conversion import from_dict as pydantic_v1_from_dict
|
||||
from cloudevents.pydantic.v1.conversion import from_json as pydantic_v1_from_json
|
||||
from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents.pydantic.v2.conversion import from_dict as pydantic_v2_from_dict
|
||||
from cloudevents.pydantic.v2.conversion import from_json as pydantic_v2_from_json
|
||||
from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents.sdk.event.attribute import SpecVersion
|
||||
from cloudevents_v1.conversion import to_json
|
||||
from cloudevents_v1.pydantic.v1.conversion import from_dict as pydantic_v1_from_dict
|
||||
from cloudevents_v1.pydantic.v1.conversion import from_json as pydantic_v1_from_json
|
||||
from cloudevents_v1.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents_v1.pydantic.v2.conversion import from_dict as pydantic_v2_from_dict
|
||||
from cloudevents_v1.pydantic.v2.conversion import from_json as pydantic_v2_from_json
|
||||
from cloudevents_v1.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents_v1.sdk.event.attribute import SpecVersion
|
||||
|
||||
test_data = json.dumps({"data-key": "val"})
|
||||
test_attributes = {
|
|
@ -22,15 +22,15 @@ from pydantic import ValidationError as PydanticV2ValidationError
|
|||
from pydantic.v1 import ValidationError as PydanticV1ValidationError
|
||||
from sanic import Sanic, response
|
||||
|
||||
import cloudevents.exceptions as cloud_exceptions
|
||||
from cloudevents.conversion import to_binary, to_structured
|
||||
from cloudevents.pydantic.v1.conversion import from_http as pydantic_v1_from_http
|
||||
from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents.pydantic.v2.conversion import from_http as pydantic_v2_from_http
|
||||
from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents.sdk import converters
|
||||
from cloudevents.sdk.converters.binary import is_binary
|
||||
from cloudevents.sdk.converters.structured import is_structured
|
||||
import cloudevents_v1.exceptions as cloud_exceptions
|
||||
from cloudevents_v1.conversion import to_binary, to_structured
|
||||
from cloudevents_v1.pydantic.v1.conversion import from_http as pydantic_v1_from_http
|
||||
from cloudevents_v1.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent
|
||||
from cloudevents_v1.pydantic.v2.conversion import from_http as pydantic_v2_from_http
|
||||
from cloudevents_v1.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent
|
||||
from cloudevents_v1.sdk import converters
|
||||
from cloudevents_v1.sdk.converters.binary import is_binary
|
||||
from cloudevents_v1.sdk.converters.structured import is_structured
|
||||
|
||||
invalid_test_headers = [
|
||||
{
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.sdk.event import v03
|
||||
from cloudevents_v1.sdk.event import v03
|
||||
|
||||
|
||||
def test_v03_time_property():
|
|
@ -12,7 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudevents.sdk.event import v1
|
||||
from cloudevents_v1.sdk.event import v1
|
||||
|
||||
|
||||
def test_v1_time_property():
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
from sanic import Sanic, response
|
||||
|
||||
from cloudevents.sdk import converters, marshaller
|
||||
from cloudevents.sdk.event import v1
|
||||
from cloudevents.tests import data as test_data
|
||||
from cloudevents_v1.sdk import converters, marshaller
|
||||
from cloudevents_v1.sdk.event import v1
|
||||
from cloudevents_v1.tests import data as test_data
|
||||
|
||||
m = marshaller.NewDefaultHTTPMarshaller()
|
||||
app = Sanic("test_with_sanic")
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright 2018-Present The CloudEvents Authors
|
||||
#
|
||||
# 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.
|
||||
|
||||
from cloudevents import __version__
|
||||
|
||||
|
||||
def test_cloudevents_version():
|
||||
assert __version__ is not None
|
Loading…
Reference in New Issue