Refactor Done and Delete actions in list and detail views
This commit is contained in:
parent
4fe3829b98
commit
9098e3f0d4
7 changed files with 108 additions and 141 deletions
|
@ -3,7 +3,7 @@ import pytest
|
|||
from django.core import mail
|
||||
|
||||
from todo.models import Task, Comment
|
||||
from todo.utils import toggle_done, toggle_deleted, send_notify_mail, send_email_to_thread_participants
|
||||
from todo.utils import send_notify_mail, send_email_to_thread_participants
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
@ -12,42 +12,6 @@ def email_backend_setup(settings):
|
|||
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
|
||||
|
||||
def test_toggle_done(todo_setup):
|
||||
"""Utility function takes an array of POSTed IDs and changes their `completed` status.
|
||||
"""
|
||||
u1_tasks = Task.objects.filter(created_by__username="u1")
|
||||
completed = u1_tasks.filter(completed=True)
|
||||
incomplete = u1_tasks.filter(completed=False)
|
||||
|
||||
# Expected counts in fixture data
|
||||
assert u1_tasks.count() == 3
|
||||
assert incomplete.count() == 2
|
||||
assert completed.count() == 1
|
||||
|
||||
# Mark incomplete tasks completed and check again
|
||||
toggle_done([t.id for t in incomplete])
|
||||
now_completed = u1_tasks.filter(created_by__username="u1", completed=True)
|
||||
assert now_completed.count() == 3
|
||||
|
||||
# Mark all incomplete and check again
|
||||
toggle_done([t.id for t in now_completed])
|
||||
now_incomplete = u1_tasks.filter(created_by__username="u1", completed=False)
|
||||
assert now_incomplete.count() == 3
|
||||
|
||||
|
||||
def test_toggle_deleted(todo_setup):
|
||||
"""Unlike toggle_done, delete means delete, so it's not really a toggle.
|
||||
"""
|
||||
u1_tasks = Task.objects.filter(created_by__username="u1")
|
||||
assert u1_tasks.count() == 3
|
||||
t1 = u1_tasks.first()
|
||||
t2 = u1_tasks.last()
|
||||
|
||||
toggle_deleted([t1.id, t2.id, ])
|
||||
u1_tasks = Task.objects.filter(created_by__username="u1")
|
||||
assert u1_tasks.count() == 1
|
||||
|
||||
|
||||
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.
|
||||
TODO: Future tests could check for email contents.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue