This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for the SendJoinParser
- Loading branch information
David Robertson
committed
Nov 26, 2021
1 parent
1d8b80b
commit 8cd7b00
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
|
||
from synapse.api.room_versions import RoomVersions | ||
from synapse.federation.transport.client import SendJoinParser | ||
from tests.unittest import TestCase | ||
|
||
|
||
class SendJoinParserTestCase(TestCase): | ||
def test_two_writes(self): | ||
"""Test that the parser can sensibly deserialise an input given in two slices.""" | ||
parser = SendJoinParser(RoomVersions.V1, True) | ||
parent_event = { | ||
"content": { | ||
"see_room_version_spec": "The event format changes depending on the room version." | ||
}, | ||
"event_id": "$authparent", | ||
"room_id": "!somewhere:example.org", | ||
"type": "m.room.minimal_pdu", | ||
} | ||
state = { | ||
"content": { | ||
"see_room_version_spec": "The event format changes depending on the room version." | ||
}, | ||
"event_id": "$DoNotThinkAboutTheEvent", | ||
"room_id": "!somewhere:example.org", | ||
"type": "m.room.minimal_pdu", | ||
} | ||
response = [ | ||
200, | ||
{ | ||
"auth_chain": [parent_event], | ||
"origin": "matrix.org", | ||
"state": [state], | ||
}, | ||
] | ||
serialised_response = json.dumps(response).encode() | ||
|
||
# Send data to the parser | ||
parser.write(serialised_response[:100]) | ||
parser.write(serialised_response[100:]) | ||
|
||
# Retrieve the parsed SendJoinResponse | ||
response = parser.finish() | ||
|
||
# Sanity check the parsing gave us sensible data. | ||
self.assertEqual(len(response.auth_events), 1, response) | ||
self.assertEqual(len(response.state), 1, response) | ||
self.assertEqual(response.event_dict, {}, response) | ||
self.assertIsNone(response.event, response) |