mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-19 08:24:25 +01:00
Add more integration testing
This commit is contained in:
parent
395683add1
commit
fe51d6cacf
2 changed files with 40 additions and 7 deletions
|
@ -872,7 +872,7 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
|
||||||
args.append(int(limit))
|
args.append(int(limit))
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT event_id, topological_ordering, stream_ordering"
|
"SELECT DISTINCT event_id, topological_ordering, stream_ordering"
|
||||||
" FROM events"
|
" FROM events"
|
||||||
" LEFT JOIN event_labels USING (event_id)"
|
" LEFT JOIN event_labels USING (event_id)"
|
||||||
" WHERE outlier = ? AND room_id = ? AND %(bounds)s"
|
" WHERE outlier = ? AND room_id = ? AND %(bounds)s"
|
||||||
|
|
|
@ -85,6 +85,7 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_sync_filter_labels(self):
|
def test_sync_filter_labels(self):
|
||||||
|
"""Test that we can filter by a label."""
|
||||||
sync_filter = json.dumps(
|
sync_filter = json.dumps(
|
||||||
{
|
{
|
||||||
"room": {
|
"room": {
|
||||||
|
@ -98,11 +99,12 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
events = self._test_sync_filter_labels(sync_filter)
|
events = self._test_sync_filter_labels(sync_filter)
|
||||||
|
|
||||||
self.assertEqual(len(events), 2, events)
|
self.assertEqual(len(events), 2, [event["content"] for event in events])
|
||||||
self.assertEqual(events[0]["content"]["body"], "with label", events[0])
|
self.assertEqual(events[0]["content"]["body"], "with right label", events[0])
|
||||||
self.assertEqual(events[1]["content"]["body"], "with label", events[1])
|
self.assertEqual(events[1]["content"]["body"], "with right label", events[1])
|
||||||
|
|
||||||
def test_sync_filter_not_labels(self):
|
def test_sync_filter_not_labels(self):
|
||||||
|
"""Test that we can filter by the absence of a label."""
|
||||||
sync_filter = json.dumps(
|
sync_filter = json.dumps(
|
||||||
{
|
{
|
||||||
"room": {
|
"room": {
|
||||||
|
@ -116,9 +118,29 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
events = self._test_sync_filter_labels(sync_filter)
|
events = self._test_sync_filter_labels(sync_filter)
|
||||||
|
|
||||||
self.assertEqual(len(events), 2, events)
|
self.assertEqual(len(events), 3, [event["content"] for event in events])
|
||||||
self.assertEqual(events[0]["content"]["body"], "without label", events[0])
|
self.assertEqual(events[0]["content"]["body"], "without label", events[0])
|
||||||
self.assertEqual(events[1]["content"]["body"], "with wrong label", events[1])
|
self.assertEqual(events[1]["content"]["body"], "with wrong label", events[1])
|
||||||
|
self.assertEqual(events[2]["content"]["body"], "with two wrong labels", events[2])
|
||||||
|
|
||||||
|
def test_sync_filter_labels_not_labels(self):
|
||||||
|
"""Test that we can filter by both a label and the absence of another label."""
|
||||||
|
sync_filter = json.dumps(
|
||||||
|
{
|
||||||
|
"room": {
|
||||||
|
"timeline": {
|
||||||
|
"types": [EventTypes.Message],
|
||||||
|
"org.matrix.labels": ["#work"],
|
||||||
|
"org.matrix.not_labels": ["#notfun"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
events = self._test_sync_filter_labels(sync_filter)
|
||||||
|
|
||||||
|
self.assertEqual(len(events), 1, [event["content"] for event in events])
|
||||||
|
self.assertEqual(events[0]["content"]["body"], "with wrong label", events[0])
|
||||||
|
|
||||||
def _test_sync_filter_labels(self, sync_filter):
|
def _test_sync_filter_labels(self, sync_filter):
|
||||||
user_id = self.register_user("kermit", "test")
|
user_id = self.register_user("kermit", "test")
|
||||||
|
@ -131,7 +153,7 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
type=EventTypes.Message,
|
type=EventTypes.Message,
|
||||||
content={
|
content={
|
||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with label",
|
"body": "with right label",
|
||||||
LabelsField: ["#fun"],
|
LabelsField: ["#fun"],
|
||||||
},
|
},
|
||||||
tok=tok,
|
tok=tok,
|
||||||
|
@ -163,7 +185,18 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
type=EventTypes.Message,
|
type=EventTypes.Message,
|
||||||
content={
|
content={
|
||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with label",
|
"body": "with two wrong labels",
|
||||||
|
LabelsField: ["#work", "#notfun"],
|
||||||
|
},
|
||||||
|
tok=tok,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.helper.send_event(
|
||||||
|
room_id=room_id,
|
||||||
|
type=EventTypes.Message,
|
||||||
|
content={
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "with right label",
|
||||||
LabelsField: ["#fun"],
|
LabelsField: ["#fun"],
|
||||||
},
|
},
|
||||||
tok=tok,
|
tok=tok,
|
||||||
|
|
Loading…
Reference in a new issue