@@ -298,10 +298,15 @@ def test_multiple_events_only_following_false(self):
298298
299299 @freeze_time ('2013-1-2' )
300300 def test_bulk_multiple_events_only_following_false (self ):
301+ """
302+ Handles bulk creating events and tests the unique constraint of the duplicated subscription which would cause
303+ a bulk create error if it wasn't handled
304+ """
301305 source = G (Source )
302306 e = G (Entity )
303307 other_e = G (Entity )
304308
309+ G (Subscription , entity = e , source = source , medium = self .email_medium , only_following = False )
305310 G (Subscription , entity = e , source = source , medium = self .email_medium , only_following = False )
306311 G (Subscription , entity = other_e , source = source , medium = self .email_medium , only_following = False )
307312 email_context = {
@@ -320,6 +325,35 @@ def test_bulk_multiple_events_only_following_false(self):
320325 self .assertEquals (email .subject , '' )
321326 self .assertEquals (email .scheduled , datetime (2013 , 1 , 2 ))
322327
328+ @freeze_time ('2013-1-2' )
329+ def test_bulk_multiple_events_only_following_true (self ):
330+ """
331+ Handles bulk creating events and tests the unique constraint of the duplicated subscription which would cause
332+ a bulk create error if it wasn't handled
333+ """
334+ source = G (Source )
335+ e = G (Entity )
336+ other_e = G (Entity )
337+
338+ G (Subscription , entity = e , source = source , medium = self .email_medium , only_following = True )
339+ G (Subscription , entity = e , source = source , medium = self .email_medium , only_following = True )
340+ G (Subscription , entity = other_e , source = source , medium = self .email_medium , only_following = True )
341+ email_context = {
342+ 'entity_emailer_template' : 'template' ,
343+ 'entity_emailer_subject' : 'hi' ,
344+ }
345+ G (Event , source = source , context = email_context )
346+ event = G (Event , source = source , context = email_context )
347+ G (EventActor , event = event , entity = e )
348+
349+ EntityEmailerInterface .bulk_convert_events_to_emails ()
350+
351+ email = Email .objects .get ()
352+ self .assertEquals (set (email .recipients .all ()), set ([e ]))
353+ self .assertEquals (email .event .context , email_context )
354+ self .assertEquals (email .subject , '' )
355+ self .assertEquals (email .scheduled , datetime (2013 , 1 , 2 ))
356+
323357 @freeze_time ('2013-1-2' )
324358 def test_multiple_events_only_following_true (self ):
325359 source = G (Source )
@@ -371,7 +405,7 @@ def test_sends_all_scheduled_emails(self, render_mock, address_mock):
371405 with patch (settings .EMAIL_BACKEND ) as mock_connection :
372406 EntityEmailerInterface .send_unsent_scheduled_emails ()
373407
374- self .assertEqual (2 , mock_connection .return_value .__enter__ .return_value .send_message .call_count )
408+ self .assertEqual (2 , mock_connection .return_value .__enter__ .return_value .send_messages .call_count )
375409
376410 @patch ('entity_emailer.interface.pre_send' )
377411 @patch ('entity_emailer.interface.get_subscribed_email_addresses' )
@@ -392,7 +426,7 @@ def test_send_signals(self, render_mock, address_mock, mock_pre_send):
392426 EntityEmailerInterface .send_unsent_scheduled_emails ()
393427
394428 # Assert that we sent the email
395- self .assertEqual (1 , mock_connection .return_value .__enter__ .return_value .send_message .call_count )
429+ self .assertEqual (1 , mock_connection .return_value .__enter__ .return_value .send_messages .call_count )
396430
397431 # Assert that we called the pre send signal with the proper values
398432 name , args , kwargs = mock_pre_send .send .mock_calls [0 ]
@@ -416,7 +450,7 @@ def test_sends_email_with_specified_from_address(self, render_mock, address_mock
416450 with patch (settings .EMAIL_BACKEND ) as mock_connection :
417451 EntityEmailerInterface .send_unsent_scheduled_emails ()
418452
419- args = mock_connection .return_value .__enter__ .return_value .send_message .call_args
453+ args = mock_connection .return_value .__enter__ .return_value .send_messages .call_args
420454 self .assertEqual (args [0 ][0 ].from_email , from_address )
421455
422456 @patch ('entity_emailer.interface.get_subscribed_email_addresses' )
@@ -504,7 +538,7 @@ def to_dict(self):
504538
505539 with patch (settings .EMAIL_BACKEND ) as mock_connection :
506540 # Mock side effects for sending emails
507- mock_connection .return_value .__enter__ .return_value .send_message .side_effect = [
541+ mock_connection .return_value .__enter__ .return_value .send_messages .side_effect = [
508542 None ,
509543 TestEmailSendMessageException ('test' ),
510544 ]
0 commit comments