diff --git a/bookwyrm/tests/views/test_book.py b/bookwyrm/tests/views/test_book.py index 0ba09e3b..6a28ba9d 100644 --- a/bookwyrm/tests/views/test_book.py +++ b/bookwyrm/tests/views/test_book.py @@ -114,11 +114,29 @@ class BookViews(TestCase): view(request, self.book.id) - # the changes haven't been saved yet self.book.refresh_from_db() self.assertEqual(self.book.title, 'New Title') self.assertEqual(self.book.authors.first().name, 'Sappho') + def test_edit_book_remove_author(self): + ''' remove an author from a book ''' + author = models.Author.objects.create(name='Sappho') + self.book.authors.add(author) + form = forms.EditionForm(instance=self.book) + view = views.EditBook.as_view() + self.local_user.groups.add(self.group) + form = forms.EditionForm(instance=self.book) + form.data['title'] = 'New Title' + form.data['last_edited_by'] = self.local_user.id + form.data['remove_authors'] = [author.id] + request = self.factory.post('', form.data) + request.user = self.local_user + + view(request, self.book.id) + self.book.refresh_from_db() + self.assertEqual(self.book.title, 'New Title') + self.assertFalse(self.book.authors.exists()) + def test_switch_edition(self): ''' updates user's relationships to a book ''' diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index cc05a79c..07a1d437 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -206,6 +206,10 @@ class ConfirmEditBook(View): name=request.POST.get('add_author')) book.authors.add(author) + remove_authors = request.POST.getlist('remove_authors') + for author_id in remove_authors: + book.authors.remove(author_id) + return redirect('/book/%s' % book.id)