コード例 #1
0
    def test_update_newsletter_status_advanced(self):
        self.server.mails_hour = 2
        self.server.save()

        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.build_email_content = fake_email_content
        mailer.run()

        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 2)
        self.assertEquals(self.newsletter.status, Newsletter.SENDING)

        self.server.mails_hour = 0
        self.server.save()

        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.build_email_content = fake_email_content
        mailer.run()
        
        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 4)
        self.assertEquals(self.newsletter.status, Newsletter.SENT)
コード例 #2
0
    def test_update_newsletter_status_advanced(self):
        self.server.mails_hour = 2
        self.server.save()

        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.run()

        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(
            ContactMailingStatus.objects.filter(
                status=ContactMailingStatus.SENT,
                newsletter=self.newsletter).count(), 2)
        self.assertEquals(self.newsletter.status, Newsletter.SENDING)

        self.server.mails_hour = 0
        self.server.save()

        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.run()

        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(
            ContactMailingStatus.objects.filter(
                status=ContactMailingStatus.SENT,
                newsletter=self.newsletter).count(), 4)
        self.assertEquals(self.newsletter.status, Newsletter.SENT)
コード例 #3
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        activate(settings.LANGUAGE_CODE)

        for newsletter in Newsletter.objects.exclude(
            status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    # TODO:
                    #
                    # * implement proper logging
                    #
                    # * alter tests to address encoding
                    
                    #print 'Start emailing %s' % newsletter.title
                    print 'Start emailing %s' % unicode(newsletter.id,
                                                        encoding='utf-8')
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #4
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        activate(settings.LANGUAGE_CODE)

        for newsletter in Newsletter.objects.exclude(
                status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    # TODO:
                    #
                    # * implement proper logging
                    #
                    # * alter tests to address encoding

                    #print 'Start emailing %s' % newsletter.title
                    print 'Start emailing %s' % unicode(newsletter.id,
                                                        encoding='utf-8')
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #5
0
    def handle_noargs(self, **options):
        print 'Starting sending newsletters...'

        for newsletter in Newsletter.objects.exclude(
            status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter)
            if mailer.can_send:
                print 'Start emailing %s' % newsletter.title
                mailer.run()

        print 'End session sending'
コード例 #6
0
ファイル: newsletter.py プロジェクト: maisengasse/newsletter
 def send_mail_test(self, request, queryset):
     """Send newsletter in test"""
     for newsletter in queryset:
         if newsletter.test_contacts.count():
             mailer = Mailer(newsletter, test=True)
             mailer.run()
             self.message_user(request,
                               _('%s succesfully sent.') % newsletter)
         else:
             self.message_user(
                 request,
                 _('No test contacts assigned for %s.') % newsletter)
コード例 #7
0
 def send_mail_test(self, request, queryset):
     """Send newsletter in test"""
     for newsletter in queryset:
         if newsletter.test_contacts.count():
             mailer = Mailer(newsletter, test=True)
             try:
                 mailer.run()
             except HTMLParseError:
                 self.message_user(request, _('Unable send newsletter, due to errors within HTML.'))
                 continue
             self.message_user(request, _('%s succesfully sent.') % newsletter)
         else:
             self.message_user(request, _('No test contacts assigned for %s.') % newsletter)
コード例 #8
0
 def send_mail_test(self, request, queryset):
     """Send newsletter in test"""
     for newsletter in queryset:
         if newsletter.test_contacts.count():
             mailer = Mailer(newsletter, test=True)
             try:
                 mailer.run()
             except HTMLParseError:
                 self.message_user(request, _('Unable send newsletter, due to errors within HTML.'))
                 continue
             self.message_user(request, _('%s succesfully sent.') % newsletter)
         else:
             self.message_user(request, _('No test contacts assigned for %s.') % newsletter)
コード例 #9
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        for newsletter in Newsletter.objects.exclude(
                status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter)
            if mailer.can_send:
                if verbose:
                    print 'Start emailing %s' % newsletter.title
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #10
0
    def handle_noargs(self, **options):
        verbose = int(options["verbosity"])

        if verbose:
            print "Starting sending newsletters..."

        activate(settings.LANGUAGE_CODE)

        for newsletter in Newsletter.objects.exclude(status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    print u"Start emailing %s" % newsletter.pk
                mailer.run()

        if verbose:
            print "End session sending"
コード例 #11
0
    def test_update_newsletter_status(self):
        mailer = Mailer(self.newsletter, test=True)
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)

        mailer = Mailer(self.newsletter)
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.SENDING)

        for contact in self.contacts:
            ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                                contact=contact,
                                                status=ContactMailingStatus.SENT)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.SENT)
