test_relations.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. import itertools
  16. import json
  17. import urllib
  18. from synapse.api.constants import EventTypes, RelationTypes
  19. from synapse.rest import admin
  20. from synapse.rest.client.v1 import login, room
  21. from synapse.rest.client.v2_alpha import register, relations
  22. from tests import unittest
  23. class RelationsTestCase(unittest.HomeserverTestCase):
  24. servlets = [
  25. relations.register_servlets,
  26. room.register_servlets,
  27. login.register_servlets,
  28. register.register_servlets,
  29. admin.register_servlets_for_client_rest_resource,
  30. ]
  31. hijack_auth = False
  32. def make_homeserver(self, reactor, clock):
  33. # We need to enable msc1849 support for aggregations
  34. config = self.default_config()
  35. config["experimental_msc1849_support_enabled"] = True
  36. return self.setup_test_homeserver(config=config)
  37. def prepare(self, reactor, clock, hs):
  38. self.user_id, self.user_token = self._create_user("alice")
  39. self.user2_id, self.user2_token = self._create_user("bob")
  40. self.room = self.helper.create_room_as(self.user_id, tok=self.user_token)
  41. self.helper.join(self.room, user=self.user2_id, tok=self.user2_token)
  42. res = self.helper.send(self.room, body="Hi!", tok=self.user_token)
  43. self.parent_id = res["event_id"]
  44. def test_send_relation(self):
  45. """Tests that sending a relation using the new /send_relation works
  46. creates the right shape of event.
  47. """
  48. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", key="👍")
  49. self.assertEquals(200, channel.code, channel.json_body)
  50. event_id = channel.json_body["event_id"]
  51. channel = self.make_request(
  52. "GET",
  53. "/rooms/%s/event/%s" % (self.room, event_id),
  54. access_token=self.user_token,
  55. )
  56. self.assertEquals(200, channel.code, channel.json_body)
  57. self.assert_dict(
  58. {
  59. "type": "m.reaction",
  60. "sender": self.user_id,
  61. "content": {
  62. "m.relates_to": {
  63. "event_id": self.parent_id,
  64. "key": "👍",
  65. "rel_type": RelationTypes.ANNOTATION,
  66. }
  67. },
  68. },
  69. channel.json_body,
  70. )
  71. def test_deny_membership(self):
  72. """Test that we deny relations on membership events
  73. """
  74. channel = self._send_relation(RelationTypes.ANNOTATION, EventTypes.Member)
  75. self.assertEquals(400, channel.code, channel.json_body)
  76. def test_deny_double_react(self):
  77. """Test that we deny relations on membership events
  78. """
  79. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", key="a")
  80. self.assertEquals(200, channel.code, channel.json_body)
  81. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
  82. self.assertEquals(400, channel.code, channel.json_body)
  83. def test_basic_paginate_relations(self):
  84. """Tests that calling pagination API correctly the latest relations.
  85. """
  86. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction")
  87. self.assertEquals(200, channel.code, channel.json_body)
  88. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction")
  89. self.assertEquals(200, channel.code, channel.json_body)
  90. annotation_id = channel.json_body["event_id"]
  91. channel = self.make_request(
  92. "GET",
  93. "/_matrix/client/unstable/rooms/%s/relations/%s?limit=1"
  94. % (self.room, self.parent_id),
  95. access_token=self.user_token,
  96. )
  97. self.assertEquals(200, channel.code, channel.json_body)
  98. # We expect to get back a single pagination result, which is the full
  99. # relation event we sent above.
  100. self.assertEquals(len(channel.json_body["chunk"]), 1, channel.json_body)
  101. self.assert_dict(
  102. {"event_id": annotation_id, "sender": self.user_id, "type": "m.reaction"},
  103. channel.json_body["chunk"][0],
  104. )
  105. # We also expect to get the original event (the id of which is self.parent_id)
  106. self.assertEquals(
  107. channel.json_body["original_event"]["event_id"], self.parent_id
  108. )
  109. # Make sure next_batch has something in it that looks like it could be a
  110. # valid token.
  111. self.assertIsInstance(
  112. channel.json_body.get("next_batch"), str, channel.json_body
  113. )
  114. def test_repeated_paginate_relations(self):
  115. """Test that if we paginate using a limit and tokens then we get the
  116. expected events.
  117. """
  118. expected_event_ids = []
  119. for _ in range(10):
  120. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction")
  121. self.assertEquals(200, channel.code, channel.json_body)
  122. expected_event_ids.append(channel.json_body["event_id"])
  123. prev_token = None
  124. found_event_ids = []
  125. for _ in range(20):
  126. from_token = ""
  127. if prev_token:
  128. from_token = "&from=" + prev_token
  129. channel = self.make_request(
  130. "GET",
  131. "/_matrix/client/unstable/rooms/%s/relations/%s?limit=1%s"
  132. % (self.room, self.parent_id, from_token),
  133. access_token=self.user_token,
  134. )
  135. self.assertEquals(200, channel.code, channel.json_body)
  136. found_event_ids.extend(e["event_id"] for e in channel.json_body["chunk"])
  137. next_batch = channel.json_body.get("next_batch")
  138. self.assertNotEquals(prev_token, next_batch)
  139. prev_token = next_batch
  140. if not prev_token:
  141. break
  142. # We paginated backwards, so reverse
  143. found_event_ids.reverse()
  144. self.assertEquals(found_event_ids, expected_event_ids)
  145. def test_aggregation_pagination_groups(self):
  146. """Test that we can paginate annotation groups correctly.
  147. """
  148. # We need to create ten separate users to send each reaction.
  149. access_tokens = [self.user_token, self.user2_token]
  150. idx = 0
  151. while len(access_tokens) < 10:
  152. user_id, token = self._create_user("test" + str(idx))
  153. idx += 1
  154. self.helper.join(self.room, user=user_id, tok=token)
  155. access_tokens.append(token)
  156. idx = 0
  157. sent_groups = {"👍": 10, "a": 7, "b": 5, "c": 3, "d": 2, "e": 1}
  158. for key in itertools.chain.from_iterable(
  159. itertools.repeat(key, num) for key, num in sent_groups.items()
  160. ):
  161. channel = self._send_relation(
  162. RelationTypes.ANNOTATION,
  163. "m.reaction",
  164. key=key,
  165. access_token=access_tokens[idx],
  166. )
  167. self.assertEquals(200, channel.code, channel.json_body)
  168. idx += 1
  169. idx %= len(access_tokens)
  170. prev_token = None
  171. found_groups = {}
  172. for _ in range(20):
  173. from_token = ""
  174. if prev_token:
  175. from_token = "&from=" + prev_token
  176. channel = self.make_request(
  177. "GET",
  178. "/_matrix/client/unstable/rooms/%s/aggregations/%s?limit=1%s"
  179. % (self.room, self.parent_id, from_token),
  180. access_token=self.user_token,
  181. )
  182. self.assertEquals(200, channel.code, channel.json_body)
  183. self.assertEqual(len(channel.json_body["chunk"]), 1, channel.json_body)
  184. for groups in channel.json_body["chunk"]:
  185. # We only expect reactions
  186. self.assertEqual(groups["type"], "m.reaction", channel.json_body)
  187. # We should only see each key once
  188. self.assertNotIn(groups["key"], found_groups, channel.json_body)
  189. found_groups[groups["key"]] = groups["count"]
  190. next_batch = channel.json_body.get("next_batch")
  191. self.assertNotEquals(prev_token, next_batch)
  192. prev_token = next_batch
  193. if not prev_token:
  194. break
  195. self.assertEquals(sent_groups, found_groups)
  196. def test_aggregation_pagination_within_group(self):
  197. """Test that we can paginate within an annotation group.
  198. """
  199. # We need to create ten separate users to send each reaction.
  200. access_tokens = [self.user_token, self.user2_token]
  201. idx = 0
  202. while len(access_tokens) < 10:
  203. user_id, token = self._create_user("test" + str(idx))
  204. idx += 1
  205. self.helper.join(self.room, user=user_id, tok=token)
  206. access_tokens.append(token)
  207. idx = 0
  208. expected_event_ids = []
  209. for _ in range(10):
  210. channel = self._send_relation(
  211. RelationTypes.ANNOTATION,
  212. "m.reaction",
  213. key="👍",
  214. access_token=access_tokens[idx],
  215. )
  216. self.assertEquals(200, channel.code, channel.json_body)
  217. expected_event_ids.append(channel.json_body["event_id"])
  218. idx += 1
  219. # Also send a different type of reaction so that we test we don't see it
  220. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", key="a")
  221. self.assertEquals(200, channel.code, channel.json_body)
  222. prev_token = None
  223. found_event_ids = []
  224. encoded_key = urllib.parse.quote_plus("👍".encode("utf-8"))
  225. for _ in range(20):
  226. from_token = ""
  227. if prev_token:
  228. from_token = "&from=" + prev_token
  229. channel = self.make_request(
  230. "GET",
  231. "/_matrix/client/unstable/rooms/%s"
  232. "/aggregations/%s/%s/m.reaction/%s?limit=1%s"
  233. % (
  234. self.room,
  235. self.parent_id,
  236. RelationTypes.ANNOTATION,
  237. encoded_key,
  238. from_token,
  239. ),
  240. access_token=self.user_token,
  241. )
  242. self.assertEquals(200, channel.code, channel.json_body)
  243. self.assertEqual(len(channel.json_body["chunk"]), 1, channel.json_body)
  244. found_event_ids.extend(e["event_id"] for e in channel.json_body["chunk"])
  245. next_batch = channel.json_body.get("next_batch")
  246. self.assertNotEquals(prev_token, next_batch)
  247. prev_token = next_batch
  248. if not prev_token:
  249. break
  250. # We paginated backwards, so reverse
  251. found_event_ids.reverse()
  252. self.assertEquals(found_event_ids, expected_event_ids)
  253. def test_aggregation(self):
  254. """Test that annotations get correctly aggregated.
  255. """
  256. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
  257. self.assertEquals(200, channel.code, channel.json_body)
  258. channel = self._send_relation(
  259. RelationTypes.ANNOTATION, "m.reaction", "a", access_token=self.user2_token
  260. )
  261. self.assertEquals(200, channel.code, channel.json_body)
  262. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
  263. self.assertEquals(200, channel.code, channel.json_body)
  264. channel = self.make_request(
  265. "GET",
  266. "/_matrix/client/unstable/rooms/%s/aggregations/%s"
  267. % (self.room, self.parent_id),
  268. access_token=self.user_token,
  269. )
  270. self.assertEquals(200, channel.code, channel.json_body)
  271. self.assertEquals(
  272. channel.json_body,
  273. {
  274. "chunk": [
  275. {"type": "m.reaction", "key": "a", "count": 2},
  276. {"type": "m.reaction", "key": "b", "count": 1},
  277. ]
  278. },
  279. )
  280. def test_aggregation_redactions(self):
  281. """Test that annotations get correctly aggregated after a redaction.
  282. """
  283. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
  284. self.assertEquals(200, channel.code, channel.json_body)
  285. to_redact_event_id = channel.json_body["event_id"]
  286. channel = self._send_relation(
  287. RelationTypes.ANNOTATION, "m.reaction", "a", access_token=self.user2_token
  288. )
  289. self.assertEquals(200, channel.code, channel.json_body)
  290. # Now lets redact one of the 'a' reactions
  291. channel = self.make_request(
  292. "POST",
  293. "/_matrix/client/r0/rooms/%s/redact/%s" % (self.room, to_redact_event_id),
  294. access_token=self.user_token,
  295. content={},
  296. )
  297. self.assertEquals(200, channel.code, channel.json_body)
  298. channel = self.make_request(
  299. "GET",
  300. "/_matrix/client/unstable/rooms/%s/aggregations/%s"
  301. % (self.room, self.parent_id),
  302. access_token=self.user_token,
  303. )
  304. self.assertEquals(200, channel.code, channel.json_body)
  305. self.assertEquals(
  306. channel.json_body,
  307. {"chunk": [{"type": "m.reaction", "key": "a", "count": 1}]},
  308. )
  309. def test_aggregation_must_be_annotation(self):
  310. """Test that aggregations must be annotations.
  311. """
  312. channel = self.make_request(
  313. "GET",
  314. "/_matrix/client/unstable/rooms/%s/aggregations/%s/%s?limit=1"
  315. % (self.room, self.parent_id, RelationTypes.REPLACE),
  316. access_token=self.user_token,
  317. )
  318. self.assertEquals(400, channel.code, channel.json_body)
  319. def test_aggregation_get_event(self):
  320. """Test that annotations and references get correctly bundled when
  321. getting the parent event.
  322. """
  323. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "a")
  324. self.assertEquals(200, channel.code, channel.json_body)
  325. channel = self._send_relation(
  326. RelationTypes.ANNOTATION, "m.reaction", "a", access_token=self.user2_token
  327. )
  328. self.assertEquals(200, channel.code, channel.json_body)
  329. channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
  330. self.assertEquals(200, channel.code, channel.json_body)
  331. channel = self._send_relation(RelationTypes.REFERENCE, "m.room.test")
  332. self.assertEquals(200, channel.code, channel.json_body)
  333. reply_1 = channel.json_body["event_id"]
  334. channel = self._send_relation(RelationTypes.REFERENCE, "m.room.test")
  335. self.assertEquals(200, channel.code, channel.json_body)
  336. reply_2 = channel.json_body["event_id"]
  337. channel = self.make_request(
  338. "GET",
  339. "/rooms/%s/event/%s" % (self.room, self.parent_id),
  340. access_token=self.user_token,
  341. )
  342. self.assertEquals(200, channel.code, channel.json_body)
  343. self.assertEquals(
  344. channel.json_body["unsigned"].get("m.relations"),
  345. {
  346. RelationTypes.ANNOTATION: {
  347. "chunk": [
  348. {"type": "m.reaction", "key": "a", "count": 2},
  349. {"type": "m.reaction", "key": "b", "count": 1},
  350. ]
  351. },
  352. RelationTypes.REFERENCE: {
  353. "chunk": [{"event_id": reply_1}, {"event_id": reply_2}]
  354. },
  355. },
  356. )
  357. def test_edit(self):
  358. """Test that a simple edit works.
  359. """
  360. new_body = {"msgtype": "m.text", "body": "I've been edited!"}
  361. channel = self._send_relation(
  362. RelationTypes.REPLACE,
  363. "m.room.message",
  364. content={"msgtype": "m.text", "body": "foo", "m.new_content": new_body},
  365. )
  366. self.assertEquals(200, channel.code, channel.json_body)
  367. edit_event_id = channel.json_body["event_id"]
  368. channel = self.make_request(
  369. "GET",
  370. "/rooms/%s/event/%s" % (self.room, self.parent_id),
  371. access_token=self.user_token,
  372. )
  373. self.assertEquals(200, channel.code, channel.json_body)
  374. self.assertEquals(channel.json_body["content"], new_body)
  375. relations_dict = channel.json_body["unsigned"].get("m.relations")
  376. self.assertIn(RelationTypes.REPLACE, relations_dict)
  377. m_replace_dict = relations_dict[RelationTypes.REPLACE]
  378. for key in ["event_id", "sender", "origin_server_ts"]:
  379. self.assertIn(key, m_replace_dict)
  380. self.assert_dict(
  381. {"event_id": edit_event_id, "sender": self.user_id}, m_replace_dict
  382. )
  383. def test_multi_edit(self):
  384. """Test that multiple edits, including attempts by people who
  385. shouldn't be allowed, are correctly handled.
  386. """
  387. channel = self._send_relation(
  388. RelationTypes.REPLACE,
  389. "m.room.message",
  390. content={
  391. "msgtype": "m.text",
  392. "body": "Wibble",
  393. "m.new_content": {"msgtype": "m.text", "body": "First edit"},
  394. },
  395. )
  396. self.assertEquals(200, channel.code, channel.json_body)
  397. new_body = {"msgtype": "m.text", "body": "I've been edited!"}
  398. channel = self._send_relation(
  399. RelationTypes.REPLACE,
  400. "m.room.message",
  401. content={"msgtype": "m.text", "body": "foo", "m.new_content": new_body},
  402. )
  403. self.assertEquals(200, channel.code, channel.json_body)
  404. edit_event_id = channel.json_body["event_id"]
  405. channel = self._send_relation(
  406. RelationTypes.REPLACE,
  407. "m.room.message.WRONG_TYPE",
  408. content={
  409. "msgtype": "m.text",
  410. "body": "Wibble",
  411. "m.new_content": {"msgtype": "m.text", "body": "Edit, but wrong type"},
  412. },
  413. )
  414. self.assertEquals(200, channel.code, channel.json_body)
  415. channel = self.make_request(
  416. "GET",
  417. "/rooms/%s/event/%s" % (self.room, self.parent_id),
  418. access_token=self.user_token,
  419. )
  420. self.assertEquals(200, channel.code, channel.json_body)
  421. self.assertEquals(channel.json_body["content"], new_body)
  422. relations_dict = channel.json_body["unsigned"].get("m.relations")
  423. self.assertIn(RelationTypes.REPLACE, relations_dict)
  424. m_replace_dict = relations_dict[RelationTypes.REPLACE]
  425. for key in ["event_id", "sender", "origin_server_ts"]:
  426. self.assertIn(key, m_replace_dict)
  427. self.assert_dict(
  428. {"event_id": edit_event_id, "sender": self.user_id}, m_replace_dict
  429. )
  430. def test_relations_redaction_redacts_edits(self):
  431. """Test that edits of an event are redacted when the original event
  432. is redacted.
  433. """
  434. # Send a new event
  435. res = self.helper.send(self.room, body="Heyo!", tok=self.user_token)
  436. original_event_id = res["event_id"]
  437. # Add a relation
  438. channel = self._send_relation(
  439. RelationTypes.REPLACE,
  440. "m.room.message",
  441. parent_id=original_event_id,
  442. content={
  443. "msgtype": "m.text",
  444. "body": "Wibble",
  445. "m.new_content": {"msgtype": "m.text", "body": "First edit"},
  446. },
  447. )
  448. self.assertEquals(200, channel.code, channel.json_body)
  449. # Check the relation is returned
  450. channel = self.make_request(
  451. "GET",
  452. "/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
  453. % (self.room, original_event_id),
  454. access_token=self.user_token,
  455. )
  456. self.assertEquals(200, channel.code, channel.json_body)
  457. self.assertIn("chunk", channel.json_body)
  458. self.assertEquals(len(channel.json_body["chunk"]), 1)
  459. # Redact the original event
  460. channel = self.make_request(
  461. "PUT",
  462. "/rooms/%s/redact/%s/%s"
  463. % (self.room, original_event_id, "test_relations_redaction_redacts_edits"),
  464. access_token=self.user_token,
  465. content="{}",
  466. )
  467. self.assertEquals(200, channel.code, channel.json_body)
  468. # Try to check for remaining m.replace relations
  469. channel = self.make_request(
  470. "GET",
  471. "/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
  472. % (self.room, original_event_id),
  473. access_token=self.user_token,
  474. )
  475. self.assertEquals(200, channel.code, channel.json_body)
  476. # Check that no relations are returned
  477. self.assertIn("chunk", channel.json_body)
  478. self.assertEquals(channel.json_body["chunk"], [])
  479. def test_aggregations_redaction_prevents_access_to_aggregations(self):
  480. """Test that annotations of an event are redacted when the original event
  481. is redacted.
  482. """
  483. # Send a new event
  484. res = self.helper.send(self.room, body="Hello!", tok=self.user_token)
  485. original_event_id = res["event_id"]
  486. # Add a relation
  487. channel = self._send_relation(
  488. RelationTypes.ANNOTATION, "m.reaction", key="👍", parent_id=original_event_id
  489. )
  490. self.assertEquals(200, channel.code, channel.json_body)
  491. # Redact the original
  492. channel = self.make_request(
  493. "PUT",
  494. "/rooms/%s/redact/%s/%s"
  495. % (
  496. self.room,
  497. original_event_id,
  498. "test_aggregations_redaction_prevents_access_to_aggregations",
  499. ),
  500. access_token=self.user_token,
  501. content="{}",
  502. )
  503. self.assertEquals(200, channel.code, channel.json_body)
  504. # Check that aggregations returns zero
  505. channel = self.make_request(
  506. "GET",
  507. "/_matrix/client/unstable/rooms/%s/aggregations/%s/m.annotation/m.reaction"
  508. % (self.room, original_event_id),
  509. access_token=self.user_token,
  510. )
  511. self.assertEquals(200, channel.code, channel.json_body)
  512. self.assertIn("chunk", channel.json_body)
  513. self.assertEquals(channel.json_body["chunk"], [])
  514. def _send_relation(
  515. self,
  516. relation_type,
  517. event_type,
  518. key=None,
  519. content={},
  520. access_token=None,
  521. parent_id=None,
  522. ):
  523. """Helper function to send a relation pointing at `self.parent_id`
  524. Args:
  525. relation_type (str): One of `RelationTypes`
  526. event_type (str): The type of the event to create
  527. parent_id (str): The event_id this relation relates to. If None, then self.parent_id
  528. key (str|None): The aggregation key used for m.annotation relation
  529. type.
  530. content(dict|None): The content of the created event.
  531. access_token (str|None): The access token used to send the relation,
  532. defaults to `self.user_token`
  533. Returns:
  534. FakeChannel
  535. """
  536. if not access_token:
  537. access_token = self.user_token
  538. query = ""
  539. if key:
  540. query = "?key=" + urllib.parse.quote_plus(key.encode("utf-8"))
  541. original_id = parent_id if parent_id else self.parent_id
  542. channel = self.make_request(
  543. "POST",
  544. "/_matrix/client/unstable/rooms/%s/send_relation/%s/%s/%s%s"
  545. % (self.room, original_id, relation_type, event_type, query),
  546. json.dumps(content).encode("utf-8"),
  547. access_token=access_token,
  548. )
  549. return channel
  550. def _create_user(self, localpart):
  551. user_id = self.register_user(localpart, "abc123")
  552. access_token = self.login(localpart, "abc123")
  553. return user_id, access_token