Add sensible __eq__ operators inside the tests.
Rather than adding them globally. This limits the changes to only affect the tests.
This commit is contained in:
parent
60ec9793fb
commit
57fa1801c3
|
@ -36,10 +36,6 @@ class _EventInternalMetadata(object):
|
||||||
def is_invite_from_remote(self):
|
def is_invite_from_remote(self):
|
||||||
return getattr(self, "invite_from_remote", False)
|
return getattr(self, "invite_from_remote", False)
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
"Equality check for unit tests."
|
|
||||||
return self.__dict__ == other.__dict__
|
|
||||||
|
|
||||||
|
|
||||||
def _event_dict_property(key):
|
def _event_dict_property(key):
|
||||||
def getter(self):
|
def getter(self):
|
||||||
|
@ -184,8 +180,3 @@ class FrozenEvent(EventBase):
|
||||||
self.get("type", None),
|
self.get("type", None),
|
||||||
self.get("state_key", None),
|
self.get("state_key", None),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
"""Equality check for unit tests. Compares internal_metadata as well
|
|
||||||
as the event fields"""
|
|
||||||
return self.__dict__ == other.__dict__
|
|
||||||
|
|
|
@ -14,20 +14,47 @@
|
||||||
|
|
||||||
from ._base import BaseSlavedStoreTestCase
|
from ._base import BaseSlavedStoreTestCase
|
||||||
|
|
||||||
from synapse.events import FrozenEvent
|
from synapse.events import FrozenEvent, _EventInternalMetadata
|
||||||
from synapse.events.snapshot import EventContext
|
from synapse.events.snapshot import EventContext
|
||||||
from synapse.storage.roommember import RoomsForUser
|
from synapse.storage.roommember import RoomsForUser
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
|
||||||
USER_ID = "@feeling:blue"
|
USER_ID = "@feeling:blue"
|
||||||
USER_ID_2 = "@bright:blue"
|
USER_ID_2 = "@bright:blue"
|
||||||
OUTLIER = {"outlier": True}
|
OUTLIER = {"outlier": True}
|
||||||
ROOM_ID = "!room:blue"
|
ROOM_ID = "!room:blue"
|
||||||
|
|
||||||
|
|
||||||
|
def dict_equals(self, other):
|
||||||
|
return self.__dict__ == other.__dict__
|
||||||
|
|
||||||
|
|
||||||
|
def patch__eq__(cls):
|
||||||
|
eq = getattr(cls, "__eq__", None)
|
||||||
|
cls.__eq__ = dict_equals
|
||||||
|
|
||||||
|
def unpatch():
|
||||||
|
if eq is not None:
|
||||||
|
cls.__eq__ = eq
|
||||||
|
return unpatch
|
||||||
|
|
||||||
|
|
||||||
class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
|
class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# Patch up the equality operator for events so that we can check
|
||||||
|
# whether lists of events match using assertEquals
|
||||||
|
self.unpatches = [
|
||||||
|
patch__eq__(_EventInternalMetadata),
|
||||||
|
patch__eq__(FrozenEvent),
|
||||||
|
]
|
||||||
|
return super(SlavedEventStoreTestCase, self).setUp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
[unpatch() for unpatch in self.unpatches]
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_room_name_and_aliases(self):
|
def test_room_name_and_aliases(self):
|
||||||
create = yield self.persist(type="m.room.create", key="", creator=USER_ID)
|
create = yield self.persist(type="m.room.create", key="", creator=USER_ID)
|
||||||
|
|
Loading…
Reference in New Issue