Test mail tracking
This commit is contained in:
parent
c9ec890658
commit
db062447d1
4 changed files with 102 additions and 6 deletions
|
@ -29,6 +29,8 @@ INSTALLED_APPS = (
|
||||||
"django.contrib.sites",
|
"django.contrib.sites",
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"todo",
|
"todo",
|
||||||
|
"dal",
|
||||||
|
"dal_select2",
|
||||||
)
|
)
|
||||||
|
|
||||||
ROOT_URLCONF = "base_urls"
|
ROOT_URLCONF = "base_urls"
|
||||||
|
@ -61,3 +63,30 @@ TEMPLATES = [
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': False,
|
||||||
|
'handlers': {
|
||||||
|
'console': {
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
'django': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
'django.request': {
|
||||||
|
'handlers': ['console'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -28,3 +28,9 @@ def todo_setup(django_user_model):
|
||||||
Task.objects.create(created_by=u2, title="Task 1", task_list=tlist2, priority=1)
|
Task.objects.create(created_by=u2, title="Task 1", task_list=tlist2, priority=1)
|
||||||
Task.objects.create(created_by=u2, title="Task 2", task_list=tlist2, priority=2, completed=True)
|
Task.objects.create(created_by=u2, title="Task 2", task_list=tlist2, priority=2, completed=True)
|
||||||
Task.objects.create(created_by=u2, title="Task 3", task_list=tlist2, priority=3)
|
Task.objects.create(created_by=u2, title="Task 3", task_list=tlist2, priority=3)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
# Set up an in-memory mail server to receive test emails
|
||||||
|
def email_backend_setup(settings):
|
||||||
|
settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
||||||
|
|
67
todo/tests/test_tracker.py
Normal file
67
todo/tests/test_tracker.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from django.core import mail
|
||||||
|
|
||||||
|
from todo.models import Task, Comment
|
||||||
|
from todo.mail.consumers import tracker_consumer
|
||||||
|
from email.message import EmailMessage
|
||||||
|
|
||||||
|
|
||||||
|
def consumer(*args, title_format="[TEST] {subject}", **kwargs):
|
||||||
|
return tracker_consumer(
|
||||||
|
group="Workgroup One",
|
||||||
|
task_list_slug="zip",
|
||||||
|
priority=1,
|
||||||
|
task_title_format=title_format,
|
||||||
|
)(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def make_message(subject, content):
|
||||||
|
msg = EmailMessage()
|
||||||
|
msg.set_content(content)
|
||||||
|
msg['Subject'] = subject
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def test_tracker_task_creation(todo_setup, django_user_model):
|
||||||
|
msg = make_message("test1 subject", "test1 content")
|
||||||
|
msg['From'] = 'test1@example.com'
|
||||||
|
msg['Message-ID'] = '<a@example.com>'
|
||||||
|
|
||||||
|
# test task creation
|
||||||
|
task_count = Task.objects.count()
|
||||||
|
consumer([msg])
|
||||||
|
|
||||||
|
assert task_count + 1 == Task.objects.count(), "task wasn't created"
|
||||||
|
task = Task.objects.filter(title="[TEST] test1 subject").first()
|
||||||
|
assert task is not None, "task was created with the wrong name"
|
||||||
|
|
||||||
|
# test thread answers
|
||||||
|
msg = make_message("test2 subject", "test2 content")
|
||||||
|
msg['From'] = 'test1@example.com'
|
||||||
|
msg['Message-ID'] = '<b@example.com>'
|
||||||
|
msg['References'] = '<nope@example.com> <a@example.com>'
|
||||||
|
|
||||||
|
task_count = Task.objects.count()
|
||||||
|
consumer([msg])
|
||||||
|
assert task_count == Task.objects.count(), "comment created another task"
|
||||||
|
Comment.objects.get(
|
||||||
|
task=task,
|
||||||
|
body__contains="test2 content",
|
||||||
|
email_message_id='<b@example.com>'
|
||||||
|
)
|
||||||
|
|
||||||
|
# test notification answer
|
||||||
|
msg = make_message("test3 subject", "test3 content")
|
||||||
|
msg['From'] = 'test1@example.com'
|
||||||
|
msg['Message-ID'] = '<c@example.com>'
|
||||||
|
msg['References'] = '<thread-{}@django-todo> <unknown@example.com>'.format(task.pk)
|
||||||
|
|
||||||
|
task_count = Task.objects.count()
|
||||||
|
consumer([msg])
|
||||||
|
assert task_count == Task.objects.count(), "comment created another task"
|
||||||
|
Comment.objects.get(
|
||||||
|
task=task,
|
||||||
|
body__contains="test3 content",
|
||||||
|
email_message_id='<c@example.com>'
|
||||||
|
)
|
|
@ -6,12 +6,6 @@ from todo.models import Task, Comment
|
||||||
from todo.utils import send_notify_mail, send_email_to_thread_participants
|
from todo.utils import send_notify_mail, send_email_to_thread_participants
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
# Set up an in-memory mail server to receive test emails
|
|
||||||
def email_backend_setup(settings):
|
|
||||||
settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
|
|
||||||
|
|
||||||
|
|
||||||
def test_send_notify_mail_not_me(todo_setup, django_user_model, email_backend_setup):
|
def test_send_notify_mail_not_me(todo_setup, django_user_model, email_backend_setup):
|
||||||
"""Assign a task to someone else, mail should be sent.
|
"""Assign a task to someone else, mail should be sent.
|
||||||
TODO: Future tests could check for email contents.
|
TODO: Future tests could check for email contents.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue