Repository: django-hijack/django-hijack

Issue:
Named urls for hijack endpoints
Was there a reason these URLs are unamed?

https://github.com/arteria/django-hijack/blob/master/hijack/urls.py#L6-L8

If not I could whip up a PR with those changes.



Discussion:
Hi @destos 
No, there is no special reason. A PR would be great. Thanks in advance. 


Resolving patch:
diff --git a/hijack/admin.py b/hijack/admin.py
--- a/hijack/admin.py
+++ b/hijack/admin.py
@@ -9,7 +9,7 @@
 class HijackUserAdminMixin(object):
 
     def hijack_field(self, obj):
-        return '<a href="%s" class="button">Hijack %s</a>' % (reverse('hijack.views.login_with_id',args=(obj.id,)), obj)
+        return '<a href="%s" class="button">Hijack %s</a>' % (reverse('login_with_id', args=(obj.id,)), obj)
     hijack_field.allow_tags = True
     hijack_field.short_description = 'Hijack User'
 
diff --git a/hijack/urls.py b/hijack/urls.py
--- a/hijack/urls.py
+++ b/hijack/urls.py
@@ -1,9 +1,9 @@
 from compat import patterns, url
- 
+
 urlpatterns = patterns('hijack.views',
     url(r'^disable-hijack-warning/$', 'disable_hijack_warning', name='disable_hijack_warning'),
     url(r'^release-hijack/$', 'release_hijack', name='release_hijack'),
-    url(r'^email/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', 'login_with_email'),
-    url(r'^username/(?P<username>\w+)/$', 'login_with_username'),
-    url(r'^(?P<userId>\w+)/$', 'login_with_id'),
+    url(r'^email/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', 'login_with_email', name='login_with_email'),
+    url(r'^username/(?P<username>\w+)/$', 'login_with_username', name='login_with_username'),
+    url(r'^(?P<userId>\w+)/$', 'login_with_id', name='login_with_id'),
 )


Test patch:
diff --git a/hijack/tests/hijack_tests.py b/hijack/tests/hijack_tests.py
--- a/hijack/tests/hijack_tests.py
+++ b/hijack/tests/hijack_tests.py
@@ -1,7 +1,9 @@
 from django.test import TestCase
+from django.core.urlresolvers import reverse
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.contrib.admin.sites import AdminSite
+from six.moves.urllib.parse import unquote
 
 from django import VERSION
 
@@ -35,13 +37,13 @@ def test_hijack_simple(self):
         self.client.login(username='Admin',password='Admin pw')
         response = self.client.get('/hijack/2/', follow=True)
         self.assertTrue('on behalf of %s' % (response.context['user'].username) in str(response.content))
-        
+
         response = self.client.get('/hijack/release-hijack/', follow=True)
         self.assertEqual(response.context['user'].username, 'Admin')
-        
+
         response = self.client.get('/hijack/3/', follow=True)
         self.assertTrue('on behalf of %s' % (response.context['user'].username) in str(response.content))
-        
+
         response = self.client.get('/hijack/disable-hijack-warning/?next=/hello', follow=True)
         self.assertFalse('on behalf of %s' % (response.context['user'].username) in str(response.content))
 
@@ -98,19 +100,21 @@ def test_hijack_helper_permission_denied(self):
             self.assertEqual(response.status_code, 302)
         else:
             self.assertTrue('name="this_is_the_login_form"' in  str(response.content))
-        
+
     def test_hijack_admin(self):
         from hijack.admin import HijackUserAdmin
 
         ua = HijackUserAdmin(User, AdminSite())
         self.assertEqual(ua.list_display, ('username', 'email', 'first_name', 'last_name',  'last_login', 'date_joined', 'is_staff', 'hijack_field',))
 
+    def test_hijack_urls(self):
+        self.assertEqual('/hijack/disable-hijack-warning/', reverse('disable_hijack_warning'))
+        self.assertEqual('/hijack/release-hijack/', reverse('release_hijack'))
+        self.assertEqual('/hijack/1/', reverse('login_with_id', args=[1]))
+        self.assertEqual('/hijack/2/', reverse('login_with_id', kwargs={'userId': 2}))
+        self.assertEqual('/hijack/username/bob/', reverse('login_with_username', args=['bob']))
+        self.assertEqual('/hijack/username/bob_too/', reverse('login_with_username', kwargs={'username':'bob_too'}))
+        self.assertEqual('/hijack/email/bob@bobsburgers.com/', unquote(reverse('login_with_email', args=['bob@bobsburgers.com'])))
+        self.assertEqual('/hijack/email/bob_too@bobsburgers.com/', unquote(reverse('login_with_email', kwargs={'email':'bob_too@bobsburgers.com'})))
 
 #    def test_hijack_
-
-
-
-
-
-
-
diff --git a/test_requirements.txt b/test_requirements.txt
--- a/test_requirements.txt
+++ b/test_requirements.txt
@@ -9,3 +9,4 @@ factory_boy
 mock
 selenium
 django-compat
+six