Skip to content

Commit

Permalink
Merge pull request #483 from CTPUG/bugs/allow_empty_slugs
Browse files Browse the repository at this point in the history
Bugs/allow empty slugs
  • Loading branch information
drnlm authored Oct 3, 2019
2 parents 83a82d3 + 6314f9c commit b80717c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions wafer/talks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,49 @@ def test_view_seven_speakers(self):
self.check_n_speakers(7, [(0, 4), (4, 7)])


class TalkSlugUrlTests(TestCase):
"""Check that we can lookup a talk via correct and incorrect slugs"""
def setUp(self):
self.talk_a = create_talk('Test Talk 1', ACCEPTED, "author_a")
# Unicode talk will generate empty slug - this should not crash
self.talk_b = create_talk(u'\xa9\xa3', ACCEPTED, "author_b")
self.client = Client()

def test_slug_generation(self):
self.assertEqual(self.talk_a.slug, 'test-talk-1')
self.assertEqual(self.talk_b.slug, '')

def test_non_unicode_slug_lookups(self):
response = self.client.get('/talks/%d-test-talk-1/' % self.talk_a.pk)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '%s' % self.talk_a.title)

response = self.client.get('/talks/%d-bogus-slug/' % self.talk_a.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/talks/%d-test-talk-1/' % self.talk_a.pk)

response = self.client.get('/talks/%d-/' % self.talk_a.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/talks/%d-test-talk-1/' % self.talk_a.pk)

response = self.client.get('/talks/%d/' % self.talk_a.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/talks/%d-test-talk-1/' % self.talk_a.pk)

def test_unicode_slug_lookups(self):
response = self.client.get('/talks/%d-/' % self.talk_b.pk)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '%s' % self.talk_b.title)

response = self.client.get('/talks/%d-bogus-slug/' % self.talk_b.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/talks/%d-/' % self.talk_b.pk)

response = self.client.get('/talks/%d/' % self.talk_b.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, '/talks/%d-/' % self.talk_b.pk)


class TalkViewSetPermissionTests(TestCase):

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion wafer/talks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
url(r'^page/(?P<page>\d+)/$', UsersTalks.as_view(),
name='wafer_users_talks_page'),
url(r'^new/$', TalkCreate.as_view(), name='wafer_talk_submit'),
url(r'^(?P<pk>\d+)(?:-(?P<slug>[\w-]+))?/$', TalkView.as_view(),
url(r'^(?P<pk>\d+)(?:-(?P<slug>[\w-]*))?/$', TalkView.as_view(),
name='wafer_talk'),
url(r'^(?P<pk>\d+)/edit/$', TalkUpdate.as_view(),
name='wafer_talk_edit'),
Expand Down

0 comments on commit b80717c

Please sign in to comment.