diff --git a/README.md b/README.md index 10b6536..feb8f34 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,8 @@ django-todo uses pytest exclusively for testing. The best way to run the suite i ## Version History +**2.4.9** Fixed: Editing a task should not change its completed/incomplete status + **2.4.8** Fix bug when setting default values for unspecified settings **2.4.7** Support custom user model in external_add diff --git a/todo/__init__.py b/todo/__init__.py index 9a57202..8a6ba39 100644 --- a/todo/__init__.py +++ b/todo/__init__.py @@ -1,7 +1,7 @@ """ A multi-user, multi-group task management and assignment system for Django. """ -__version__ = "2.4.8" +__version__ = "2.4.9" __author__ = "Scot Hacker" __email__ = "shacker@birdhouse.org" diff --git a/todo/forms.py b/todo/forms.py index 072a201..d17c724 100644 --- a/todo/forms.py +++ b/todo/forms.py @@ -49,6 +49,8 @@ class AddEditTaskForm(ModelForm): note = forms.CharField(widget=forms.Textarea(), required=False) + completed = forms.BooleanField(required=False) + def clean_created_by(self): """Keep the existing created_by regardless of anything coming from the submitted form. If creating a new task, then created_by will be None, but we set it before saving.""" diff --git a/todo/templates/todo/include/task_edit.html b/todo/templates/todo/include/task_edit.html index 1c8242f..f1070ac 100644 --- a/todo/templates/todo/include/task_edit.html +++ b/todo/templates/todo/include/task_edit.html @@ -45,6 +45,7 @@ +

diff --git a/todo/tests/test_views.py b/todo/tests/test_views.py index 007bab6..1915140 100644 --- a/todo/tests/test_views.py +++ b/todo/tests/test_views.py @@ -135,7 +135,7 @@ def test_no_javascript_in_task_note(todo_setup, client): @pytest.mark.django_db def test_created_by_unchanged(todo_setup, client): - + task_list = TaskList.objects.first() u2 = get_user_model().objects.get(username="u2") title = "Some Unique String with unique chars: ab78539e" @@ -150,7 +150,9 @@ def test_created_by_unchanged(todo_setup, client): } client.login(username="u2", password="password") - url_add_task = reverse("todo:list_detail", kwargs={"list_id": task_list.id, "list_slug": task_list.slug}) + url_add_task = reverse( + "todo:list_detail", kwargs={"list_id": task_list.id, "list_slug": task_list.slug} + ) response = client.post(url_add_task, data) assert response.status_code == 302 @@ -167,26 +169,58 @@ def test_created_by_unchanged(todo_setup, client): url_edit_task = reverse("todo:task_detail", kwargs={"task_id": task.id}) - dataTwo = { + dataTwo = { "task_list": task.task_list.id, - "created_by": extra_g2_user.id, # this submission is attempting to change created_by + "created_by": extra_g2_user.id, # this submission is attempting to change created_by "priority": 10, "title": task.title, "note": "the note was changed", "add_edit_task": "Submit", } - + response = client.post(url_edit_task, dataTwo) assert response.status_code == 302 task.refresh_from_db() - + # Proof that the task was saved: assert task.note == "the note was changed" # client was unable to modify created_by: assert task.created_by == u2 - + + +@pytest.mark.django_db +@pytest.mark.parametrize("test_input, expected", [(True, True), (False, False)]) +def test_completed_unchanged(test_input, expected, todo_setup, client): + """Tasks are marked completed/uncompleted by buttons, + not via checkbox on the task edit form. Editing a task should + not change its completed status. Test with both completed and incomplete Tasks.""" + + task = Task.objects.get(title="Task 1", created_by__username="u1") + task.completed = test_input + task.save() + assert task.completed == expected + + url_edit_task = reverse("todo:task_detail", kwargs={"task_id": task.id}) + + data = { + "task_list": task.task_list.id, + "title": "Something", + "note": "the note was changed", + "add_edit_task": "Submit", + "completed": task.completed, + } + + client.login(username="u1", password="password") + response = client.post(url_edit_task, data) + assert response.status_code == 302 + + # Prove the task is still marked complete/incomplete + # (despite the default default state for completed being False) + task.refresh_from_db() + assert task.completed == expected + @pytest.mark.django_db def test_no_javascript_in_comments(todo_setup, client):