Skip to content

Commit

Permalink
Merge pull request #308 from whitesmith/pdcribeiro-patch
Browse files Browse the repository at this point in the history
Handle box not found
  • Loading branch information
dethos authored Dec 9, 2020
2 parents 0f6ec2f + 0ec03b5 commit 7cea93e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions boxes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
6 changes: 3 additions & 3 deletions boxes/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions humans/migrations/0013_auto_20201204_1807.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]

0 comments on commit 7cea93e

Please sign in to comment.