diff --git a/src/apps/dashboard/tests/test_views.py b/src/apps/dashboard/tests/test_views.py index d9e2bae..244ab81 100644 --- a/src/apps/dashboard/tests/test_views.py +++ b/src/apps/dashboard/tests/test_views.py @@ -201,3 +201,11 @@ class ShareListTest(TestCase): data={"recipient": "alice@example.com"}, ) 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}/") diff --git a/src/apps/dashboard/views.py b/src/apps/dashboard/views.py index 2b46cb1..fc8359c 100644 --- a/src/apps/dashboard/views.py +++ b/src/apps/dashboard/views.py @@ -40,6 +40,9 @@ def my_lists(request, user_id): def share_list(request, list_id): our_list = List.objects.get(id=list_id) - recipient = User.objects.get(email=request.POST["recipient"]) - our_list.shared_with.add(recipient) + try: + recipient = User.objects.get(email=request.POST["recipient"]) + our_list.shared_with.add(recipient) + except User.DoesNotExist: + pass return redirect(our_list)