Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
babolivier committed Oct 30, 2019
1 parent 62588ea commit dcc069a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 50 deletions.
8 changes: 1 addition & 7 deletions synapse/storage/data_stores/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,13 +2486,7 @@ def insert_labels_for_event_txn(self, txn, event_id, labels):
return self._simple_insert_many_txn(
txn=txn,
table="event_labels",
values=[
{
"event_id": event_id,
"label": label,
}
for label in labels
],
values=[{"event_id": event_id, "label": label} for label in labels],
)


Expand Down
16 changes: 4 additions & 12 deletions tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ def test_filter_labels(self):
sender="@foo:bar",
type="m.room.message",
room_id="!secretbase:unknown",
content={
LabelsField: ["#fun"]
},
content={LabelsField: ["#fun"]},
)

self.assertTrue(Filter(definition).check(event))
Expand All @@ -340,9 +338,7 @@ def test_filter_labels(self):
sender="@foo:bar",
type="m.room.message",
room_id="!secretbase:unknown",
content={
LabelsField: ["#notfun"]
},
content={LabelsField: ["#notfun"]},
)

self.assertFalse(Filter(definition).check(event))
Expand All @@ -353,9 +349,7 @@ def test_filter_not_labels(self):
sender="@foo:bar",
type="m.room.message",
room_id="!secretbase:unknown",
content={
LabelsField: ["#fun"]
},
content={LabelsField: ["#fun"]},
)

self.assertFalse(Filter(definition).check(event))
Expand All @@ -364,9 +358,7 @@ def test_filter_not_labels(self):
sender="@foo:bar",
type="m.room.message",
room_id="!secretbase:unknown",
content={
LabelsField: ["#notfun"]
},
content={LabelsField: ["#notfun"]},
)

self.assertTrue(Filter(definition).check(event))
Expand Down
49 changes: 24 additions & 25 deletions tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,9 @@ def test_stream_token_is_accepted_for_fwd_pagianation(self):

def test_filter_labels(self):
"""Test that we can filter by a label."""
message_filter = json.dumps({
"types": [EventTypes.Message],
"org.matrix.labels": ["#fun"],
})
message_filter = json.dumps(
{"types": [EventTypes.Message], "org.matrix.labels": ["#fun"]}
)

events = self._test_filter_labels(message_filter)

Expand All @@ -826,25 +825,28 @@ def test_filter_labels(self):

def test_filter_not_labels(self):
"""Test that we can filter by the absence of a label."""
message_filter = json.dumps({
"types": [EventTypes.Message],
"org.matrix.not_labels": ["#fun"],
})
message_filter = json.dumps(
{"types": [EventTypes.Message], "org.matrix.not_labels": ["#fun"]}
)

events = self._test_filter_labels(message_filter)

self.assertEqual(len(events), 3, [event["content"] for event in events])
self.assertEqual(events[0]["content"]["body"], "without label", events[0])
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):
"""Test that we can filter by both a label and the absence of another label."""
sync_filter = json.dumps({
"types": [EventTypes.Message],
"org.matrix.labels": ["#work"],
"org.matrix.not_labels": ["#notfun"],
})
sync_filter = json.dumps(
{
"types": [EventTypes.Message],
"org.matrix.labels": ["#work"],
"org.matrix.not_labels": ["#notfun"],
}
)

events = self._test_filter_labels(sync_filter)

Expand All @@ -859,16 +861,13 @@ def _test_filter_labels(self, message_filter):
"msgtype": "m.text",
"body": "with right label",
LabelsField: ["#fun"],
}
},
)

self.helper.send_event(
room_id=self.room_id,
type=EventTypes.Message,
content={
"msgtype": "m.text",
"body": "without label",
}
content={"msgtype": "m.text", "body": "without label"},
)

self.helper.send_event(
Expand All @@ -878,7 +877,7 @@ def _test_filter_labels(self, message_filter):
"msgtype": "m.text",
"body": "with wrong label",
LabelsField: ["#work"],
}
},
)

self.helper.send_event(
Expand All @@ -888,7 +887,7 @@ def _test_filter_labels(self, message_filter):
"msgtype": "m.text",
"body": "with two wrong labels",
LabelsField: ["#work", "#notfun"],
}
},
)

self.helper.send_event(
Expand All @@ -898,14 +897,14 @@ def _test_filter_labels(self, message_filter):
"msgtype": "m.text",
"body": "with right label",
LabelsField: ["#fun"],
}
},
)

token = "s0_0_0_0_0_0_0_0_0"
request, channel = self.make_request(
"GET", "/rooms/%s/messages?access_token=x&from=%s&filter=%s" % (
self.room_id, token, message_filter
)
"GET",
"/rooms/%s/messages?access_token=x&from=%s&filter=%s"
% (self.room_id, token, message_filter),
)
self.render(request)

Expand Down
12 changes: 6 additions & 6 deletions tests/rest/client/v2_alpha/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json

from mock import Mock

from synapse.api.constants import EventTypes, LabelsField
import synapse.rest.admin
from synapse.api.constants import EventTypes, LabelsField
from synapse.rest.client.v1 import login, room
from synapse.rest.client.v2_alpha import sync

Expand Down Expand Up @@ -121,7 +122,9 @@ def test_sync_filter_not_labels(self):
self.assertEqual(len(events), 3, [event["content"] for event in events])
self.assertEqual(events[0]["content"]["body"], "without label", events[0])
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):
"""Test that we can filter by both a label and the absence of another label."""
Expand Down Expand Up @@ -162,10 +165,7 @@ def _test_sync_filter_labels(self, sync_filter):
self.helper.send_event(
room_id=room_id,
type=EventTypes.Message,
content={
"msgtype": "m.text",
"body": "without label",
},
content={"msgtype": "m.text", "body": "without label"},
tok=tok,
)

Expand Down

0 comments on commit dcc069a

Please sign in to comment.