Initial layout of /edit/[short]

- a new URL (and test)
- a new view (and test)
parent ef18dac9
Pipeline #1166 failed with stage
in 1 minute and 4 seconds
......@@ -104,6 +104,18 @@ class ViewTest(TestCase):
response = self.client.get('/view/test')
self.assertEqual(response.status_code, 200)
class EditTest(TestCase):
"""
Test cases for the edit view
"""
def test_django_test(self):
"""
Default test case, does not actually test anything
"""
self.assertEqual("Hello World!", "Hello World!")
class DeleteTest(TestCase):
"""
Test cases for the delete view
......
......@@ -193,6 +193,31 @@ def view(request, short):
'domain': domain,
})
@login_required
def edit(request, short):
"""
This view allows a logged in user to edit the details of a Go link that they
own. They can modify any value that they wish. If `short` is modified then
we will need to create a new link and copy over stats from the previous.
"""
# Do not allow unapproved users to edit links
if not request.user.registereduser.approved:
return render(request, 'not_registered.html')
# Get the URL that is going to be edited
url = get_object_or_404(URL, short__iexact=short)
# If the RegisteredUser is the owner of the URL
if url.owner == request.user.registereduser:
# render the edit URL form
# TODO
# redirect to my_links
return redirect('my_links')
else:
# do not allow them to edit
raise PermissionDenied()
@login_required
def delete(request, short):
"""
......@@ -211,7 +236,7 @@ def delete(request, short):
if url.owner == request.user.registereduser:
# remove the URL
url.delete()
# rediret to my_links
# redirect to my_links
return redirect('my_links')
else:
# do not allow them to delete
......
......@@ -82,6 +82,39 @@ class UrlsTest(TestCase):
url = reverse('my_links')
self.assertEqual(url, '/myLinks')
def test_edit_reverse_chars(self):
"""
/edit/<short> - Delete a link, no content display.
"""
url = reverse('edit', args=['dhaynes'])
self.assertEqual(url, '/delete/dhaynes')
def test_edit_reverse_ints(self):
"""
/edit/<short> - Delete a link, no content display.
"""
url = reverse('edit', args=['123456789'])
self.assertEqual(url, '/delete/123456789')
def test_edit_reverse_chars_ints(self):
"""
/edit/<short> - Delete a link, no content display.
"""
url = reverse('edit', args=['dhaynes123'])
self.assertEqual(url, '/delete/dhaynes123')
def test_edit_reverse_full_slug(self):
"""
/edit/<short> - Delete a link, no content display.
"""
url = reverse('edit', args=['dhaynes123_-'])
self.assertEqual(url, '/delete/dhaynes123_-')
def test_delete_reverse_chars(self):
"""
/delete/<short> - Delete a link, no content display.
......
......@@ -42,6 +42,9 @@ urlpatterns = [
# /myLinks - My-Links page, view and review links.
url(r'^myLinks/?$', go.views.my_links, name='my_links'),
# /edit/<short> - Edit link form
url(r'^edit/(?P<short>[-\w]+)$', go.views.edit, name='edit'),
# /delete/<short> - Delete a link, no content display.
url(r'^delete/(?P<short>[-\w]+)$', go.views.delete, name='delete'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment