mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Lint
This commit is contained in:
parent
62588eae4a
commit
dcc069a2e2
@ -2486,13 +2486,7 @@ class EventsStore(
|
|||||||
return self._simple_insert_many_txn(
|
return self._simple_insert_many_txn(
|
||||||
txn=txn,
|
txn=txn,
|
||||||
table="event_labels",
|
table="event_labels",
|
||||||
values=[
|
values=[{"event_id": event_id, "label": label} for label in labels],
|
||||||
{
|
|
||||||
"event_id": event_id,
|
|
||||||
"label": label,
|
|
||||||
}
|
|
||||||
for label in labels
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -329,9 +329,7 @@ class FilteringTestCase(unittest.TestCase):
|
|||||||
sender="@foo:bar",
|
sender="@foo:bar",
|
||||||
type="m.room.message",
|
type="m.room.message",
|
||||||
room_id="!secretbase:unknown",
|
room_id="!secretbase:unknown",
|
||||||
content={
|
content={LabelsField: ["#fun"]},
|
||||||
LabelsField: ["#fun"]
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertTrue(Filter(definition).check(event))
|
self.assertTrue(Filter(definition).check(event))
|
||||||
@ -340,9 +338,7 @@ class FilteringTestCase(unittest.TestCase):
|
|||||||
sender="@foo:bar",
|
sender="@foo:bar",
|
||||||
type="m.room.message",
|
type="m.room.message",
|
||||||
room_id="!secretbase:unknown",
|
room_id="!secretbase:unknown",
|
||||||
content={
|
content={LabelsField: ["#notfun"]},
|
||||||
LabelsField: ["#notfun"]
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertFalse(Filter(definition).check(event))
|
self.assertFalse(Filter(definition).check(event))
|
||||||
@ -353,9 +349,7 @@ class FilteringTestCase(unittest.TestCase):
|
|||||||
sender="@foo:bar",
|
sender="@foo:bar",
|
||||||
type="m.room.message",
|
type="m.room.message",
|
||||||
room_id="!secretbase:unknown",
|
room_id="!secretbase:unknown",
|
||||||
content={
|
content={LabelsField: ["#fun"]},
|
||||||
LabelsField: ["#fun"]
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertFalse(Filter(definition).check(event))
|
self.assertFalse(Filter(definition).check(event))
|
||||||
@ -364,9 +358,7 @@ class FilteringTestCase(unittest.TestCase):
|
|||||||
sender="@foo:bar",
|
sender="@foo:bar",
|
||||||
type="m.room.message",
|
type="m.room.message",
|
||||||
room_id="!secretbase:unknown",
|
room_id="!secretbase:unknown",
|
||||||
content={
|
content={LabelsField: ["#notfun"]},
|
||||||
LabelsField: ["#notfun"]
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertTrue(Filter(definition).check(event))
|
self.assertTrue(Filter(definition).check(event))
|
||||||
|
@ -813,10 +813,9 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
|
|
||||||
def test_filter_labels(self):
|
def test_filter_labels(self):
|
||||||
"""Test that we can filter by a label."""
|
"""Test that we can filter by a label."""
|
||||||
message_filter = json.dumps({
|
message_filter = json.dumps(
|
||||||
"types": [EventTypes.Message],
|
{"types": [EventTypes.Message], "org.matrix.labels": ["#fun"]}
|
||||||
"org.matrix.labels": ["#fun"],
|
)
|
||||||
})
|
|
||||||
|
|
||||||
events = self._test_filter_labels(message_filter)
|
events = self._test_filter_labels(message_filter)
|
||||||
|
|
||||||
@ -826,25 +825,28 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
|
|
||||||
def test_filter_not_labels(self):
|
def test_filter_not_labels(self):
|
||||||
"""Test that we can filter by the absence of a label."""
|
"""Test that we can filter by the absence of a label."""
|
||||||
message_filter = json.dumps({
|
message_filter = json.dumps(
|
||||||
"types": [EventTypes.Message],
|
{"types": [EventTypes.Message], "org.matrix.not_labels": ["#fun"]}
|
||||||
"org.matrix.not_labels": ["#fun"],
|
)
|
||||||
})
|
|
||||||
|
|
||||||
events = self._test_filter_labels(message_filter)
|
events = self._test_filter_labels(message_filter)
|
||||||
|
|
||||||
self.assertEqual(len(events), 3, [event["content"] for event in 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])
|
self.assertEqual(
|
||||||
|
events[2]["content"]["body"], "with two wrong labels", events[2]
|
||||||
|
)
|
||||||
|
|
||||||
def test_filter_labels_not_labels(self):
|
def test_filter_labels_not_labels(self):
|
||||||
"""Test that we can filter by both a label and the absence of another label."""
|
"""Test that we can filter by both a label and the absence of another label."""
|
||||||
sync_filter = json.dumps({
|
sync_filter = json.dumps(
|
||||||
"types": [EventTypes.Message],
|
{
|
||||||
"org.matrix.labels": ["#work"],
|
"types": [EventTypes.Message],
|
||||||
"org.matrix.not_labels": ["#notfun"],
|
"org.matrix.labels": ["#work"],
|
||||||
})
|
"org.matrix.not_labels": ["#notfun"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
events = self._test_filter_labels(sync_filter)
|
events = self._test_filter_labels(sync_filter)
|
||||||
|
|
||||||
@ -859,16 +861,13 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with right label",
|
"body": "with right label",
|
||||||
LabelsField: ["#fun"],
|
LabelsField: ["#fun"],
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.helper.send_event(
|
self.helper.send_event(
|
||||||
room_id=self.room_id,
|
room_id=self.room_id,
|
||||||
type=EventTypes.Message,
|
type=EventTypes.Message,
|
||||||
content={
|
content={"msgtype": "m.text", "body": "without label"},
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "without label",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.helper.send_event(
|
self.helper.send_event(
|
||||||
@ -878,7 +877,7 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with wrong label",
|
"body": "with wrong label",
|
||||||
LabelsField: ["#work"],
|
LabelsField: ["#work"],
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.helper.send_event(
|
self.helper.send_event(
|
||||||
@ -888,7 +887,7 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with two wrong labels",
|
"body": "with two wrong labels",
|
||||||
LabelsField: ["#work", "#notfun"],
|
LabelsField: ["#work", "#notfun"],
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.helper.send_event(
|
self.helper.send_event(
|
||||||
@ -898,14 +897,14 @@ class RoomMessageListTestCase(RoomBase):
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": "with right label",
|
"body": "with right label",
|
||||||
LabelsField: ["#fun"],
|
LabelsField: ["#fun"],
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
token = "s0_0_0_0_0_0_0_0_0"
|
token = "s0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
request, channel = self.make_request(
|
||||||
"GET", "/rooms/%s/messages?access_token=x&from=%s&filter=%s" % (
|
"GET",
|
||||||
self.room_id, token, message_filter
|
"/rooms/%s/messages?access_token=x&from=%s&filter=%s"
|
||||||
)
|
% (self.room_id, token, message_filter),
|
||||||
)
|
)
|
||||||
self.render(request)
|
self.render(request)
|
||||||
|
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, LabelsField
|
|
||||||
import synapse.rest.admin
|
import synapse.rest.admin
|
||||||
|
from synapse.api.constants import EventTypes, LabelsField
|
||||||
from synapse.rest.client.v1 import login, room
|
from synapse.rest.client.v1 import login, room
|
||||||
from synapse.rest.client.v2_alpha import sync
|
from synapse.rest.client.v2_alpha import sync
|
||||||
|
|
||||||
@ -121,7 +122,9 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
|||||||
self.assertEqual(len(events), 3, [event["content"] for event in 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])
|
self.assertEqual(
|
||||||
|
events[2]["content"]["body"], "with two wrong labels", events[2]
|
||||||
|
)
|
||||||
|
|
||||||
def test_sync_filter_labels_not_labels(self):
|
def test_sync_filter_labels_not_labels(self):
|
||||||
"""Test that we can filter by both a label and the absence of another label."""
|
"""Test that we can filter by both a label and the absence of another label."""
|
||||||
@ -162,10 +165,7 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
|||||||
self.helper.send_event(
|
self.helper.send_event(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
type=EventTypes.Message,
|
type=EventTypes.Message,
|
||||||
content={
|
content={"msgtype": "m.text", "body": "without label"},
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "without label",
|
|
||||||
},
|
|
||||||
tok=tok,
|
tok=tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user