added to apps.dashboard.views, share_list() FBV, a try/except catch that accounts for nonexistent users; .test.test_views ensures functionality
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@@ -201,3 +201,11 @@ class ShareListTest(TestCase):
|
|||||||
data={"recipient": "alice@example.com"},
|
data={"recipient": "alice@example.com"},
|
||||||
)
|
)
|
||||||
self.assertIn(alice, our_list.shared_with.all())
|
self.assertIn(alice, our_list.shared_with.all())
|
||||||
|
|
||||||
|
def test_post_with_nonexistent_email_redirects_to_list(self):
|
||||||
|
our_list = List.objects.create()
|
||||||
|
response = self.client.post(
|
||||||
|
f"/apps/dashboard/{our_list.id}/share_list",
|
||||||
|
data={"recipient": "nobody@example.com"},
|
||||||
|
)
|
||||||
|
self.assertRedirects(response, f"/apps/dashboard/{our_list.id}/")
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ def my_lists(request, user_id):
|
|||||||
|
|
||||||
def share_list(request, list_id):
|
def share_list(request, list_id):
|
||||||
our_list = List.objects.get(id=list_id)
|
our_list = List.objects.get(id=list_id)
|
||||||
|
try:
|
||||||
recipient = User.objects.get(email=request.POST["recipient"])
|
recipient = User.objects.get(email=request.POST["recipient"])
|
||||||
our_list.shared_with.add(recipient)
|
our_list.shared_with.add(recipient)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
return redirect(our_list)
|
return redirect(our_list)
|
||||||
|
|||||||
Reference in New Issue
Block a user