This commit is contained in:
Matt Lehrer 2023-11-30 11:12:42 +01:00
parent f4da9fbf34
commit 31a78a5c9e
2 changed files with 21 additions and 9 deletions

View file

@ -139,14 +139,17 @@ class BookViews(TestCase):
work = models.Work.objects.create(title="test work")
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
edition2 = models.Edition.objects.create(title="second ed", parent_work=work)
models.ReviewRating.objects.create(
book=edition1,
user=self.local_user,
rating=3,
)
self.assertIsInstance(models.ReviewRating.objects.get(user=self.local_user, book=edition1), models.ReviewRating)
self.assertIsInstance(
models.ReviewRating.objects.get(user=self.local_user, book=edition1),
models.ReviewRating,
)
with self.assertRaises(models.ReviewRating.DoesNotExist):
models.ReviewRating.objects.get(user=self.local_user, book=edition2)
@ -154,7 +157,10 @@ class BookViews(TestCase):
request.user = self.local_user
views.switch_edition(request)
self.assertIsInstance(models.ReviewRating.objects.get(user=self.local_user, book=edition2), models.ReviewRating)
self.assertIsInstance(
models.ReviewRating.objects.get(user=self.local_user, book=edition2),
models.ReviewRating,
)
with self.assertRaises(models.ReviewRating.DoesNotExist):
models.ReviewRating.objects.get(user=self.local_user, book=edition1)
@ -167,16 +173,19 @@ class BookViews(TestCase):
work = models.Work.objects.create(title="test work")
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
edition2 = models.Edition.objects.create(title="second ed", parent_work=work)
models.Review.objects.create(
book=edition1,
user=self.local_user,
name="blah",
rating=3,
content="not bad"
content="not bad",
)
self.assertIsInstance(models.Review.objects.get(user=self.local_user, book=edition1), models.Review)
self.assertIsInstance(
models.Review.objects.get(user=self.local_user, book=edition1),
models.Review,
)
with self.assertRaises(models.Review.DoesNotExist):
models.Review.objects.get(user=self.local_user, book=edition2)
@ -184,6 +193,9 @@ class BookViews(TestCase):
request.user = self.local_user
views.switch_edition(request)
self.assertIsInstance(models.Review.objects.get(user=self.local_user, book=edition2), models.Review)
self.assertIsInstance(
models.Review.objects.get(user=self.local_user, book=edition2),
models.Review,
)
with self.assertRaises(models.Review.DoesNotExist):
models.Review.objects.get(user=self.local_user, book=edition1)

View file

@ -107,9 +107,9 @@ def switch_edition(request):
book__parent_work=new_edition.parent_work, user=request.user
)
for review in reviews.all():
# because ratings are a subclass of reviews,
# because ratings are a subclass of reviews,
# this will pick up both ratings and reviews
review.book = new_edition
review.save()
review.save()
return redirect(f"/book/{new_edition.id}")