Editing task should not change its completed status
This commit is contained in:
parent
2d40ef471e
commit
4f9f379543
5 changed files with 47 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
<input type="hidden" name="priority"
|
||||
value="{% if form.priority.value %}{{ form.priority.value }}{% else %}999{% endif %}" id="id_priority">
|
||||
<input type="hidden" name="task_list" value="{{ form.task_list.value }}" id="id_task_list">
|
||||
<input type="hidden" name="completed" class="form-check-input" type="checkbox" checked="{%if task.completed%}checked{% endif %}" id="id_completed">
|
||||
|
||||
<p>
|
||||
<input type="submit" name="add_edit_task" value="Submit" class="btn btn-primary">
|
||||
|
|
|
@ -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,9 +169,9 @@ 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",
|
||||
|
@ -188,6 +190,38 @@ def test_created_by_unchanged(todo_setup, client):
|
|||
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):
|
||||
user = get_user_model().objects.get(username="u2")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue