# Path: cloudevents/http/event.py
# class CloudEvent:
#     """
#     Python-friendly cloudevent class supporting v1 events
#     Supports both binary and structured mode CloudEvents
#     """
# 
#     def __init__(
#         self, attributes: typing.Dict[str, str], data: typing.Any = None
#     ):
#         """
#         Event Constructor
#         :param attributes: a dict with cloudevent attributes. Minimally
#             expects the attributes 'type' and 'source'. If not given the
#             attributes 'specversion', 'id' or 'time', this will create
#             those attributes with default values.
#             e.g. {
#                 "content-type": "application/cloudevents+json",
#                 "id": "16fb5f0b-211e-1102-3dfe-ea6e2806f124",
#                 "source": "<event-source>",
#                 "type": "cloudevent.event.type",
#                 "specversion": "0.2"
#             }
#         :type attributes: typing.Dict[str, str]
#         :param data: The payload of the event, as a python object
#         :type data: typing.Any
#         """
#         self._attributes = {k.lower(): v for k, v in attributes.items()}
#         self.data = data
#         if "specversion" not in self._attributes:
#             self._attributes["specversion"] = "1.0"
#         if "id" not in self._attributes:
#             self._attributes["id"] = str(uuid.uuid4())
#         if "time" not in self._attributes:
#             self._attributes["time"] = datetime.datetime.now(
#                 datetime.timezone.utc
#             ).isoformat()
# 
#         if self._attributes["specversion"] not in _required_by_version:
#             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.MissingRequiredFields(
#                 f"Missing required keys: {required_set - self._attributes.keys()}"
#             )
# 
#     def __eq__(self, other):
#         return self.data == other.data and self._attributes == other._attributes
# 
#     # Data access is handled via `.data` member
#     # Attribute access is managed via Mapping type
#     def __getitem__(self, key):
#         return self._attributes[key]
# 
#     def __setitem__(self, key, value):
#         self._attributes[key] = value
# 
#     def __delitem__(self, key):
#         del self._attributes[key]
# 
#     def __iter__(self):
#         return iter(self._attributes)
# 
#     def __len__(self):
#         return len(self._attributes)
# 
#     def __contains__(self, key):
#         return key in self._attributes
# 
#     def __repr__(self):
#         return str({"attributes": self._attributes, "data": self.data})
# 
# Path: cloudevents/http/util.py
# def _json_or_string(content: typing.Union[str, bytes]):
#     if content is None:
#         return None
#     try:
#         return json.loads(content)
#     except (json.JSONDecodeError, TypeError):
#         return content


import pytest
import cloudevents.exceptions as cloud_exceptions
from cloudevents.http import CloudEvent
from cloudevents.http.util import _json_or_string
        _ = CloudEvent(attributes, None)
    assert f"Missing required keys: {set(['type'])}" in str(e.value)


def test_cloudevent_general_overrides():
    event = CloudEvent(
        {
            "source": "my-source",
            "type": "com.test.overrides",
            "subject": "my-subject",
        },
        None,
    )
    expected_attributes = [
        "time",
        "source",
        "id",
        "specversion",
        "type",
        "subject",
    ]

    assert len(event) == 6
    for attribute in expected_attributes:
        assert attribute in event
        del event[attribute]
    assert len(event) == 0


def test_none_json_or_string():

# Path: cloudevents/http/event.py
# class CloudEvent:
#     """
#     Python-friendly cloudevent class supporting v1 events
#     Supports both binary and structured mode CloudEvents
#     """
# 
#     def __init__(
#         self, attributes: typing.Dict[str, str], data: typing.Any = None
#     ):
#         """
#         Event Constructor
#         :param attributes: a dict with cloudevent attributes. Minimally
#             expects the attributes 'type' and 'source'. If not given the
#             attributes 'specversion', 'id' or 'time', this will create
#             those attributes with default values.
#             e.g. {
#                 "content-type": "application/cloudevents+json",
#                 "id": "16fb5f0b-211e-1102-3dfe-ea6e2806f124",
#                 "source": "<event-source>",
#                 "type": "cloudevent.event.type",
#                 "specversion": "0.2"
#             }
#         :type attributes: typing.Dict[str, str]
#         :param data: The payload of the event, as a python object
#         :type data: typing.Any
#         """
#         self._attributes = {k.lower(): v for k, v in attributes.items()}
#         self.data = data
#         if "specversion" not in self._attributes:
#             self._attributes["specversion"] = "1.0"
#         if "id" not in self._attributes:
#             self._attributes["id"] = str(uuid.uuid4())
#         if "time" not in self._attributes:
#             self._attributes["time"] = datetime.datetime.now(
#                 datetime.timezone.utc
#             ).isoformat()
# 
#         if self._attributes["specversion"] not in _required_by_version:
#             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.MissingRequiredFields(
#                 f"Missing required keys: {required_set - self._attributes.keys()}"
#             )
# 
#     def __eq__(self, other):
#         return self.data == other.data and self._attributes == other._attributes
# 
#     # Data access is handled via `.data` member
#     # Attribute access is managed via Mapping type
#     def __getitem__(self, key):
#         return self._attributes[key]
# 
#     def __setitem__(self, key, value):
#         self._attributes[key] = value
# 
#     def __delitem__(self, key):
#         del self._attributes[key]
# 
#     def __iter__(self):
#         return iter(self._attributes)
# 
#     def __len__(self):
#         return len(self._attributes)
# 
#     def __contains__(self, key):
#         return key in self._attributes
# 
#     def __repr__(self):
#         return str({"attributes": self._attributes, "data": self.data})
# 
# Path: cloudevents/http/util.py
# def _json_or_string(content: typing.Union[str, bytes]):
#     if content is None:
#         return None
#     try:
#         return json.loads(content)
#     except (json.JSONDecodeError, TypeError):
#         return content


# Path: cloudevents/tests/test_http_cloudevent.py
import pytest
import cloudevents.exceptions as cloud_exceptions
from cloudevents.http import CloudEvent
from cloudevents.http.util import _json_or_string

        _ = CloudEvent(attributes, None)
    assert f"Missing required keys: {set(['type'])}" in str(e.value)


def test_cloudevent_general_overrides():
    event = CloudEvent(
        {
            "source": "my-source",
            "type": "com.test.overrides",
            "subject": "my-subject",
        },
        None,
    )
    expected_attributes = [
        "time",
        "source",
        "id",
        "specversion",
        "type",
        "subject",
    ]

    assert len(event) == 6
    for attribute in expected_attributes:
        assert attribute in event
        del event[attribute]
    assert len(event) == 0


def test_none_json_or_string():

    assert _json_or_string(None) is None