1
0

test_receipts.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from synapse.replication.tcp.streams._base import ReceiptsStreamRow
  16. from tests.replication.tcp.streams._base import BaseStreamTestCase
  17. USER_ID = "@feeling:blue"
  18. ROOM_ID = "!room:blue"
  19. EVENT_ID = "$event:blue"
  20. class ReceiptsStreamTestCase(BaseStreamTestCase):
  21. def test_receipt(self):
  22. # make the client subscribe to the receipts stream
  23. self.replicate_stream("receipts", "NOW")
  24. # tell the master to send a new receipt
  25. self.get_success(
  26. self.hs.get_datastore().insert_receipt(
  27. ROOM_ID, "m.read", USER_ID, [EVENT_ID], {"a": 1}
  28. )
  29. )
  30. self.replicate()
  31. # there should be one RDATA command
  32. rdata_rows = self.test_handler.received_rdata_rows
  33. self.assertEqual(1, len(rdata_rows))
  34. self.assertEqual(rdata_rows[0][0], "receipts")
  35. row = rdata_rows[0][2] # type: ReceiptsStreamRow
  36. self.assertEqual(ROOM_ID, row.room_id)
  37. self.assertEqual("m.read", row.receipt_type)
  38. self.assertEqual(USER_ID, row.user_id)
  39. self.assertEqual(EVENT_ID, row.event_id)
  40. self.assertEqual({"a": 1}, row.data)