1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14+ from typing import Any , Dict , List
1415from unittest .mock import Mock
1516
1617from twisted .internet import defer
18+ from twisted .test .proto_helpers import MemoryReactor
1719
1820from synapse .api .constants import UserTypes
21+ from synapse .server import HomeServer
22+ from synapse .util import Clock
1923
2024from tests import unittest
2125from tests .test_utils import make_awaitable
2428FORTY_DAYS = 40 * 24 * 60 * 60
2529
2630
27- def gen_3pids (count ) :
31+ def gen_3pids (count : int ) -> List [ Dict [ str , Any ]] :
2832 """Generate `count` threepids as a list."""
2933 return [
3034 {"medium" : "email" , "address" : "user%i@matrix.org" % i } for i in range (count )
3135 ]
3236
3337
3438class MonthlyActiveUsersTestCase (unittest .HomeserverTestCase ):
35- def default_config (self ):
39+ def default_config (self ) -> Dict [ str , Any ] :
3640 config = default_config ("test" )
3741
3842 config .update ({"limit_usage_by_mau" : True , "max_mau_value" : 50 })
@@ -44,10 +48,10 @@ def default_config(self):
4448
4549 return config
4650
47- def prepare (self , reactor , clock , homeserver ) :
48- self .store = homeserver .get_datastores ().main
51+ def prepare (self , reactor : MemoryReactor , clock : Clock , hs : HomeServer ) -> None :
52+ self .store = hs .get_datastores ().main
4953 # Advance the clock a bit
50- reactor .advance (FORTY_DAYS )
54+ self . reactor .advance (FORTY_DAYS )
5155
5256 @override_config ({"max_mau_value" : 3 , "mau_limit_reserved_threepids" : gen_3pids (3 )})
5357 def test_initialise_reserved_users (self ):
@@ -245,17 +249,17 @@ def test_populate_monthly_users_is_guest(self):
245249 )
246250 self .get_success (d )
247251
248- self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None ))
252+ self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None )) # type: ignore[assignment]
249253
250254 d = self .store .populate_monthly_active_users (user_id )
251255 self .get_success (d )
252256
253257 self .store .upsert_monthly_active_user .assert_not_called ()
254258
255259 def test_populate_monthly_users_should_update (self ):
256- self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None ))
260+ self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None )) # type: ignore[assignment]
257261
258- self .store .is_trial_user = Mock (return_value = defer .succeed (False ))
262+ self .store .is_trial_user = Mock (return_value = defer .succeed (False )) # type: ignore[assignment]
259263
260264 self .store .user_last_seen_monthly_active = Mock (
261265 return_value = defer .succeed (None )
@@ -266,9 +270,9 @@ def test_populate_monthly_users_should_update(self):
266270 self .store .upsert_monthly_active_user .assert_called_once ()
267271
268272 def test_populate_monthly_users_should_not_update (self ):
269- self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None ))
273+ self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None )) # type: ignore[assignment]
270274
271- self .store .is_trial_user = Mock (return_value = defer .succeed (False ))
275+ self .store .is_trial_user = Mock (return_value = defer .succeed (False )) # type: ignore[assignment]
272276 self .store .user_last_seen_monthly_active = Mock (
273277 return_value = defer .succeed (self .hs .get_clock ().time_msec ())
274278 )
@@ -324,16 +328,15 @@ def test_support_user_not_add_to_mau_limits(self):
324328 count = self .get_success (self .store .get_monthly_active_count ())
325329 self .assertEqual (count , 0 )
326330
327- d = self .store .register_user (
328- user_id = support_user_id , password_hash = None , user_type = UserTypes .SUPPORT
331+ self .get_success (
332+ self .store .register_user (
333+ user_id = support_user_id , password_hash = None , user_type = UserTypes .SUPPORT
334+ )
329335 )
330- self .get_success (d )
331336
332- d = self .store .upsert_monthly_active_user (support_user_id )
333- self .get_success (d )
337+ self .get_success (self .store .upsert_monthly_active_user (support_user_id ))
334338
335- d = self .store .get_monthly_active_count ()
336- count = self .get_success (d )
339+ count = self .get_success (self .store .get_monthly_active_count ())
337340 self .assertEqual (count , 0 )
338341
339342 # Note that the max_mau_value setting should not matter.
@@ -352,7 +355,7 @@ def test_track_monthly_users_without_cap(self):
352355
353356 @override_config ({"limit_usage_by_mau" : False , "mau_stats_only" : False })
354357 def test_no_users_when_not_tracking (self ):
355- self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None ))
358+ self .store .upsert_monthly_active_user = Mock (return_value = make_awaitable (None )) # type: ignore[assignment]
356359
357360 self .get_success (self .store .populate_monthly_active_users ("@user:sever" ))
358361
@@ -388,16 +391,16 @@ def test_get_monthly_active_count_by_service(self):
388391 self .store .register_user (user_id = native_user1 , password_hash = None )
389392 )
390393
391- count = self .get_success (self .store .get_monthly_active_count_by_service ())
392- self .assertEqual (count , {})
394+ count1 = self .get_success (self .store .get_monthly_active_count_by_service ())
395+ self .assertEqual (count1 , {})
393396
394397 self .get_success (self .store .upsert_monthly_active_user (native_user1 ))
395398 self .get_success (self .store .upsert_monthly_active_user (appservice1_user1 ))
396399 self .get_success (self .store .upsert_monthly_active_user (appservice1_user2 ))
397400 self .get_success (self .store .upsert_monthly_active_user (appservice2_user1 ))
398401
399- count = self .get_success (self .store .get_monthly_active_count ())
400- self .assertEqual (count , 1 )
402+ count2 = self .get_success (self .store .get_monthly_active_count ())
403+ self .assertEqual (count2 , 1 )
401404
402405 d = self .store .get_monthly_active_count_by_service ()
403406 result = self .get_success (d )
0 commit comments