Skip to content

Commit

Permalink
- postgres incompatibility fixed.
Browse files Browse the repository at this point in the history
- Test for filter_empty_rooms added.
  • Loading branch information
afechler committed Jun 6, 2024
1 parent 406df01 commit 1e29926
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ async def get_rooms_paginate(
]
if filter_public_rooms is not None:
filter_arg = "1" if filter_public_rooms else "0"
filter_.append(f"rooms.is_public = {filter_arg}")
filter_.append(f"rooms.is_public = '{filter_arg}'")

if filter_empty_rooms is not None:
if filter_empty_rooms:
Expand Down
39 changes: 39 additions & 0 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,45 @@ def test_filter_public_rooms(self) -> None:
self.assertEqual(1, response.json_body["total_rooms"])
self.assertEqual(1, len(response.json_body["rooms"]))

def test_filter_empty_rooms(self) -> None:
self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok, is_public=True
)
self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok, is_public=True
)
room_id = self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok, is_public=False
)
self.helper.leave(room_id, self.admin_user, tok=self.admin_user_tok)

response = self.make_request(
"GET",
"/_synapse/admin/v1/rooms",
access_token=self.admin_user_tok,
)
self.assertEqual(200, response.code, msg=response.json_body)
self.assertEqual(3, response.json_body["total_rooms"])
self.assertEqual(3, len(response.json_body["rooms"]))

response = self.make_request(
"GET",
"/_synapse/admin/v1/rooms?filter_empty_rooms=false",
access_token=self.admin_user_tok,
)
self.assertEqual(200, response.code, msg=response.json_body)
self.assertEqual(2, response.json_body["total_rooms"])
self.assertEqual(2, len(response.json_body["rooms"]))

response = self.make_request(
"GET",
"/_synapse/admin/v1/rooms?filter_empty_rooms=true",
access_token=self.admin_user_tok,
)
self.assertEqual(200, response.code, msg=response.json_body)
self.assertEqual(1, response.json_body["total_rooms"])
self.assertEqual(1, len(response.json_body["rooms"]))

def test_single_room(self) -> None:
"""Test that a single room can be requested correctly"""
# Create two test rooms
Expand Down

0 comments on commit 1e29926

Please sign in to comment.