mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 03:32:55 +03:00
Remove tests for LocalizedAutoSlug
This commit is contained in:
parent
96ddc77cfc
commit
8ad9268426
@ -9,7 +9,6 @@ from django.utils.text import slugify
|
|||||||
|
|
||||||
from localized_fields.fields import (
|
from localized_fields.fields import (
|
||||||
LocalizedField,
|
LocalizedField,
|
||||||
LocalizedAutoSlugField,
|
|
||||||
LocalizedUniqueSlugField
|
LocalizedUniqueSlugField
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,14 +27,6 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
|
|
||||||
super(LocalizedSlugFieldTestCase, cls).setUpClass()
|
super(LocalizedSlugFieldTestCase, cls).setUpClass()
|
||||||
|
|
||||||
cls.AutoSlugModel = get_fake_model(
|
|
||||||
{
|
|
||||||
'title': LocalizedField(),
|
|
||||||
'name': models.CharField(max_length=255),
|
|
||||||
'slug': LocalizedAutoSlugField(populate_from='title')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
cls.MagicSlugModel = get_fake_model(
|
cls.MagicSlugModel = get_fake_model(
|
||||||
{
|
{
|
||||||
'title': LocalizedField(),
|
'title': LocalizedField(),
|
||||||
@ -44,30 +35,6 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_auto(cls):
|
|
||||||
cls._test_populate(cls.AutoSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_unique(cls):
|
|
||||||
cls._test_populate(cls.MagicSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_languages_auto(cls):
|
|
||||||
cls._test_populate_multiple_languages(cls.AutoSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_languages_unique(cls):
|
|
||||||
cls._test_populate_multiple_languages(cls.MagicSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_unique_slug_auto(cls):
|
|
||||||
cls._test_unique_slug(cls.AutoSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_unique_slug_unique(cls):
|
|
||||||
cls._test_unique_slug(cls.MagicSlugModel)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def test_unique_slug_with_time():
|
def test_unique_slug_with_time():
|
||||||
"""Tests whether the primary key is included in
|
"""Tests whether the primary key is included in
|
||||||
@ -114,74 +81,35 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
assert old_slug_en == obj.slug.en
|
assert old_slug_en == obj.slug.en
|
||||||
assert old_slug_nl != obj.slug.nl
|
assert old_slug_nl != obj.slug.nl
|
||||||
|
|
||||||
def test_unique_slug_unique_max_retries(self):
|
@classmethod
|
||||||
|
def test_unique_slug_unique_max_retries(cls):
|
||||||
"""Tests whether the unique slug implementation doesn't
|
"""Tests whether the unique slug implementation doesn't
|
||||||
try to find a slug forever and gives up after a while."""
|
try to find a slug forever and gives up after a while."""
|
||||||
|
|
||||||
title = 'myuniquetitle'
|
title = 'myuniquetitle'
|
||||||
|
|
||||||
obj = self.MagicSlugModel()
|
obj = cls.MagicSlugModel()
|
||||||
obj.title.en = title
|
obj.title.en = title
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
with self.assertRaises(IntegrityError):
|
with cls.assertRaises(cls, IntegrityError):
|
||||||
for _ in range(0, settings.LOCALIZED_FIELDS_MAX_RETRIES + 1):
|
for _ in range(0, settings.LOCALIZED_FIELDS_MAX_RETRIES + 1):
|
||||||
another_obj = self.MagicSlugModel()
|
another_obj = cls.MagicSlugModel()
|
||||||
another_obj.title.en = title
|
another_obj.title.en = title
|
||||||
another_obj.save()
|
another_obj.save()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def test_unique_slug_utf_auto(cls):
|
def test_populate(cls):
|
||||||
cls._test_unique_slug_utf(cls.AutoSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_unique_slug_utf_unique(cls):
|
|
||||||
cls._test_unique_slug_utf(cls.MagicSlugModel)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_deconstruct_auto(cls):
|
|
||||||
cls._test_deconstruct(LocalizedAutoSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_deconstruct_unique(cls):
|
|
||||||
cls._test_deconstruct(LocalizedUniqueSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_formfield_auto(cls):
|
|
||||||
cls._test_formfield(LocalizedAutoSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_formfield_unique(cls):
|
|
||||||
cls._test_formfield(LocalizedUniqueSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_from_fields_auto(cls):
|
|
||||||
cls._test_populate_multiple_from_fields(LocalizedAutoSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_from_fields_unique(cls):
|
|
||||||
cls._test_populate_multiple_from_fields(LocalizedUniqueSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_from_fields_fk_auto(cls):
|
|
||||||
cls._test_populate_multiple_from_fields_fk(LocalizedAutoSlugField)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def test_populate_multiple_from_fields_fk_unique(cls):
|
|
||||||
cls._test_populate_multiple_from_fields_fk(LocalizedUniqueSlugField)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _test_populate(model):
|
|
||||||
"""Tests whether the populating feature works correctly."""
|
"""Tests whether the populating feature works correctly."""
|
||||||
|
|
||||||
obj = model()
|
obj = cls.MagicSlugModel()
|
||||||
obj.title.en = 'this is my title'
|
obj.title.en = 'this is my title'
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
assert obj.slug.get('en') == slugify(obj.title)
|
assert obj.slug.get('en') == slugify(obj.title)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _test_populate_multiple_from_fields(field_type):
|
def test_populate_multiple_from_fields():
|
||||||
"""Tests whether populating the slug from multiple
|
"""Tests whether populating the slug from multiple
|
||||||
fields works correctly."""
|
fields works correctly."""
|
||||||
|
|
||||||
@ -189,7 +117,7 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
{
|
{
|
||||||
'title': LocalizedField(),
|
'title': LocalizedField(),
|
||||||
'name': models.CharField(max_length=255),
|
'name': models.CharField(max_length=255),
|
||||||
'slug': field_type(populate_from=('title', 'name'))
|
'slug': LocalizedUniqueSlugField(populate_from=('title', 'name'))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -204,7 +132,7 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
assert obj.slug.get(lang_code) == 'title-%s-swen' % lang_name.lower()
|
assert obj.slug.get(lang_code) == 'title-%s-swen' % lang_name.lower()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _test_populate_multiple_from_fields_fk(field_type):
|
def test_populate_multiple_from_fields_fk():
|
||||||
"""Tests whether populating the slug from multiple
|
"""Tests whether populating the slug from multiple
|
||||||
fields works correctly."""
|
fields works correctly."""
|
||||||
|
|
||||||
@ -218,7 +146,7 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
{
|
{
|
||||||
'title': LocalizedField(),
|
'title': LocalizedField(),
|
||||||
'other': models.ForeignKey(model_fk),
|
'other': models.ForeignKey(model_fk),
|
||||||
'slug': field_type(populate_from=('title', 'other.name'))
|
'slug': LocalizedUniqueSlugField(populate_from=('title', 'other.name'))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -234,12 +162,12 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
for lang_code, lang_name in settings.LANGUAGES:
|
for lang_code, lang_name in settings.LANGUAGES:
|
||||||
assert obj.slug.get(lang_code) == 'title-%s-swen' % lang_name.lower()
|
assert obj.slug.get(lang_code) == 'title-%s-swen' % lang_name.lower()
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def _test_populate_multiple_languages(model):
|
def test_populate_multiple_languages(cls):
|
||||||
"""Tests whether the populating feature correctly
|
"""Tests whether the populating feature correctly
|
||||||
works for all languages."""
|
works for all languages."""
|
||||||
|
|
||||||
obj = model()
|
obj = cls.MagicSlugModel()
|
||||||
for lang_code, lang_name in settings.LANGUAGES:
|
for lang_code, lang_name in settings.LANGUAGES:
|
||||||
obj.title.set(lang_code, 'title %s' % lang_name)
|
obj.title.set(lang_code, 'title %s' % lang_name)
|
||||||
|
|
||||||
@ -248,53 +176,53 @@ class LocalizedSlugFieldTestCase(TestCase):
|
|||||||
for lang_code, lang_name in settings.LANGUAGES:
|
for lang_code, lang_name in settings.LANGUAGES:
|
||||||
assert obj.slug.get(lang_code) == 'title-%s' % lang_name.lower()
|
assert obj.slug.get(lang_code) == 'title-%s' % lang_name.lower()
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def _test_unique_slug(model):
|
def test_unique_slug(cls):
|
||||||
"""Tests whether unique slugs are properly generated."""
|
"""Tests whether unique slugs are properly generated."""
|
||||||
|
|
||||||
title = 'myuniquetitle'
|
title = 'myuniquetitle'
|
||||||
|
|
||||||
obj = model()
|
obj = cls.MagicSlugModel()
|
||||||
obj.title.en = title
|
obj.title.en = title
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
for i in range(1, settings.LOCALIZED_FIELDS_MAX_RETRIES - 1):
|
for i in range(1, settings.LOCALIZED_FIELDS_MAX_RETRIES - 1):
|
||||||
another_obj = model()
|
another_obj = cls.MagicSlugModel()
|
||||||
another_obj.title.en = title
|
another_obj.title.en = title
|
||||||
another_obj.save()
|
another_obj.save()
|
||||||
|
|
||||||
assert another_obj.slug.en == '%s-%d' % (title, i)
|
assert another_obj.slug.en == '%s-%d' % (title, i)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def _test_unique_slug_utf(model):
|
def test_unique_slug_utf(cls):
|
||||||
"""Tests whether generating a slug works
|
"""Tests whether generating a slug works
|
||||||
when the value consists completely out
|
when the value consists completely out
|
||||||
of non-ASCII characters."""
|
of non-ASCII characters."""
|
||||||
|
|
||||||
obj = model()
|
obj = cls.MagicSlugModel()
|
||||||
obj.title.en = 'مكاتب للايجار بشارع بورسعيد'
|
obj.title.en = 'مكاتب للايجار بشارع بورسعيد'
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
assert obj.slug.en == 'مكاتب-للايجار-بشارع-بورسعيد'
|
assert obj.slug.en == 'مكاتب-للايجار-بشارع-بورسعيد'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _test_deconstruct(field_type):
|
def test_deconstruct():
|
||||||
"""Tests whether the :see:deconstruct
|
"""Tests whether the :see:deconstruct
|
||||||
function properly retains options
|
function properly retains options
|
||||||
specified in the constructor."""
|
specified in the constructor."""
|
||||||
|
|
||||||
field = field_type(populate_from='title')
|
field = LocalizedUniqueSlugField(populate_from='title')
|
||||||
_, _, _, kwargs = field.deconstruct()
|
_, _, _, kwargs = field.deconstruct()
|
||||||
|
|
||||||
assert 'populate_from' in kwargs
|
assert 'populate_from' in kwargs
|
||||||
assert kwargs['populate_from'] == field.populate_from
|
assert kwargs['populate_from'] == field.populate_from
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _test_formfield(field_type):
|
def test_formfield():
|
||||||
"""Tests whether the :see:formfield method
|
"""Tests whether the :see:formfield method
|
||||||
returns a valid form field that is hidden."""
|
returns a valid form field that is hidden."""
|
||||||
|
|
||||||
form_field = field_type(populate_from='title').formfield()
|
form_field = LocalizedUniqueSlugField(populate_from='title').formfield()
|
||||||
|
|
||||||
assert isinstance(form_field, forms.CharField)
|
assert isinstance(form_field, forms.CharField)
|
||||||
assert isinstance(form_field.widget, forms.HiddenInput)
|
assert isinstance(form_field.widget, forms.HiddenInput)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user