Adds unit test for creating shelves for another user

This commit is contained in:
Mouse Reeve 2022-07-14 11:38:53 -07:00
parent 2def5ff2bc
commit 05716c3578

View file

@ -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("")