11import pytest
2+ from django .utils import timezone
23from django .contrib .contenttypes .models import ContentType
34
45from osf .models import Notification , NotificationType , NotificationTypeEnum , EmailTask , Email
@@ -186,6 +187,26 @@ def test_get_users_emails(self):
186187 assert user_info ['user_id' ] == user ._id
187188 assert any (msg ['notification_id' ] == notification1 .id for msg in user_info ['info' ])
188189
190+ def test_get_users_emails_ignore_scheduled (self ):
191+ user = AuthUserFactory ()
192+ notification_type = NotificationType .objects .get (name = NotificationTypeEnum .USER_FILE_UPDATED )
193+ notification1 = Notification .objects .create (
194+ subscription = add_notification_subscription (user , notification_type , 'daily' ),
195+ event_context = {},
196+ sent = None
197+ )
198+ Notification .objects .create (
199+ subscription = add_notification_subscription (user , notification_type , 'daily' ),
200+ event_context = {},
201+ sent = None ,
202+ scheduled = timezone .now ()
203+ )
204+ res = list (get_users_emails ('daily' ))
205+ assert len (res ) == 1
206+ user_info = res [0 ]
207+ assert user_info ['user_id' ] == user ._id
208+ assert any (msg ['notification_id' ] == notification1 .id for msg in user_info ['info' ])
209+
189210 def test_get_moderators_emails (self ):
190211 user = AuthUserFactory ()
191212 provider = RegistrationProviderFactory ()
@@ -204,6 +225,30 @@ def test_get_moderators_emails(self):
204225 ]
205226 assert entry , 'Expected moderator digest group'
206227
228+ def test_get_moderators_emails_ignore_scheduled (self ):
229+ user = AuthUserFactory ()
230+ provider = RegistrationProviderFactory ()
231+ reg = RegistrationFactory (provider = provider )
232+ notification_type = NotificationType .objects .get (name = NotificationTypeEnum .PROVIDER_NEW_PENDING_SUBMISSIONS )
233+ subscription = add_notification_subscription (user , notification_type , 'daily' , subscribed_object = reg )
234+ Notification .objects .create (
235+ subscription = subscription ,
236+ event_context = {},
237+ sent = None
238+ )
239+ Notification .objects .create (
240+ subscription = subscription ,
241+ event_context = {},
242+ sent = None ,
243+ scheduled = timezone .now ()
244+ )
245+ res = list (get_moderators_emails ('daily' ))
246+ assert len (res ) >= 1
247+ entry = [
248+ x for x in res if x ['user_id' ] == user ._id and subscription .subscribed_object .id == reg .id
249+ ]
250+ assert entry , 'Expected moderator digest group'
251+
207252 def test_send_users_digest_email_end_to_end (self ):
208253 user = AuthUserFactory ()
209254 notification_type = NotificationType .objects .get (name = NotificationTypeEnum .USER_FILE_UPDATED )
0 commit comments