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

Add type hints to event push actions tests. #13099

Merged
merged 2 commits into from
Jun 17, 2022
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
2 changes: 1 addition & 1 deletion changelog.d/12985.misc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add type annotations to `tests.state.test_v2`.
Add type hints to tests.
1 change: 1 addition & 0 deletions changelog.d/13099.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type hints to tests.
28 changes: 17 additions & 11 deletions tests/storage/test_event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

from unittest.mock import Mock

from twisted.test.proto_helpers import MemoryReactor

from synapse.server import HomeServer
from synapse.storage.databases.main.event_push_actions import NotifCounts
from synapse.util import Clock

from tests.unittest import HomeserverTestCase

Expand All @@ -29,31 +33,33 @@


class EventPushActionsStoreTestCase(HomeserverTestCase):
def prepare(self, reactor, clock, hs):
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.store = hs.get_datastores().main
self.persist_events_store = hs.get_datastores().persist_events
persist_events_store = hs.get_datastores().persist_events
assert persist_events_store is not None
self.persist_events_store = persist_events_store

def test_get_unread_push_actions_for_user_in_range_for_http(self):
def test_get_unread_push_actions_for_user_in_range_for_http(self) -> None:
self.get_success(
self.store.get_unread_push_actions_for_user_in_range_for_http(
USER_ID, 0, 1000, 20
)
)

def test_get_unread_push_actions_for_user_in_range_for_email(self):
def test_get_unread_push_actions_for_user_in_range_for_email(self) -> None:
self.get_success(
self.store.get_unread_push_actions_for_user_in_range_for_email(
USER_ID, 0, 1000, 20
)
)

def test_count_aggregation(self):
def test_count_aggregation(self) -> None:
room_id = "!foo:example.com"
user_id = "@user1235:example.com"

last_read_stream_ordering = [0]

def _assert_counts(noitf_count, highlight_count):
def _assert_counts(noitf_count: int, highlight_count: int) -> None:
counts = self.get_success(
self.store.db_pool.runInteraction(
"",
Expand All @@ -72,7 +78,7 @@ def _assert_counts(noitf_count, highlight_count):
),
)

def _inject_actions(stream, action):
def _inject_actions(stream: int, action: list) -> None:
event = Mock()
event.room_id = room_id
event.event_id = "$test:example.com"
Expand All @@ -96,14 +102,14 @@ def _inject_actions(stream, action):
)
)

def _rotate(stream):
def _rotate(stream: int) -> None:
self.get_success(
self.store.db_pool.runInteraction(
"", self.store._rotate_notifs_before_txn, stream
)
)

def _mark_read(stream, depth):
def _mark_read(stream: int, depth: int) -> None:
last_read_stream_ordering[0] = stream
self.get_success(
self.store.db_pool.runInteraction(
Expand Down Expand Up @@ -165,8 +171,8 @@ def _mark_read(stream, depth):
_mark_read(10, 10)
_assert_counts(0, 0)

def test_find_first_stream_ordering_after_ts(self):
def add_event(so, ts):
def test_find_first_stream_ordering_after_ts(self) -> None:
def add_event(so: int, ts: int) -> None:
self.get_success(
self.store.db_pool.simple_insert(
"events",
Expand Down