コード例 #12
0
    def test_can_send(self):
        mailer = Mailer(self.newsletter)
        self.assertTrue(mailer.can_send)

        # Checks credits
        self.server.mails_hour = 1
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.SENT)
        mailer = Mailer(self.newsletter)
        self.assertFalse(mailer.can_send)
        self.server.mails_hour = 10
        mailer = Mailer(self.newsletter)
        self.assertTrue(mailer.can_send)

        # Checks statut
        self.newsletter.status = Newsletter.DRAFT
        mailer = Mailer(self.newsletter)
        self.assertFalse(mailer.can_send)
        mailer = Mailer(self.newsletter, test=True)
        self.assertTrue(mailer.can_send)

        # Checks expedition time
        self.newsletter.status = Newsletter.WAITING
        self.newsletter.sending_date = datetime.now() + timedelta(hours=1)
        mailer = Mailer(self.newsletter)
        self.assertFalse(mailer.can_send)
        self.newsletter.sending_date = datetime.now()
        mailer = Mailer(self.newsletter)
        self.assertTrue(mailer.can_send)
コード例 #13
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        activate(settings.LANGUAGE_CODE)

        for newsletter in Newsletter.objects.exclude(
            status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    print u'Start emailing %s' % unicode(newsletter.id)
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #14
0
    def test_recipients_refused(self):
        server = SMTPServer.objects.create(name='Local SMTP',
                                           host='localhost')
        contact = Contact.objects.create(email='thisisaninvalidemail')
        self.newsletter.test_contacts.clear()
        self.newsletter.test_contacts.add(contact)
        self.newsletter.server = server
        self.newsletter.save()

        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 0)

        mailer = Mailer(self.newsletter, test=True)
        mailer.build_email_content = fake_email_content
        mailer.run()

        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 1)
コード例 #15
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        activate(settings.LANGUAGE_CODE)

        for newsletter in Newsletter.objects.exclude(
            status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    print 'Start emailing %s' % codecs.encode(newsletter.title,"utf-8")
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #16
0
    def test_recipients_refused(self):
        server = SMTPServer.objects.create(name='Local SMTP',
                                           host='localhost')
        contact = Contact.objects.create(email='thisisaninvalidemail')
        self.newsletter.test_contacts.clear()
        self.newsletter.test_contacts.add(contact)
        self.newsletter.server = server
        self.newsletter.save()

        self.assertEquals(contact.valid, True)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 0)

        mailer = Mailer(self.newsletter, test=True)
        mailer.run()

        self.assertEquals(Contact.objects.get(email='thisisaninvalidemail').valid, False)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.INVALID, newsletter=self.newsletter).count(), 1)
コード例 #17
0
    def handle(self, **options):
        from emencia.django.newsletter.mailer import Mailer
        from emencia.django.newsletter.models import Newsletter

        translation.activate('de')
        verbose = int(options['verbosity'])

        if verbose:
            print('Starting sending newsletters...')

        for newsletter in Newsletter.objects.exclude(
                status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter)
            if mailer.can_send:
                if verbose:
                    print('Start emailing %r' % newsletter.title)
                mailer.run()

        if verbose:
            print('End session sending')
