Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send submission to entire newsletter if subscriptions are empty #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion newsletter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ def __unicode__(self):
}

def submit(self):
subscriptions = self.subscriptions.filter(subscribed=True)
if self.subscriptions.all().count() == 0:
subscriptions = self.newsletter.subscription_set.filter(subscribed=True)
else:
subscriptions = self.subscriptions.filter(subscribed=True)

logger.info(
ugettext(u"Submitting %(submission)s to %(count)d people"),
Expand Down
24 changes: 23 additions & 1 deletion newsletter/tests/test_mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_submission_from_message(self):
self.assertFalse(sub.sending)

def test_submission_subscribed(self):
""" Test a simpel submission with single subscriber. """
""" Test a simple submission with single subscriber. """

self.s.subscribed = False
self.s.save()
Expand Down Expand Up @@ -214,6 +214,28 @@ def test_submitsubmission(self):
self.assertEmailContains(submission.message.title)
self.assertEmailContains(submission.newsletter.unsubscribe_url())

def test_submitsubmission_with_empty_list(self):
""" Test submission with empty subscription list. """

self.sub.prepared = True
self.sub.publish_date = now() - timedelta(seconds=1)
self.sub.subscriptions.clear()
self.sub.save()

Submission.submit_queue()

# Get the object fresh from DB, as to assure no caching takes place
submission = Submission.objects.get(pk=self.sub.pk)

self.assert_(submission.sent)
self.assertFalse(submission.sending)

# Make sure mail is being sent out
self.assertEquals(len(mail.outbox), 1)

# Make sure a submission contains the title and unsubscribe URL
self.assertEmailContains(submission.message.title)
self.assertEmailContains(submission.newsletter.unsubscribe_url())

class SubscriptionTestCase(UserTestCase, MailingTestCase):
def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
django-extensions
Django>=1.4.10
vobject
Pillow
chardet
surlex>=0.2.0
sorl-thumbnail
Expand Down