def testAutoCreateNextSlug(self): m = SluggedTestModel(title='foo') m.save() m = SluggedTestModel(title='foo') m.save() self.assertEqual(m.slug, 'foo-2')
def testInheritanceCreatesNextSlug(self): m = SluggedTestModel(title='foo') m.save() n = ChildSluggedTestModel(title='foo') n.save() self.assertEqual(n.slug, 'foo-2') o = SluggedTestModel(title='foo') o.save() self.assertEqual(o.slug, 'foo-3')
def testSimpleSlugSource(self): m = SluggedTestModel(title='-foo') m.save() self.assertEqual(m.slug, 'foo') n = SluggedTestModel(title='-foo') n.save() self.assertEqual(n.slug, 'foo-2') n.save() self.assertEqual(n.slug, 'foo-2')
def testEmptySlugSource(self): # regression test m = SluggedTestModel(title='') m.save() self.assertEqual(m.slug, '-2') n = SluggedTestModel(title='') n.save() self.assertEqual(n.slug, '-3') n.save() self.assertEqual(n.slug, '-3')
def testUpdateSlug(self): m = SluggedTestModel(title='foo') m.save() self.assertEqual(m.slug, 'foo') # update m instance without using `save' SluggedTestModel.objects.filter(pk=m.pk).update(slug='foo-2012') # update m instance with new data from the db m = SluggedTestModel.objects.get(pk=m.pk) self.assertEqual(m.slug, 'foo-2012') m.save() self.assertEqual(m.title, 'foo') self.assertEqual(m.slug, 'foo-2012') # Check slug is not overwrite m.title = 'bar' m.save() self.assertEqual(m.title, 'bar') self.assertEqual(m.slug, 'foo-2012')
def testAutoUpdateSlugWithNumber(self): m = SluggedTestModel(title='foo 2012') m.save() m.save() self.assertEqual(m.slug, 'foo-2012')