add tests for checking if room search works with non-ascii char

pull/10859/head
H.Shay 2021-09-20 08:25:30 -07:00
parent b3590614da
commit a0669412da
1 changed files with 44 additions and 0 deletions

View File

@ -941,6 +941,50 @@ class RoomTestCase(unittest.HomeserverTestCase):
_search_test(None, "bar")
_search_test(None, "", expected_http_code=400)
def test_search_term_non_ASCII(self):
"""Test that searching for a room with non-ASCII characters works correctly"""
# Create test room
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_name = "ж"
# Set the name for the room
self.helper.send_state(
room_id,
"m.room.name",
{"name": room_name},
tok=self.admin_user_tok,
)
def _search_test_utf8(
expected_room_id,
search_term: str,
expected_http_code: int = 200,
):
"""Search for a room and check that the returned room's id is a match
Args:
expected_room_id: The room_id expected to be returned by the API. Set
to None to expect zero results for the search
search_term: The term to search for room names with
expected_http_code: The expected http code for the request
"""
url = "/_synapse/admin/v1/rooms?search_term=%s" % (search_term,)
channel = self.make_request(
"GET",
url.encode("UTF-8"),
access_token=self.admin_user_tok,
)
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body)
self.assertIn(expected_room_id, channel.json_body.get('rooms')[0].get('room_id'))
self.assertIn("ж", channel.json_body.get('rooms')[0].get('name'))
search_term = "ж"
_search_test_utf8(room_id, search_term)
def test_single_room(self):
"""Test that a single room can be requested correctly"""
# Create two test rooms