summary refs log tree commit diff
path: root/tests/test_utils/event_injection.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2020-05-06 11:58:31 +0100
committerRichard van der Hoff <richard@matrix.org>2020-05-06 11:58:31 +0100
commit2e0c46ca07564d9592e5ec7d260e40c0659daa80 (patch)
tree598b91e8ee09902969038d9e1616471a7108adfe /tests/test_utils/event_injection.py
parentMerge pull request #7429 from matrix-org/rav/upsert_for_device_list (diff)
parentMove logs about discarded RDATA to debug (#7421) (diff)
downloadsynapse-2e0c46ca07564d9592e5ec7d260e40c0659daa80.tar.xz
Merge branch 'release-v1.13.0' into develop
Diffstat (limited to 'tests/test_utils/event_injection.py')
-rw-r--r--tests/test_utils/event_injection.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/test_utils/event_injection.py b/tests/test_utils/event_injection.py
index 8f6872761a..431e9f8e5e 100644
--- a/tests/test_utils/event_injection.py
+++ b/tests/test_utils/event_injection.py
@@ -14,12 +14,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Optional
+from typing import Optional, Tuple
 
 import synapse.server
 from synapse.api.constants import EventTypes
 from synapse.api.room_versions import KNOWN_ROOM_VERSIONS
 from synapse.events import EventBase
+from synapse.events.snapshot import EventContext
 from synapse.types import Collection
 
 from tests.test_utils import get_awaitable_result
@@ -75,6 +76,23 @@ def inject_event(
     """
     test_reactor = hs.get_reactor()
 
+    event, context = create_event(hs, room_version, prev_event_ids, **kwargs)
+
+    d = hs.get_storage().persistence.persist_event(event, context)
+    test_reactor.advance(0)
+    get_awaitable_result(d)
+
+    return event
+
+
+def create_event(
+    hs: synapse.server.HomeServer,
+    room_version: Optional[str] = None,
+    prev_event_ids: Optional[Collection[str]] = None,
+    **kwargs
+) -> Tuple[EventBase, EventContext]:
+    test_reactor = hs.get_reactor()
+
     if room_version is None:
         d = hs.get_datastore().get_room_version_id(kwargs["room_id"])
         test_reactor.advance(0)
@@ -89,8 +107,4 @@ def inject_event(
     test_reactor.advance(0)
     event, context = get_awaitable_result(d)
 
-    d = hs.get_storage().persistence.persist_event(event, context)
-    test_reactor.advance(0)
-    get_awaitable_result(d)
-
-    return event
+    return event, context