Use constants for receipt types in tests. (#12582)

This commit is contained in:
Šimon Brandner 2022-04-28 13:34:12 -04:00 committed by Patrick Cloke
parent 0b684b59e5
commit 0d9eaa19fd
4 changed files with 30 additions and 23 deletions

1
changelog.d/12582.misc Normal file
View File

@ -0,0 +1 @@
Use constants for read-receipts in tests.

View File

@ -15,7 +15,7 @@
from typing import List from typing import List
from synapse.api.constants import ReadReceiptEventFields from synapse.api.constants import ReadReceiptEventFields, ReceiptTypes
from synapse.types import JsonDict from synapse.types import JsonDict
from tests import unittest from tests import unittest
@ -35,7 +35,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@rikj:jki.re": { "@rikj:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
"hidden": True, "hidden": True,
@ -56,7 +56,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916hfgh4394fHBLK:matrix.org": { "$1435641916hfgh4394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@me:server.org": { "@me:server.org": {
"ts": 1436451550453, "ts": 1436451550453,
"hidden": True, "hidden": True,
@ -72,7 +72,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916hfgh4394fHBLK:matrix.org": { "$1435641916hfgh4394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@me:server.org": { "@me:server.org": {
"ts": 1436451550453, "ts": 1436451550453,
ReadReceiptEventFields.MSC2285_HIDDEN: True, ReadReceiptEventFields.MSC2285_HIDDEN: True,
@ -92,7 +92,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1dgdgrd5641916114394fHBLK:matrix.org": { "$1dgdgrd5641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@rikj:jki.re": { "@rikj:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
"hidden": True, "hidden": True,
@ -111,7 +111,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1dgdgrd5641916114394fHBLK:matrix.org": { "$1dgdgrd5641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -130,7 +130,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$14356419edgd14394fHBLK:matrix.org": { "$14356419edgd14394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@rikj:jki.re": { "@rikj:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
"hidden": True, "hidden": True,
@ -138,7 +138,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
} }
}, },
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -153,7 +153,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -171,9 +171,9 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
[ [
{ {
"content": { "content": {
"$14356419ggffg114394fHBLK:matrix.org": {"m.read": {}}, "$14356419ggffg114394fHBLK:matrix.org": {ReceiptTypes.READ: {}},
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -187,9 +187,9 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
[ [
{ {
"content": { "content": {
"$14356419ggffg114394fHBLK:matrix.org": {"m.read": {}}, "$14356419ggffg114394fHBLK:matrix.org": {ReceiptTypes.READ: {}},
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -209,7 +209,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
"content": { "content": {
"$143564gdfg6114394fHBLK:matrix.org": {}, "$143564gdfg6114394fHBLK:matrix.org": {},
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -225,7 +225,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
"content": { "content": {
"$143564gdfg6114394fHBLK:matrix.org": {}, "$143564gdfg6114394fHBLK:matrix.org": {},
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -244,7 +244,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$14356419edgd14394fHBLK:matrix.org": { "$14356419edgd14394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@rikj:jki.re": { "@rikj:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
"hidden": True, "hidden": True,
@ -258,7 +258,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -273,7 +273,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$1435641916114394fHBLK:matrix.org": { "$1435641916114394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@user:jki.re": { "@user:jki.re": {
"ts": 1436451550453, "ts": 1436451550453,
} }
@ -297,7 +297,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
{ {
"content": { "content": {
"$14356419edgd14394fHBLK:matrix.org": { "$14356419edgd14394fHBLK:matrix.org": {
"m.read": { ReceiptTypes.READ: {
"@rikj:jki.re": "string", "@rikj:jki.re": "string",
} }
}, },

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from synapse.api.constants import ReceiptTypes
from synapse.replication.slave.storage.receipts import SlavedReceiptsStore from synapse.replication.slave.storage.receipts import SlavedReceiptsStore
from ._base import BaseSlavedStoreTestCase from ._base import BaseSlavedStoreTestCase
@ -26,9 +27,13 @@ class SlavedReceiptTestCase(BaseSlavedStoreTestCase):
STORE_TYPE = SlavedReceiptsStore STORE_TYPE = SlavedReceiptsStore
def test_receipt(self): def test_receipt(self):
self.check("get_receipts_for_user", [USER_ID, "m.read"], {}) self.check("get_receipts_for_user", [USER_ID, ReceiptTypes.READ], {})
self.get_success( self.get_success(
self.master_store.insert_receipt(ROOM_ID, "m.read", USER_ID, [EVENT_ID], {}) self.master_store.insert_receipt(
ROOM_ID, ReceiptTypes.READ, USER_ID, [EVENT_ID], {}
)
) )
self.replicate() self.replicate()
self.check("get_receipts_for_user", [USER_ID, "m.read"], {ROOM_ID: EVENT_ID}) self.check(
"get_receipts_for_user", [USER_ID, ReceiptTypes.READ], {ROOM_ID: EVENT_ID}
)

View File

@ -24,6 +24,7 @@ from synapse.api.constants import (
EventContentFields, EventContentFields,
EventTypes, EventTypes,
ReadReceiptEventFields, ReadReceiptEventFields,
ReceiptTypes,
RelationTypes, RelationTypes,
) )
from synapse.rest.client import devices, knock, login, read_marker, receipts, room, sync from synapse.rest.client import devices, knock, login, read_marker, receipts, room, sync
@ -560,7 +561,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
self._check_unread_count(1) self._check_unread_count(1)
# Send a read receipt to tell the server we've read the latest event. # Send a read receipt to tell the server we've read the latest event.
body = json.dumps({"m.read": res["event_id"]}).encode("utf8") body = json.dumps({ReceiptTypes.READ: res["event_id"]}).encode("utf8")
channel = self.make_request( channel = self.make_request(
"POST", "POST",
"/rooms/%s/read_markers" % self.room_id, "/rooms/%s/read_markers" % self.room_id,