From 05716c3578fafb21d1c9f6537ebe88a7a65d4ec7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 14 Jul 2022 11:38:53 -0700 Subject: [PATCH] Adds unit test for creating shelves for another user --- .../tests/views/shelf/test_shelf_actions.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bookwyrm/tests/views/shelf/test_shelf_actions.py b/bookwyrm/tests/views/shelf/test_shelf_actions.py index 93ff0a38e..2f2c208c7 100644 --- a/bookwyrm/tests/views/shelf/test_shelf_actions.py +++ b/bookwyrm/tests/views/shelf/test_shelf_actions.py @@ -32,6 +32,14 @@ class ShelfActionViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) + self.another_user = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + ) self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Example Edition", @@ -165,6 +173,20 @@ class ShelfActionViews(TestCase): self.assertEqual(shelf.description, "desc") self.assertEqual(shelf.user, self.local_user) + def test_create_shelf_wrong_user(self, *_): + """a brand new custom shelf""" + form = forms.ShelfForm() + form.data["user"] = self.another_user.id + form.data["name"] = "new shelf name" + form.data["description"] = "desc" + form.data["privacy"] = "unlisted" + request = self.factory.post("", form.data) + request.user = self.local_user + + views.create_shelf(request) + + self.assertIsNone(models.Shelf.objects.filter(name="new shelf name")) + def test_delete_shelf(self, *_): """delete a brand new custom shelf""" request = self.factory.post("")