Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use constants for receipt types in tests. #12582

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12582.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use constants for read-receipts in tests.
38 changes: 19 additions & 19 deletions tests/handlers/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from typing import List

from synapse.api.constants import ReadReceiptEventFields
from synapse.api.constants import ReadReceiptEventFields, ReceiptTypes
from synapse.types import JsonDict

from tests import unittest
Expand All @@ -35,7 +35,7 @@ def test_filters_out_hidden_receipt(self):
{
"content": {
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@rikj:jki.re": {
"ts": 1436451550453,
"hidden": True,
Expand All @@ -56,7 +56,7 @@ def test_does_not_filter_out_our_hidden_receipt(self):
{
"content": {
"$1435641916hfgh4394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@me:server.org": {
"ts": 1436451550453,
"hidden": True,
Expand All @@ -72,7 +72,7 @@ def test_does_not_filter_out_our_hidden_receipt(self):
{
"content": {
"$1435641916hfgh4394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@me:server.org": {
"ts": 1436451550453,
ReadReceiptEventFields.MSC2285_HIDDEN: True,
Expand All @@ -92,7 +92,7 @@ def test_filters_out_hidden_receipt_and_ignores_rest(self):
{
"content": {
"$1dgdgrd5641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@rikj:jki.re": {
"ts": 1436451550453,
"hidden": True,
Expand All @@ -111,7 +111,7 @@ def test_filters_out_hidden_receipt_and_ignores_rest(self):
{
"content": {
"$1dgdgrd5641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -130,15 +130,15 @@ def test_filters_out_event_with_only_hidden_receipts_and_ignores_the_rest(self):
{
"content": {
"$14356419edgd14394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@rikj:jki.re": {
"ts": 1436451550453,
"hidden": True,
},
}
},
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -153,7 +153,7 @@ def test_filters_out_event_with_only_hidden_receipts_and_ignores_the_rest(self):
{
"content": {
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -171,9 +171,9 @@ def test_handles_missing_content_of_m_read(self):
[
{
"content": {
"$14356419ggffg114394fHBLK:matrix.org": {"m.read": {}},
"$14356419ggffg114394fHBLK:matrix.org": {ReceiptTypes.READ: {}},
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -187,9 +187,9 @@ def test_handles_missing_content_of_m_read(self):
[
{
"content": {
"$14356419ggffg114394fHBLK:matrix.org": {"m.read": {}},
"$14356419ggffg114394fHBLK:matrix.org": {ReceiptTypes.READ: {}},
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -209,7 +209,7 @@ def test_handles_empty_event(self):
"content": {
"$143564gdfg6114394fHBLK:matrix.org": {},
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -225,7 +225,7 @@ def test_handles_empty_event(self):
"content": {
"$143564gdfg6114394fHBLK:matrix.org": {},
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -244,7 +244,7 @@ def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(sel
{
"content": {
"$14356419edgd14394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@rikj:jki.re": {
"ts": 1436451550453,
"hidden": True,
Expand All @@ -258,7 +258,7 @@ def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(sel
{
"content": {
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -273,7 +273,7 @@ def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(sel
{
"content": {
"$1435641916114394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@user:jki.re": {
"ts": 1436451550453,
}
Expand All @@ -297,7 +297,7 @@ def test_handles_string_data(self):
{
"content": {
"$14356419edgd14394fHBLK:matrix.org": {
"m.read": {
ReceiptTypes.READ: {
"@rikj:jki.re": "string",
}
},
Expand Down
11 changes: 8 additions & 3 deletions tests/replication/slave/storage/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from synapse.api.constants import ReceiptTypes
from synapse.replication.slave.storage.receipts import SlavedReceiptsStore

from ._base import BaseSlavedStoreTestCase
Expand All @@ -26,9 +27,13 @@ class SlavedReceiptTestCase(BaseSlavedStoreTestCase):
STORE_TYPE = SlavedReceiptsStore

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.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.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}
)
3 changes: 2 additions & 1 deletion tests/rest/client/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
EventContentFields,
EventTypes,
ReadReceiptEventFields,
ReceiptTypes,
RelationTypes,
)
from synapse.rest.client import devices, knock, login, read_marker, receipts, room, sync
Expand Down Expand Up @@ -560,7 +561,7 @@ def test_unread_counts(self) -> None:
self._check_unread_count(1)

# 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(
"POST",
"/rooms/%s/read_markers" % self.room_id,
Expand Down