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
|
## 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.8** Fix bug when setting default values for unspecified settings
|
||||||
|
|
||||||
**2.4.7** Support custom user model in external_add
|
**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.
|
A multi-user, multi-group task management and assignment system for Django.
|
||||||
"""
|
"""
|
||||||
__version__ = "2.4.8"
|
__version__ = "2.4.9"
|
||||||
|
|
||||||
__author__ = "Scot Hacker"
|
__author__ = "Scot Hacker"
|
||||||
__email__ = "shacker@birdhouse.org"
|
__email__ = "shacker@birdhouse.org"
|
||||||
|
|
|
@ -49,6 +49,8 @@ class AddEditTaskForm(ModelForm):
|
||||||
|
|
||||||
note = forms.CharField(widget=forms.Textarea(), required=False)
|
note = forms.CharField(widget=forms.Textarea(), required=False)
|
||||||
|
|
||||||
|
completed = forms.BooleanField(required=False)
|
||||||
|
|
||||||
def clean_created_by(self):
|
def clean_created_by(self):
|
||||||
"""Keep the existing created_by regardless of anything coming from the submitted form.
|
"""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."""
|
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"
|
<input type="hidden" name="priority"
|
||||||
value="{% if form.priority.value %}{{ form.priority.value }}{% else %}999{% endif %}" id="id_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="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>
|
<p>
|
||||||
<input type="submit" name="add_edit_task" value="Submit" class="btn btn-primary">
|
<input type="submit" name="add_edit_task" value="Submit" class="btn btn-primary">
|
||||||
|
|
|
@ -135,7 +135,7 @@ def test_no_javascript_in_task_note(todo_setup, client):
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_created_by_unchanged(todo_setup, client):
|
def test_created_by_unchanged(todo_setup, client):
|
||||||
|
|
||||||
task_list = TaskList.objects.first()
|
task_list = TaskList.objects.first()
|
||||||
u2 = get_user_model().objects.get(username="u2")
|
u2 = get_user_model().objects.get(username="u2")
|
||||||
title = "Some Unique String with unique chars: ab78539e"
|
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")
|
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)
|
response = client.post(url_add_task, data)
|
||||||
assert response.status_code == 302
|
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})
|
url_edit_task = reverse("todo:task_detail", kwargs={"task_id": task.id})
|
||||||
|
|
||||||
dataTwo = {
|
dataTwo = {
|
||||||
"task_list": task.task_list.id,
|
"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,
|
"priority": 10,
|
||||||
"title": task.title,
|
"title": task.title,
|
||||||
"note": "the note was changed",
|
"note": "the note was changed",
|
||||||
"add_edit_task": "Submit",
|
"add_edit_task": "Submit",
|
||||||
}
|
}
|
||||||
|
|
||||||
response = client.post(url_edit_task, dataTwo)
|
response = client.post(url_edit_task, dataTwo)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
|
|
||||||
task.refresh_from_db()
|
task.refresh_from_db()
|
||||||
|
|
||||||
# Proof that the task was saved:
|
# Proof that the task was saved:
|
||||||
assert task.note == "the note was changed"
|
assert task.note == "the note was changed"
|
||||||
|
|
||||||
# client was unable to modify created_by:
|
# client was unable to modify created_by:
|
||||||
assert task.created_by == u2
|
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
|
@pytest.mark.django_db
|
||||||
def test_no_javascript_in_comments(todo_setup, client):
|
def test_no_javascript_in_comments(todo_setup, client):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue