Tests create books flow
This commit is contained in:
parent
acbebbe947
commit
58b48faff8
@ -140,6 +140,35 @@ class BookViews(TestCase):
|
|||||||
self.assertEqual(self.book.title, "New Title")
|
self.assertEqual(self.book.title, "New Title")
|
||||||
self.assertFalse(self.book.authors.exists())
|
self.assertFalse(self.book.authors.exists())
|
||||||
|
|
||||||
|
def test_create_book(self):
|
||||||
|
""" create an entirely new book and work """
|
||||||
|
view = views.ConfirmEditBook.as_view()
|
||||||
|
self.local_user.groups.add(self.group)
|
||||||
|
form = forms.EditionForm()
|
||||||
|
form.data["title"] = "New Title"
|
||||||
|
form.data["last_edited_by"] = self.local_user.id
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
request.user = self.local_user
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
view(request)
|
||||||
|
book = models.Edition.objects.get(title="New Title")
|
||||||
|
self.assertEqual(book.parent_work.title, "New Title")
|
||||||
|
|
||||||
|
def test_create_book_existing_work(self):
|
||||||
|
""" create an entirely new book and work """
|
||||||
|
view = views.ConfirmEditBook.as_view()
|
||||||
|
self.local_user.groups.add(self.group)
|
||||||
|
form = forms.EditionForm()
|
||||||
|
form.data["title"] = "New Title"
|
||||||
|
form.data["parent_work"] = self.work.id
|
||||||
|
form.data["last_edited_by"] = self.local_user.id
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
request.user = self.local_user
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
view(request)
|
||||||
|
book = models.Edition.objects.get(title="New Title")
|
||||||
|
self.assertEqual(book.parent_work, self.work)
|
||||||
|
|
||||||
def test_switch_edition(self):
|
def test_switch_edition(self):
|
||||||
""" updates user's relationships to a book """
|
""" updates user's relationships to a book """
|
||||||
work = models.Work.objects.create(title="test work")
|
work = models.Work.objects.create(title="test work")
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
""" the good stuff! the books! """
|
""" the good stuff! the books! """
|
||||||
from django.core.paginator import Paginator
|
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.contrib.postgres.search import SearchRank, SearchVector
|
from django.contrib.postgres.search import SearchRank, SearchVector
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
@ -207,7 +206,7 @@ class ConfirmEditBook(View):
|
|||||||
if work_match:
|
if work_match:
|
||||||
work = get_object_or_404(models.Work, id=work_match)
|
work = get_object_or_404(models.Work, id=work_match)
|
||||||
else:
|
else:
|
||||||
work = models.Work.objects.create(title=form.cleaned_data.title)
|
work = models.Work.objects.create(title=form.cleaned_data["title"])
|
||||||
work.authors.set(book.authors.all())
|
work.authors.set(book.authors.all())
|
||||||
book.parent_work = work
|
book.parent_work = work
|
||||||
book.save()
|
book.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user