Skip to content

Commit

Permalink
rename notification_email fields and implement get_notification_emails
Browse files Browse the repository at this point in the history
  • Loading branch information
simodalla committed Mar 17, 2014
1 parent d23ecd0 commit a5d6bb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions nowait/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def get_or_create_link(self):
return link, created

def get_notification_emails(self):
"""
Return list of email addresses from email of self.operators and from
self.notification_emails
:return: list of email address
:rtype: list of string
"""
emails = [operator.email for operator in self.operators.all()]
emails += [email.email for email in self.notification_emails.all()]
return emails
Expand Down
24 changes: 22 additions & 2 deletions nowait/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ def test_get_or_create_link_delete_old_link(self):
self.assertEqual(link.title, obj.title)
old_wrong_link.delete.assert_called_once_with()

def test_get_notifacation_email_of_only_operators(self):
n_operators = 3
booking_type = BookingType.objects.create(title=self.title)
[booking_type.operators.add(UserF()) for i in range(0, n_operators)]
emails = booking_type.get_notification_emails()
self.assertSequenceEqual(
emails,
[operator.email for operator in booking_type.operators.all()])

def test_get_notifacation_email_of_only_notification_emails(self):
n_emails = 3
booking_type = BookingType.objects.create(title=self.title)
[booking_type.notification_emails.add(
Email.objects.create(email='email_{}@example.com'.format(i)))
for i in range(0, n_emails)]
emails = booking_type.get_notification_emails()
self.assertSequenceEqual(
emails,
[email for email in Email.objects.values_list('email', flat=True)])


class DailySlotTimePatternModelTest(TestCase):

Expand Down Expand Up @@ -361,7 +381,7 @@ def test_send_emails_on_creation_without_errors(
emails = ['mail1@example.com', 'mail2@example.com']
mock_emails = Mock()
mock_emails.return_value = emails
self.slottime.booking_type.get_notification_email = mock_emails
self.slottime.booking_type.get_notification_emails = mock_emails
request = RequestFactory().get('/fake')
booking = Booking()
booking.booker = self.booker
Expand All @@ -380,7 +400,7 @@ def test_send_emails_on_creation_without_errors(
def test_send_emails_on_creation_raise_exception(
self, mock_send_mail_template, mock_get_logger):
exception = SMTPException('Boom!')
self.slottime.booking_type.get_notification_email = (
self.slottime.booking_type.get_notification_emails = (
Mock(return_value=[]))
mock_send_mail_template.side_effect = exception
mock_logger = Mock()
Expand Down

0 comments on commit a5d6bb1

Please sign in to comment.