@@ -34,7 +34,7 @@ def model(self, mocker, initial_data, user_profile,
34
34
return_value = [])
35
35
mocker .patch ('zulipterminal.model.Model.'
36
36
'_stream_info_from_subscriptions' ,
37
- return_value = ({}, set (), [], []))
37
+ return_value = ({}, set (), [], [], set () ))
38
38
# NOTE: PATCH WHERE USED NOT WHERE DEFINED
39
39
self .classify_unread_counts = mocker .patch (
40
40
'zulipterminal.model.classify_unread_counts' ,
@@ -130,7 +130,7 @@ def test_init_InvalidAPIKey_response(self, mocker, initial_data):
130
130
return_value = [])
131
131
mocker .patch ('zulipterminal.model.Model.'
132
132
'_stream_info_from_subscriptions' ,
133
- return_value = ({}, set (), [], []))
133
+ return_value = ({}, set (), [], [], set () ))
134
134
self .classify_unread_counts = mocker .patch (
135
135
'zulipterminal.model.classify_unread_counts' ,
136
136
return_value = [])
@@ -152,7 +152,7 @@ def test_init_ZulipError_exception(self, mocker, initial_data,
152
152
return_value = [])
153
153
mocker .patch ('zulipterminal.model.Model.'
154
154
'_stream_info_from_subscriptions' ,
155
- return_value = ({}, set (), [], []))
155
+ return_value = ({}, set (), [], [], set () ))
156
156
self .classify_unread_counts = mocker .patch (
157
157
'zulipterminal.model.classify_unread_counts' ,
158
158
return_value = [])
@@ -557,7 +557,7 @@ def test_success_get_messages(self, mocker, messages_successful_response,
557
557
return_value = [])
558
558
mocker .patch ('zulipterminal.model.Model.'
559
559
'_stream_info_from_subscriptions' ,
560
- return_value = ({}, set (), [], []))
560
+ return_value = ({}, set (), [], [], set () ))
561
561
self .classify_unread_counts = mocker .patch (
562
562
'zulipterminal.model.classify_unread_counts' ,
563
563
return_value = [])
@@ -597,7 +597,7 @@ def test_get_message_false_first_anchor(
597
597
return_value = [])
598
598
mocker .patch ('zulipterminal.model.Model.'
599
599
'_stream_info_from_subscriptions' ,
600
- return_value = ({}, set (), [], []))
600
+ return_value = ({}, set (), [], [], set () ))
601
601
self .classify_unread_counts = mocker .patch (
602
602
'zulipterminal.model.classify_unread_counts' ,
603
603
return_value = [])
@@ -631,7 +631,7 @@ def test_fail_get_messages(self, mocker, error_response,
631
631
return_value = [])
632
632
mocker .patch ('zulipterminal.model.Model.'
633
633
'_stream_info_from_subscriptions' ,
634
- return_value = ({}, set (), [], []))
634
+ return_value = ({}, set (), [], [], set () ))
635
635
self .classify_unread_counts = mocker .patch (
636
636
'zulipterminal.model.classify_unread_counts' ,
637
637
return_value = [])
@@ -666,6 +666,29 @@ def test_toggle_stream_muted_status(self, mocker, model,
666
666
self .display_error_if_present .assert_called_once_with (response ,
667
667
self .controller )
668
668
669
+ @pytest .mark .parametrize ('initial_desktop_notified_streams, value' , [
670
+ ({315 }, True ),
671
+ ({205 , 315 }, False ),
672
+ (set (), True ),
673
+ ({205 }, False ),
674
+ ], ids = ['desktop_notify_enable_205' , 'desktop_notify_disable_205' ,
675
+ 'first_notify_enable_205' , 'last_notify_disable_205' ])
676
+ def test_toggle_stream_desktop_notification (
677
+ self , mocker , model , initial_desktop_notified_streams ,
678
+ value , response = {'result' : 'success' }):
679
+ model .desktop_notifs_enabled_streams = initial_desktop_notified_streams
680
+ model .client .update_subscription_settings .return_value = response
681
+ model .toggle_stream_desktop_notification (205 )
682
+ request = [{
683
+ 'stream_id' : 205 ,
684
+ 'property' : 'desktop_notifications' ,
685
+ 'value' : value
686
+ }]
687
+ (model .client .update_subscription_settings
688
+ .assert_called_once_with (request ))
689
+ self .display_error_if_present .assert_called_once_with (response ,
690
+ self .controller )
691
+
669
692
@pytest .mark .parametrize ('flags_before, expected_operator' , [
670
693
([], 'add' ),
671
694
(['starred' ], 'remove' ),
@@ -716,7 +739,7 @@ def test__update_initial_data_raises_exception(self, mocker, initial_data):
716
739
return_value = [])
717
740
mocker .patch ('zulipterminal.model.Model.'
718
741
'_stream_info_from_subscriptions' ,
719
- return_value = ({}, set (), [], []))
742
+ return_value = ({}, set (), [], [], set () ))
720
743
self .classify_unread_counts = mocker .patch (
721
744
'zulipterminal.model.classify_unread_counts' ,
722
745
return_value = [])
@@ -750,26 +773,32 @@ def test_get_all_users(self, mocker, initial_data, user_list, user_dict,
750
773
self .client .register .return_value = initial_data
751
774
mocker .patch ('zulipterminal.model.Model.'
752
775
'_stream_info_from_subscriptions' ,
753
- return_value = ({}, set (), [], []))
776
+ return_value = ({}, set (), [], [], set () ))
754
777
self .classify_unread_counts = mocker .patch (
755
778
'zulipterminal.model.classify_unread_counts' ,
756
779
return_value = [])
757
780
model = Model (self .controller )
758
781
assert model .user_dict == user_dict
759
782
assert model .users == user_list
760
783
761
- @pytest .mark .parametrize ('muted' , powerset ([1 , 2 , 99 , 1000 ]))
784
+ @pytest .mark .parametrize ('muted, desktop_notifs_enabled' , list (
785
+ zip (powerset ([1 , 2 , 99 , 1000 ]), powerset ([1 , 2 , 99 , 1000 ])))
786
+ )
762
787
def test__stream_info_from_subscriptions (self , initial_data , streams ,
763
- muted ):
764
- subs = [dict (entry , in_home_view = entry ['stream_id' ] not in muted )
788
+ muted , desktop_notifs_enabled ):
789
+ subs = [dict (entry , in_home_view = entry ['stream_id' ] not in muted ,
790
+ desktop_notifications = entry ['stream_id' ] in
791
+ desktop_notifs_enabled )
765
792
for entry in initial_data ['subscriptions' ]]
766
- by_id , muted_streams , pinned , unpinned = (
793
+ (by_id , muted_streams , pinned , unpinned ,
794
+ desktop_notifs_enabled_streams ) = (
767
795
Model ._stream_info_from_subscriptions (subs ))
768
796
assert len (by_id )
769
797
assert all (msg_id == msg ['stream_id' ] for msg_id , msg in by_id .items ())
770
798
assert muted_streams == muted
771
799
assert pinned == [] # FIXME generalize/parametrize
772
800
assert unpinned == streams # FIXME generalize/parametrize
801
+ assert desktop_notifs_enabled_streams == desktop_notifs_enabled
773
802
774
803
def test__handle_message_event_with_Falsey_log (self , mocker ,
775
804
model , message_fixture ):
@@ -939,7 +968,8 @@ def test__update_topic_index(self, topic_name, topic_order_initial,
939
968
assert model .index ['topics' ][86 ] == topic_order_final
940
969
941
970
# TODO: Ideally message_fixture would use standardized ids?
942
- @pytest .mark .parametrize (['user_id' , 'vary_each_msg' , 'stream_setting' ,
971
+ @pytest .mark .parametrize (['user_id' , 'vary_each_msg' ,
972
+ 'desktop_notification_status' ,
943
973
'types_when_notify_called' ], [
944
974
(5140 , {'flags' : ['mentioned' , 'wildcard_mentioned' ]}, True ,
945
975
[]), # message_fixture sender_id is 5140
@@ -962,15 +992,13 @@ def test_notify_users_calling_msg_type(self, mocker, model,
962
992
message_fixture ,
963
993
user_id ,
964
994
vary_each_msg ,
965
- stream_setting ,
995
+ desktop_notification_status ,
966
996
types_when_notify_called ):
967
997
message_fixture .update (vary_each_msg )
968
998
model .user_id = user_id
969
- if 'stream_id' in message_fixture :
970
- model .stream_dict .update (
971
- {message_fixture ['stream_id' ]:
972
- {'desktop_notifications' : stream_setting }}
973
- )
999
+ mocker .patch ('zulipterminal.model.Model.'
1000
+ 'is_desktop_notifications_enabled' ,
1001
+ return_value = desktop_notification_status )
974
1002
notify = mocker .patch ('zulipterminal.model.notify' )
975
1003
976
1004
model .notify_user (message_fixture )
@@ -1770,6 +1798,34 @@ def set_from_list_of_dict(data):
1770
1798
update_left_panel .assert_called_once_with ()
1771
1799
model .controller .update_screen .assert_called_once_with ()
1772
1800
1801
+ @pytest .mark .parametrize ('event, final_desktop_notified_streams, ' , [
1802
+ (
1803
+ {'property' : 'desktop_notifications' ,
1804
+ 'op' : 'update' ,
1805
+ 'stream_id' : 19 ,
1806
+ 'value' : False },
1807
+ {15 }
1808
+ ),
1809
+ (
1810
+ {'property' : 'desktop_notifications' ,
1811
+ 'op' : 'update' ,
1812
+ 'stream_id' : 30 ,
1813
+ 'value' : True },
1814
+ {15 , 19 , 30 }
1815
+ )
1816
+ ], ids = [
1817
+ 'remove_19' , 'add_30'
1818
+ ])
1819
+ def test__handle_subscription_event_desktop_notified_streams (
1820
+ self , model , mocker , stream_button , event ,
1821
+ final_desktop_notified_streams ):
1822
+ model .desktop_notifs_enabled_streams = {15 , 19 }
1823
+ model ._handle_subscription_event (event )
1824
+
1825
+ assert (model .desktop_notifs_enabled_streams
1826
+ == final_desktop_notified_streams )
1827
+ model .controller .update_screen .assert_called_once_with ()
1828
+
1773
1829
@pytest .mark .parametrize (['event' , 'feature_level' ,
1774
1830
'stream_id' , 'expected_subscribers' ], [
1775
1831
({'op' : 'peer_add' , 'stream_id' : 99 , 'user_id' : 12 }, None ,
@@ -1903,6 +1959,20 @@ def test_is_muted_stream(self, muted_streams, stream_id, is_muted,
1903
1959
model .muted_streams = muted_streams
1904
1960
assert model .is_muted_stream (stream_id ) == is_muted
1905
1961
1962
+ @pytest .mark .parametrize (['desktop_notified_streams' ,
1963
+ 'stream_id' , 'is_enabled' ], [
1964
+ ({1 }, 1 , True ),
1965
+ ({1 , 3 , 7 }, 2 , False ),
1966
+ (set (), 1 , False ),
1967
+ ], ids = ['single_stream' , 'multiple_streams' , 'no_stream' ])
1968
+ def test_is_desktop_notifications_enabled (self , desktop_notified_streams ,
1969
+ stream_id , is_enabled ,
1970
+ stream_dict , model ):
1971
+ model .stream_dict = stream_dict
1972
+ model .desktop_notifs_enabled_streams = desktop_notified_streams
1973
+ assert (model .is_desktop_notifications_enabled (stream_id )
1974
+ == is_enabled )
1975
+
1906
1976
@pytest .mark .parametrize ('topic, is_muted' , [
1907
1977
((1 , 'stream muted & unmuted topic' ), False ),
1908
1978
((2 , 'muted topic' ), True ),
0 commit comments