Add a new auto-slug field that is concurrency resistent

This commit is contained in:
Swen Kooij
2017-02-02 10:58:04 +02:00
parent 1adcd5a399
commit a48eb12370
6 changed files with 63 additions and 15 deletions

View File

@@ -1,10 +1,7 @@
from django.contrib.postgres.operations import HStoreExtension
from django.db import connection, migrations
from localized_fields import LocalizedModel
from django.db.migrations.executor import MigrationExecutor
import sys
from localized_fields import (LocalizedAutoSlugField, LocalizedField,
LocalizedModel, LocalizedMagicSlugField)
from django.contrib.postgres.operations import HStoreExtension
def get_fake_model(name='TestModel', fields={}):

View File

@@ -1,10 +1,10 @@
from django import forms
from django.conf import settings
from django.test import TestCase
from localized_fields import (LocalizedField, LocalizedAutoSlugField,
LocalizedMagicSlugField)
from django.utils.text import slugify
from localized_fields import LocalizedField, LocalizedAutoSlugField, LocalizedMagicSlugField
from .fake_model import get_fake_model
@@ -71,7 +71,6 @@ class LocalizedSlugFieldTestCase(TestCase):
@classmethod
def test_deconstruct_auto(cls):
cls._test_deconstruct(LocalizedAutoSlugField)
cls._test_deconstruct(LocalizedMagicSlugField)
@classmethod
def test_deconstruct_magic(cls):
@@ -93,7 +92,7 @@ class LocalizedSlugFieldTestCase(TestCase):
obj.title.en = 'this is my title'
obj.save()
assert obj.slug.get('en') == slugify(obj.title.en)
assert obj.slug.get('en') == slugify(obj.title)
@staticmethod
def _test_populate_multiple_languages(model):
@@ -117,11 +116,12 @@ class LocalizedSlugFieldTestCase(TestCase):
obj.title.en = 'title'
obj.save()
another_obj = model()
another_obj.title.en = 'title'
another_obj.save()
for i in range(1, 90):
another_obj = model()
another_obj.title.en = 'title'
another_obj.save()
assert another_obj.slug.en == 'title-1'
assert another_obj.slug.en == 'title-%d' % i
@staticmethod
def _test_unique_slug_utf(model):