def test_zinnia_entry_shortlink(self): with self.assertNumQueries(1): response = self.client.get('/%s/' % base36(self.first_entry.pk)) self.assertEqual(response.status_code, 301) self.assertEqual( response['Location'], 'http://testserver%s' % self.first_entry.get_absolute_url())
def test_get_short_url(self): self.check_with_rich_and_poor_urls( self.admin.get_short_url, (self.entry, ), '<a href="http://example.com/%(hash)s/" target="blank">' 'http://example.com/%(hash)s/</a>' % {'hash': base36(self.entry.pk)}, '<a href="%(url)s" target="blank">%(url)s</a>' % {'url': self.entry.get_absolute_url()})
def test_zinnia_entry_shortlink_unpublished(self): """ https://github.com/Fantomas42/django-blog-zinnia/pull/367 """ self.first_entry.sites.clear() with self.assertNumQueries(1): response = self.client.get('/%s/' % base36(self.first_entry.pk)) self.assertEqual(response.status_code, 404)
def test_short_url(self): original_shortener = shortener_settings.URL_SHORTENER_BACKEND shortener_settings.URL_SHORTENER_BACKEND = 'events.url_shortener.'\ 'backends.default' self.assertEqual(self.entry.short_url, 'http://example.com' + reverse('events:entry_shortlink', args=[base36(self.entry.pk)])) shortener_settings.URL_SHORTENER_BACKEND = original_shortener
def test_base36(self): self.assertEqual(default.base36(1), '1') self.assertEqual(default.base36(100), '2S') self.assertEqual(default.base36(46656), '1000')