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

Add a test case for the SendJoinParser #11441

Merged
merged 4 commits into from
Nov 29, 2021
Merged
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/11441.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in 1.47.0 where `send_join` could fail due to an outdated `ijson` version.
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ disallow_untyped_defs = True
[mypy-tests.rest.client.test_directory]
disallow_untyped_defs = True

[mypy-tests.federation.transport.test_client]
disallow_untyped_defs = True


;; Dependencies without annotations
;; Before ignoring a module, check to see if type stubs are available.
;; The `typeshed` project maintains stubs here:
Expand Down
50 changes: 50 additions & 0 deletions tests/federation/transport/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DMRobertson Can you add a license header to this file please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #11460.


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) -> None:
"""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
parsed_response = parser.finish()

# Sanity check the parsing gave us sensible data.
self.assertEqual(len(parsed_response.auth_events), 1, parsed_response)
self.assertEqual(len(parsed_response.state), 1, parsed_response)
self.assertEqual(parsed_response.event_dict, {}, parsed_response)
self.assertIsNone(parsed_response.event, parsed_response)