From ad5587fbefe90b049ee7d7b0e5dc09d539dfc49d Mon Sep 17 00:00:00 2001 From: Nitish Bansal Date: Sun, 4 Mar 2018 03:05:00 +0530 Subject: [PATCH 1/3] Url resolved with special characters --- readthedocs/profiles/urls/public.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/profiles/urls/public.py b/readthedocs/profiles/urls/public.py index 028b66caa28..2a9c458e6fd 100644 --- a/readthedocs/profiles/urls/public.py +++ b/readthedocs/profiles/urls/public.py @@ -7,7 +7,7 @@ urlpatterns = [ - url(r'^(?P[\w@.-]+)/$', + url(r'^(?P[+\w@.-]+)/$', views.profile_detail, {'template_name': 'profiles/public/profile_detail.html'}, name='profiles_profile_detail'), From dacf27f2d8d799880f464b0b310cb1d528da3ed4 Mon Sep 17 00:00:00 2001 From: bansalnitish Date: Fri, 9 Mar 2018 00:38:03 +0530 Subject: [PATCH 2/3] add tests --- readthedocs/rtd_tests/tests/test_views.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/readthedocs/rtd_tests/tests/test_views.py b/readthedocs/rtd_tests/tests/test_views.py index a3fdad5f4d8..4fea7f80e49 100644 --- a/readthedocs/rtd_tests/tests/test_views.py +++ b/readthedocs/rtd_tests/tests/test_views.py @@ -241,3 +241,30 @@ def test_project_admins_can_delete_subprojects_that_they_are_not_admin_of(self): '/dashboard/my-mainproject/subprojects/my-subproject/delete/') self.assertEqual(response.status_code, 302) self.assertTrue(self.subproject not in [r.child for r in self.project.subprojects.all()]) + +class URLResolution(TestCase): + def setUp(self): + self.user1 = new(User, username='foo+bar') + self.user1.set_password('test1') + self.user1.save() + + self.user2 = new(User, username='abc+def@ghi.jkl') + self.user2.set_password('test2') + self.user2.save() + + self.user3 = new(User, username='abc-def+ghi') + self.user3.set_password('test3') + self.user3.save() + + self.client.login(username='foo+bar', password='test1') + + def test_profile_details_page(self): + + response = self.client.get('/profiles/foo+bar/') + self.assertEqual(response.status_code, 200) + + response = self.client.get('/profiles/abc+def@ghi.jkl/') + self.assertEqual(response.status_code, 200) + + response = self.client.get('/profiles/abc-def+ghi/') + self.assertEqual(response.status_code, 200) From 8fdf569736a1ab508c6ea7607e7dace718a6ccf2 Mon Sep 17 00:00:00 2001 From: bansalnitish Date: Wed, 18 Apr 2018 02:42:00 +0530 Subject: [PATCH 3/3] fix testing --- readthedocs/rtd_tests/tests/test_urls.py | 22 ++++++++++++++++++ readthedocs/rtd_tests/tests/test_views.py | 27 ----------------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_urls.py b/readthedocs/rtd_tests/tests/test_urls.py index 21460da8f85..27a14a27b99 100644 --- a/readthedocs/rtd_tests/tests/test_urls.py +++ b/readthedocs/rtd_tests/tests/test_urls.py @@ -51,3 +51,25 @@ def test_version_url_with_caps(self): kwargs={'type_': 'pdf', 'version_slug': u'1.4.X', 'project_slug': u'django'} ) self.assertTrue(url) + + +class TestProfileDetailURLs(TestCase): + + def test_profile_detail_url(self): + url = reverse( + 'profiles_profile_detail', + kwargs={'username': 'foo+bar'} + ) + self.assertEqual(url, '/profiles/foo+bar/') + + url = reverse( + 'profiles_profile_detail', + kwargs={'username': 'abc+def@ghi.jkl'} + ) + self.assertEqual(url, '/profiles/abc+def@ghi.jkl/') + + url = reverse( + 'profiles_profile_detail', + kwargs={'username': 'abc-def+ghi'} + ) + self.assertEqual(url, '/profiles/abc-def+ghi/') diff --git a/readthedocs/rtd_tests/tests/test_views.py b/readthedocs/rtd_tests/tests/test_views.py index 4fea7f80e49..a3fdad5f4d8 100644 --- a/readthedocs/rtd_tests/tests/test_views.py +++ b/readthedocs/rtd_tests/tests/test_views.py @@ -241,30 +241,3 @@ def test_project_admins_can_delete_subprojects_that_they_are_not_admin_of(self): '/dashboard/my-mainproject/subprojects/my-subproject/delete/') self.assertEqual(response.status_code, 302) self.assertTrue(self.subproject not in [r.child for r in self.project.subprojects.all()]) - -class URLResolution(TestCase): - def setUp(self): - self.user1 = new(User, username='foo+bar') - self.user1.set_password('test1') - self.user1.save() - - self.user2 = new(User, username='abc+def@ghi.jkl') - self.user2.set_password('test2') - self.user2.save() - - self.user3 = new(User, username='abc-def+ghi') - self.user3.set_password('test3') - self.user3.save() - - self.client.login(username='foo+bar', password='test1') - - def test_profile_details_page(self): - - response = self.client.get('/profiles/foo+bar/') - self.assertEqual(response.status_code, 200) - - response = self.client.get('/profiles/abc+def@ghi.jkl/') - self.assertEqual(response.status_code, 200) - - response = self.client.get('/profiles/abc-def+ghi/') - self.assertEqual(response.status_code, 200)