2016-08-16 01:00:52 +02:00
|
|
|
import os
|
|
|
|
|
|
2013-07-25 23:45:39 -07:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
2021-02-08 23:39:19 -05:00
|
|
|
from django_mailbox2.models import Mailbox
|
2013-07-25 23:45:39 -07:00
|
|
|
|
|
|
|
|
|
2021-02-03 23:05:48 -05:00
|
|
|
__all__ = ["TestMailbox"]
|
2013-07-25 23:45:39 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestMailbox(TestCase):
|
|
|
|
|
def test_protocol_info(self):
|
|
|
|
|
mailbox = Mailbox()
|
2021-02-03 23:05:48 -05:00
|
|
|
mailbox.uri = "alpha://test.com"
|
2013-07-25 23:45:39 -07:00
|
|
|
|
2021-02-03 23:05:48 -05:00
|
|
|
expected_protocol = "alpha"
|
2013-07-25 23:45:39 -07:00
|
|
|
actual_protocol = mailbox._protocol_info.scheme
|
|
|
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
expected_protocol,
|
|
|
|
|
actual_protocol,
|
|
|
|
|
)
|
2016-08-16 01:00:52 +02:00
|
|
|
|
|
|
|
|
def test_last_polling_field_exists(self):
|
|
|
|
|
mailbox = Mailbox()
|
2021-02-03 23:05:48 -05:00
|
|
|
self.assertTrue(hasattr(mailbox, "last_polling"))
|
2016-08-16 01:00:52 +02:00
|
|
|
|
|
|
|
|
def test_get_new_mail_update_last_polling(self):
|
2021-02-03 23:05:48 -05:00
|
|
|
mailbox = Mailbox.objects.create(
|
|
|
|
|
uri="mbox://"
|
|
|
|
|
+ os.path.join(
|
2016-08-16 01:00:52 +02:00
|
|
|
os.path.dirname(__file__),
|
2021-02-03 23:05:48 -05:00
|
|
|
"messages",
|
|
|
|
|
"generic_message.eml",
|
|
|
|
|
)
|
|
|
|
|
)
|
2016-08-16 01:00:52 +02:00
|
|
|
self.assertEqual(mailbox.last_polling, None)
|
2018-03-09 19:09:45 +01:00
|
|
|
list(mailbox.get_new_mail())
|
2016-08-16 01:00:52 +02:00
|
|
|
self.assertNotEqual(mailbox.last_polling, None)
|
2020-07-26 14:21:21 +08:00
|
|
|
|
|
|
|
|
def test_queryset_get_new_mail(self):
|
2021-02-03 23:05:48 -05:00
|
|
|
mailbox = Mailbox.objects.create(
|
|
|
|
|
uri="mbox://"
|
|
|
|
|
+ os.path.join(
|
2020-07-26 14:21:21 +08:00
|
|
|
os.path.dirname(__file__),
|
2021-02-03 23:05:48 -05:00
|
|
|
"messages",
|
|
|
|
|
"generic_message.eml",
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-07-26 14:21:21 +08:00
|
|
|
Mailbox.objects.filter(pk=mailbox.pk).get_new_mail()
|
|
|
|
|
mailbox.refresh_from_db()
|
|
|
|
|
self.assertNotEqual(mailbox.last_polling, None)
|