This commit is contained in:
Brendan Abolivier 2019-11-05 14:50:19 +00:00
parent 8822b33111
commit a6863da249
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD
1 changed files with 41 additions and 30 deletions

View File

@ -1020,9 +1020,15 @@ class LabelsTestCase(unittest.HomeserverTestCase):
] ]
# Filter that should only catch messages with the label "#fun". # Filter that should only catch messages with the label "#fun".
FILTER_LABELS = {"types": [EventTypes.Message], "org.matrix.labels": ["#fun"]} FILTER_LABELS = {
"types": [EventTypes.Message],
"org.matrix.labels": ["#fun"],
}
# Filter that should only catch messages without the label "#fun". # Filter that should only catch messages without the label "#fun".
FILTER_NOT_LABELS = {"types": [EventTypes.Message], "org.matrix.not_labels": ["#fun"]} FILTER_NOT_LABELS = {
"types": [EventTypes.Message],
"org.matrix.not_labels": ["#fun"],
}
# Filter that should only catch messages with the label "#work" but without the label # Filter that should only catch messages with the label "#work" but without the label
# "#notfun". # "#notfun".
FILTER_LABELS_NOT_LABELS = { FILTER_LABELS_NOT_LABELS = {
@ -1181,7 +1187,12 @@ class LabelsTestCase(unittest.HomeserverTestCase):
request, channel = self.make_request( request, channel = self.make_request(
"GET", "GET",
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s" "/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
% (self.room_id, self.tok, token, json.dumps(self.FILTER_LABELS_NOT_LABELS)), % (
self.room_id,
self.tok,
token,
json.dumps(self.FILTER_LABELS_NOT_LABELS),
),
) )
self.render(request) self.render(request)
@ -1192,14 +1203,16 @@ class LabelsTestCase(unittest.HomeserverTestCase):
def test_search_filter_labels(self): def test_search_filter_labels(self):
"""Test that we can filter by a label on a /search request.""" """Test that we can filter by a label on a /search request."""
request_data = json.dumps({ request_data = json.dumps(
{
"search_categories": { "search_categories": {
"room_events": { "room_events": {
"search_term": "label", "search_term": "label",
"filter": self.FILTER_LABELS, "filter": self.FILTER_LABELS,
} }
} }
}) }
)
self._send_labelled_messages_in_room() self._send_labelled_messages_in_room()
@ -1211,9 +1224,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
results = channel.json_body["search_categories"]["room_events"]["results"] results = channel.json_body["search_categories"]["room_events"]["results"]
self.assertEqual( self.assertEqual(
len(results), len(results), 2, [result["result"]["content"] for result in results],
2,
[result["result"]["content"] for result in results],
) )
self.assertEqual( self.assertEqual(
results[0]["result"]["content"]["body"], results[0]["result"]["content"]["body"],
@ -1228,14 +1239,16 @@ class LabelsTestCase(unittest.HomeserverTestCase):
def test_search_filter_not_labels(self): def test_search_filter_not_labels(self):
"""Test that we can filter by the absence of a label on a /search request.""" """Test that we can filter by the absence of a label on a /search request."""
request_data = json.dumps({ request_data = json.dumps(
{
"search_categories": { "search_categories": {
"room_events": { "room_events": {
"search_term": "label", "search_term": "label",
"filter": self.FILTER_NOT_LABELS, "filter": self.FILTER_NOT_LABELS,
} }
} }
}) }
)
self._send_labelled_messages_in_room() self._send_labelled_messages_in_room()
@ -1247,9 +1260,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
results = channel.json_body["search_categories"]["room_events"]["results"] results = channel.json_body["search_categories"]["room_events"]["results"]
self.assertEqual( self.assertEqual(
len(results), len(results), 4, [result["result"]["content"] for result in results],
4,
[result["result"]["content"] for result in results],
) )
self.assertEqual( self.assertEqual(
results[0]["result"]["content"]["body"], results[0]["result"]["content"]["body"],
@ -1276,14 +1287,16 @@ class LabelsTestCase(unittest.HomeserverTestCase):
"""Test that we can filter by both a label and the absence of another label on a """Test that we can filter by both a label and the absence of another label on a
/search request. /search request.
""" """
request_data = json.dumps({ request_data = json.dumps(
{
"search_categories": { "search_categories": {
"room_events": { "room_events": {
"search_term": "label", "search_term": "label",
"filter": self.FILTER_LABELS_NOT_LABELS, "filter": self.FILTER_LABELS_NOT_LABELS,
} }
} }
}) }
)
self._send_labelled_messages_in_room() self._send_labelled_messages_in_room()
@ -1295,9 +1308,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
results = channel.json_body["search_categories"]["room_events"]["results"] results = channel.json_body["search_categories"]["room_events"]["results"]
self.assertEqual( self.assertEqual(
len(results), len(results), 1, [result["result"]["content"] for result in results],
1,
[result["result"]["content"] for result in results],
) )
self.assertEqual( self.assertEqual(
results[0]["result"]["content"]["body"], results[0]["result"]["content"]["body"],