Skip to content

Commit

Permalink
Merge pull request #3401 from dato/comment_progress_keep_start_date
Browse files Browse the repository at this point in the history
Fix reading progress `start_date` bug
  • Loading branch information
mouse-reeve authored Aug 9, 2024
2 parents 66dd39e + 041f2fc commit 95c2798
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
33 changes: 33 additions & 0 deletions bookwyrm/tests/views/test_status.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
""" test for app action functionality """
import json
from unittest.mock import patch
import dateutil
from django.core.exceptions import PermissionDenied
from django.test import TestCase, TransactionTestCase
from django.test.client import RequestFactory
from django.utils import timezone

from bookwyrm import forms, models, views
from bookwyrm.views.status import find_mentions, find_or_create_hashtags
Expand Down Expand Up @@ -167,6 +169,37 @@ def test_create_status_rating(self, *_):
self.assertEqual(status.rating, 4.0)
self.assertIsNone(status.edited_date)

def test_create_status_progress(self, *_):
"""create a status that updates a readthrough"""
start_date = timezone.make_aware(dateutil.parser.parse("2024-07-27"))
readthrough = models.ReadThrough.objects.create(
book=self.book, user=self.local_user, start_date=start_date
)

self.assertEqual(start_date, readthrough.start_date)
self.assertIsNone(readthrough.progress)

view = views.CreateStatus.as_view()
form = forms.CommentForm(
{
"progress": 1,
"progress_mode": "PG",
"content": "I started the book",
"id": readthrough.id,
"book": self.book.id,
"user": self.local_user.id,
"privacy": "public",
}
)
request = self.factory.post("", form.data)
request.user = self.local_user

view(request, "comment")
readthrough.refresh_from_db()

self.assertEqual(1, readthrough.progress)
self.assertEqual(start_date, readthrough.start_date) # not overwritten

def test_create_status_wrong_user(self, *_):
"""You can't compose statuses for someone else"""
view = views.CreateStatus.as_view()
Expand Down
11 changes: 5 additions & 6 deletions bookwyrm/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,11 @@ def edit_readthrough(request):
# TODO: remove this, it duplicates the code in the ReadThrough view
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))

readthrough.start_date = load_date_in_user_tz_as_utc(
request.POST.get("start_date"), request.user
)
readthrough.finish_date = load_date_in_user_tz_as_utc(
request.POST.get("finish_date"), request.user
)
if start_date := request.POST.get("start_date"):
readthrough.start_date = load_date_in_user_tz_as_utc(start_date, request.user)

if finish_date := request.POST.get("finish_date"):
readthrough.finish_date = load_date_in_user_tz_as_utc(finish_date, request.user)

progress = request.POST.get("progress")
try:
Expand Down

0 comments on commit 95c2798

Please sign in to comment.