Add flag to disable LocalizedUniqueSlugField

This commit is contained in:
Swen Kooij
2021-03-13 13:24:36 +02:00
parent 62e1e805c7
commit bd8924224e
2 changed files with 27 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
import copy
import pytest
from django import forms
from django.conf import settings
from django.db import models
@@ -215,6 +217,27 @@ class LocalizedSlugFieldTestCase(TestCase):
for lang_code, lang_name in settings.LANGUAGES:
assert obj.slug.get(lang_code) == "title-%s" % lang_name.lower()
@classmethod
def test_disable(cls):
"""Tests whether disabling auto-slugging works."""
Model = get_fake_model(
{
"title": LocalizedField(),
"slug": LocalizedUniqueSlugField(
populate_from="title", enabled=False
),
}
)
obj = Model()
obj.title = "test"
# should raise IntegrityError because auto-slugging
# is disabled and the slug field is NULL
with pytest.raises(IntegrityError):
obj.save()
@classmethod
def test_allows_override_when_immutable(cls):
"""Tests whether setting a value manually works and does not get