コード例 #18
0
    def test_run(self):
        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.run()
        self.assertEquals(mailer.smtp.mails_sent, 4)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.SENT, newsletter=self.newsletter).count(), 4)

        mailer = Mailer(self.newsletter, test=True)
        mailer.smtp = FakeSMTP()

        mailer.run()
        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(ContactMailingStatus.objects.filter(
            status=ContactMailingStatus.SENT_TEST, newsletter=self.newsletter).count(), 2)

        mailer.smtp = None
コード例 #19
0
    def handle_noargs(self, **options):
        verbose = int(options['verbosity'])

        if verbose:
            print 'Starting sending newsletters...'

        activate(settings.LANGUAGE_CODE)

        is_test = options.get('test', False)

        for newsletter in Newsletter.objects.exclude(
                status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
            mailer = Mailer(newsletter, test=is_test, verbose=verbose)
            if mailer.can_send:
                if verbose:
                    print 'Start emailing %s' % unicode(
                        newsletter.title).encode('utf-8')
                mailer.run()

        if verbose:
            print 'End session sending'
コード例 #20
0
    def test_update_newsletter_status(self):
        mailer = Mailer(self.newsletter, test=True)
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)

        mailer = Mailer(self.newsletter)
        self.assertEquals(self.newsletter.status, Newsletter.WAITING)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.SENDING)

        for contact in self.contacts:
            ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                                contact=contact,
                                                status=ContactMailingStatus.SENT)
        mailer.update_newsletter_status()
        self.assertEquals(self.newsletter.status, Newsletter.SENT)
コード例 #21
0
    def test_expedition_list(self):
        mailer = Mailer(self.newsletter, test=True)
        self.assertEquals(len(mailer.get_expedition_list()), 2)
        self.server.mails_hour = 1
        self.assertEquals(len(mailer.get_expedition_list()), 1)

        self.server.mails_hour = 100
        mailer = Mailer(self.newsletter)
        self.assertEquals(len(mailer.get_expedition_list()), 4)
        self.server.mails_hour = 3
        self.assertEquals(len(mailer.get_expedition_list()), 3)

        self.server.mails_hour = 100
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.SENT)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.SENT)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.SENT)
        self.assertEquals(len(mailer.get_expedition_list()), 2)
        self.assertFalse(self.contacts[0] in mailer.get_expedition_list())
コード例 #22
0
    def test_expedition_list(self):
        mailer = Mailer(self.newsletter, test=True)
        self.assertEquals(len(mailer.get_expedition_list()), 2)
        self.server.mails_hour = 1
        self.assertEquals(len(mailer.get_expedition_list()), 1)

        self.server.mails_hour = 100
        mailer = Mailer(self.newsletter)
        self.assertEquals(len(mailer.get_expedition_list()), 4)
        self.server.mails_hour = 3
        self.assertEquals(len(mailer.get_expedition_list()), 3)

        self.server.mails_hour = 100
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[0],
                                            status=ContactMailingStatus.SENT)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.SENT)
        ContactMailingStatus.objects.create(newsletter=self.newsletter,
                                            contact=self.contacts[1],
                                            status=ContactMailingStatus.SENT)
        self.assertEquals(len(mailer.get_expedition_list()), 2)
        self.assertFalse(self.contacts[0] in mailer.get_expedition_list())
コード例 #23
0
    def test_run(self):
        mailer = Mailer(self.newsletter)
        mailer.smtp = FakeSMTP()
        mailer.run()
        self.assertEquals(mailer.smtp.mails_sent, 4)
        self.assertEquals(
            ContactMailingStatus.objects.filter(
                status=ContactMailingStatus.SENT,
                newsletter=self.newsletter).count(), 4)

        mailer = Mailer(self.newsletter, test=True)
        mailer.smtp = FakeSMTP()

        mailer.run()
        self.assertEquals(mailer.smtp.mails_sent, 2)
        self.assertEquals(
            ContactMailingStatus.objects.filter(
                status=ContactMailingStatus.SENT_TEST,
                newsletter=self.newsletter).count(), 2)

        mailer.smtp = None