def test_not_supported_alternatives(self): email_message = EmailMultiAlternatives("foo", "bar", "*****@*****.**", ["*****@*****.**"]) email_message.attach_alternative("some", "text/json") generator = QueuedEmailMessage.queue([email_message]) self.assertRaises(NotImplementedError, list, generator)
def run(): # pragma: no cover assert 'DJANGO_SETTINGS_MODULE' in os.environ, "DJANGO_SETTINGS_MODULE is missing from environment, you must set if before running this worker" logging.info("os.environ['DJANGO_SETTINGS_MODULE']: %s" % os.environ['DJANGO_SETTINGS_MODULE']) cwd = os.getcwd() if cwd not in sys.path: # pragma: no cover sys.path.append(cwd) # Show a debugging info on console logging.debug("__file__ = %s", __file__) logging.debug("sys.version = %s", sys.version) logging.debug("os.getpid() = %s", os.getpid()) logging.debug("os.getcwd() = %s", cwd) logging.debug("os.curdir = %s", os.curdir) logging.debug("sys.path:\n\t%s", "\n\t".join(sys.path)) logging.debug("PYTHONPATH:\n\t%s", "\n\t".join(os.environ.get('PYTHONPATH', "").split(';'))) logging.debug("sys.modules.keys() = %s", repr(sys.modules.keys())) logging.debug("sys.modules.has_key('website') = %s", 'website' in sys.modules) from django.conf import settings import django django.setup() logging.debug("settings.__dir__: %s", settings.__dir__()) logging.debug("settings.DEBUG: %s", settings.DEBUG) from django_email_queue.models import QueuedEmailMessage while True: QueuedEmailMessage.send_queued(10) seconds = settings.EMAIL_QUEUE_SLEEP_TIME logging.debug("Will sleep for %s seconds", seconds) sleep(seconds)
def test_queue(self): email_message = EmailMultiAlternatives( "foo", "bar", "*****@*****.**", ["*****@*****.**", "*****@*****.**"], ["*****@*****.**", "*****@*****.**"], cc=["*****@*****.**", "*****@*****.**"], reply_to=["*****@*****.**", "*****@*****.**"]) email_message.attach_alternative("baz", "text/html") instance = list(QueuedEmailMessage.queue([email_message]))[0] self.assertIsNotNone(instance.pk) self.assertIsNotNone(instance.created) self.assertEqual(QueuedEmailMessageStatus.created, instance.status) self.assertEqual("foo", instance.subject) self.assertEqual("bar", instance.body_text) self.assertEqual("baz", instance.body_html) self.assertEqual("*****@*****.**", instance.from_email) self.assertEqual("[email protected], [email protected]", instance.to) self.assertEqual("[email protected], [email protected]", instance.cc) self.assertEqual("[email protected], [email protected]", instance.bcc) self.assertEqual("[email protected], [email protected]", instance.reply_to)
def send_messages(self, email_messages): messages = list(QueuedEmailMessage.queue(email_messages)) from django.conf import settings if settings.EMAIL_QUEUE_EAGER: for item in messages: item.send()
def test_send_queued(self, send): QueuedEmailMessageFactory.create_batch( 11, status=QueuedEmailMessageStatus.posted) QueuedEmailMessageFactory.create_batch(5) QueuedEmailMessage.send_queued() self.assertEqual(5, send.call_count)
def test_send_queued_limit(self, send): QueuedEmailMessageFactory.create_batch(5) QueuedEmailMessage.send_queued(3) self.assertEqual(3, send.call_count)
def test_str2(self): o = QueuedEmailMessage(subject="ążśźćń󳥯ŚŹĘĆŃÓŁ", to="b", pk=123) self.assertEqual(u"QueuedEmailMessage:123:ążśźćń󳥯ŚŹĘĆŃÓŁ:b", six.text_type(o))
def test_no_recipients(self): email_message = EmailMultiAlternatives("foo", "bar", "*****@*****.**") email_message.attach_alternative("some", "text/json") generator = QueuedEmailMessage.queue([email_message]) self.assertRaises(AssertionError, list, generator)