Skip to content

Commit

Permalink
test 4 custom_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mpachas committed Oct 14, 2022
1 parent ce3747e commit 8117868
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions autoslug/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class NonDeletedObjects(Manager):
def get_queryset(self):
return super(NonDeletedObjects, self).get_queryset().filter(is_deleted=False)

class NoObjects(Manager):
def get_queryset(self):
return super(NoObjects, self).get_queryset().none()


class AbstractModelWithCustomManager(Model):
is_deleted = BooleanField(default=False)
Expand All @@ -182,3 +186,10 @@ def delete(self, using=None):
class NonDeletableModelWithUniqueSlug(AbstractModelWithCustomManager):
name = CharField(max_length=200)
slug = AutoSlugField(populate_from='name', unique=True, manager_name='all_objects')

class ModelWithCustomManager(Model):
name = CharField(max_length=200)
slug = AutoSlugField(populate_from='name', unique_with=['name',])

objects = NoObjects()
all_objects = Manager()
9 changes: 9 additions & 0 deletions autoslug/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ def test_deconstruct_with_manager(self):
a.save()
_, _, _, kwargs = a._meta.get_field('slug').deconstruct()
self.assertNotIn('manager', kwargs)

def test_custom_manager(self):
greeting = 'Hello world!'
a = ModelWithCustomManager(name=greeting)
a.save()
assert a.slug == u'hello-world'
b = ModelWithCustomManager(name=greeting)
b.save()
assert b.slug == u'hello-world'


class AutoSlugModelTranslationTestCase(TestCase):
Expand Down

0 comments on commit 8117868

Please sign in to comment.