diff --git a/boxes/tests.py b/boxes/tests.py index 5a94c60e..cc106e37 100644 --- a/boxes/tests.py +++ b/boxes/tests.py @@ -254,6 +254,16 @@ def test_no_owner_key(self): response = self.client.get(reverse("boxes_show", args=(box.uuid,))) self.assertEqual(response.template_name, 'boxes/closed.html') + def test_box_not_found(self): + user = create_and_login_user(self.client) + user.public_key = VALID_KEY + user.fingerprint = VALID_KEY_FINGERPRINT + user.save() + box = create_open_box(user) + box.delete() + response = self.client.get(reverse("boxes_show", args=(box.uuid,))) + self.assertEqual(response.status_code, 404) + class BoxCreateViewTests(TestCase): diff --git a/boxes/views.py b/boxes/views.py index 7750cc26..fc335cd1 100644 --- a/boxes/views.py +++ b/boxes/views.py @@ -1,5 +1,5 @@ from django.views.generic import ListView, CreateView, DeleteView, UpdateView -from django.http import HttpResponseRedirect +from django.http import Http404, HttpResponseRedirect from django.urls import reverse_lazy from django.core.exceptions import ObjectDoesNotExist from django.contrib import messages @@ -139,8 +139,8 @@ def get_object(self, queryset=None): try: q = queryset.select_related('owner').prefetch_related('recipients') return q.get(uuid=self.kwargs.get("box_uuid")) - except ValueError: - raise ObjectDoesNotExist(_('Not Found. Double check your URL')) + except (ValueError, Box.DoesNotExist): + raise Http404(_('Not Found. Double check your URL')) def dispatch(self, request, *args, **kwargs): self.object = self.get_object() diff --git a/humans/migrations/0013_auto_20201204_1807.py b/humans/migrations/0013_auto_20201204_1807.py new file mode 100644 index 00000000..81619b25 --- /dev/null +++ b/humans/migrations/0013_auto_20201204_1807.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.13 on 2020-12-04 18:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('humans', '0012_remove_user_server_signed'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='last_name', + field=models.CharField(blank=True, max_length=150, verbose_name='last name'), + ), + ]