Repository: cloudevents/sdk-python

Issue:
CloudEvent needs __eq__ overload to be supported
## Expected Behavior
```python
event = from_http(request.get_data(), request.headers)
event1 = from_http(request.get_data(), request.headers)
assert event == event1
```
I would expect this to pass as we are passing in the same fields into both objects

## Actual Behavior
Assertion error because cloudevent does not support equality overload

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa8f3a1..8a66cf3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [1.0.1]
+### Added
+- CloudEvent equality override ([#98])
+
 ## [1.0.0]
 ### Added
 - Added a user friendly CloudEvent class with data validation ([#36])
@@ -77,3 +81,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 [#36]: https://github.com/cloudevents/sdk-python/pull/36
 [#43]: https://github.com/cloudevents/sdk-python/pull/43
 [#47]: https://github.com/cloudevents/sdk-python/pull/47
+[#98]: https://github.com/cloudevents/sdk-python/pull/98
\ No newline at end of file
diff --git a/cloudevents/__init__.py b/cloudevents/__init__.py
index 5becc17..5c4105c 100644
--- a/cloudevents/__init__.py
+++ b/cloudevents/__init__.py
@@ -1,1 +1,1 @@
-__version__ = "1.0.0"
+__version__ = "1.0.1"
diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py
index a31b894..9cb4400 100644
--- a/cloudevents/http/event.py
+++ b/cloudevents/http/event.py
@@ -68,6 +68,9 @@ class CloudEvent:
                 f"Missing required keys: {required_set - 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):


Test patch:
diff --git a/cloudevents/tests/test_http_cloudevent_overrides.py b/cloudevents/tests/test_http_cloudevent_overrides.py
new file mode 100644
index 0000000..1babbe2
--- /dev/null
+++ b/cloudevents/tests/test_http_cloudevent_overrides.py
@@ -0,0 +1,71 @@
+import pytest
+
+from cloudevents.http import CloudEvent
+
+
+@pytest.mark.parametrize("specversion", ["0.3", "1.0"])
+def test_http_cloudevent_equality(specversion):
+    attributes = {
+        "source": "<source>",
+        "specversion": specversion,
+        "id": "my-id",
+        "time": "tomorrow",
+        "type": "tests.cloudevents.override",
+        "datacontenttype": "application/json",
+        "subject": "my-subject",
+    }
+    data = '{"name":"john"}'
+    event1 = CloudEvent(attributes, data)
+    event2 = CloudEvent(attributes, data)
+    assert event1 == event2
+    # Test different attributes
+    for key in attributes:
+        if key == "specversion":
+            continue
+        else:
+            attributes[key] = f"noise-{key}"
+        event3 = CloudEvent(attributes, data)
+        event2 = CloudEvent(attributes, data)
+        assert event2 == event3
+        assert event1 != event2 and event3 != event1
+
+    # Test different data
+    data = '{"name":"paul"}'
+    event3 = CloudEvent(attributes, data)
+    event2 = CloudEvent(attributes, data)
+    assert event2 == event3
+    assert event1 != event2 and event3 != event1
+
+
+@pytest.mark.parametrize("specversion", ["0.3", "1.0"])
+def test_http_cloudevent_mutates_equality(specversion):
+    attributes = {
+        "source": "<source>",
+        "specversion": specversion,
+        "id": "my-id",
+        "time": "tomorrow",
+        "type": "tests.cloudevents.override",
+        "datacontenttype": "application/json",
+        "subject": "my-subject",
+    }
+    data = '{"name":"john"}'
+    event1 = CloudEvent(attributes, data)
+    event2 = CloudEvent(attributes, data)
+    event3 = CloudEvent(attributes, data)
+
+    assert event1 == event2
+    # Test different attributes
+    for key in attributes:
+        if key == "specversion":
+            continue
+        else:
+            event2[key] = f"noise-{key}"
+            event3[key] = f"noise-{key}"
+        assert event2 == event3
+        assert event1 != event2 and event3 != event1
+
+    # Test different data
+    event2.data = '{"name":"paul"}'
+    event3.data = '{"name":"paul"}'
+    assert event2 == event3
+    assert event1 != event2 and event3 != event1