Fixed #32073 -- Skipped collation tests on PostgreSQL < 10.

PostgreSQL < 10 doesn't support ICU collations.

Thanks Hannes Ljungberg for the report.
This commit is contained in:
Mariusz Felisiak 2020-10-06 12:51:35 +02:00 committed by GitHub
parent 143d8e1ab3
commit 999cddd58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 9 deletions

View File

@ -58,10 +58,16 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_deferrable_unique_constraints = True
has_json_operators = True
json_key_contains_list_matching_requires_list = True
test_collations = {
'non_default': 'sv-x-icu',
'swedish_ci': 'sv-x-icu',
}
@cached_property
def test_collations(self):
# PostgreSQL < 10 doesn't support ICU collations.
if self.is_postgresql_10:
return {
'non_default': 'sv-x-icu',
'swedish_ci': 'sv-x-icu',
}
return {}
@cached_property
def introspected_field_types(self):

View File

@ -105,6 +105,7 @@ class InspectDBTestCase(TestCase):
self.assertIn('null_json_field = models.JSONField(blank=True, null=True)', output)
@skipUnlessDBFeature('supports_collation_on_charfield')
@skipUnless(test_collation, 'Language collations are not supported.')
def test_char_field_db_collation(self):
out = StringIO()
call_command('inspectdb', 'inspectdb_charfielddbcollation', stdout=out)
@ -123,6 +124,7 @@ class InspectDBTestCase(TestCase):
)
@skipUnlessDBFeature('supports_collation_on_textfield')
@skipUnless(test_collation, 'Language collations are not supported.')
def test_text_field_db_collation(self):
out = StringIO()
call_command('inspectdb', 'inspectdb_textfielddbcollation', stdout=out)

View File

@ -3236,7 +3236,9 @@ class SchemaTests(TransactionTestCase):
@isolate_apps('schema')
@skipUnlessDBFeature('supports_collation_on_charfield')
def test_db_collation_charfield(self):
collation = connection.features.test_collations['non_default']
collation = connection.features.test_collations.get('non_default')
if not collation:
self.skipTest('Language collations are not supported.')
class Foo(Model):
field = CharField(max_length=255, db_collation=collation)
@ -3256,7 +3258,9 @@ class SchemaTests(TransactionTestCase):
@isolate_apps('schema')
@skipUnlessDBFeature('supports_collation_on_textfield')
def test_db_collation_textfield(self):
collation = connection.features.test_collations['non_default']
collation = connection.features.test_collations.get('non_default')
if not collation:
self.skipTest('Language collations are not supported.')
class Foo(Model):
field = TextField(db_collation=collation)
@ -3275,10 +3279,13 @@ class SchemaTests(TransactionTestCase):
@skipUnlessDBFeature('supports_collation_on_charfield')
def test_add_field_db_collation(self):
collation = connection.features.test_collations.get('non_default')
if not collation:
self.skipTest('Language collations are not supported.')
with connection.schema_editor() as editor:
editor.create_model(Author)
collation = connection.features.test_collations['non_default']
new_field = CharField(max_length=255, db_collation=collation)
new_field.set_attributes_from_name('alias')
with connection.schema_editor() as editor:
@ -3292,10 +3299,13 @@ class SchemaTests(TransactionTestCase):
@skipUnlessDBFeature('supports_collation_on_charfield')
def test_alter_field_db_collation(self):
collation = connection.features.test_collations.get('non_default')
if not collation:
self.skipTest('Language collations are not supported.')
with connection.schema_editor() as editor:
editor.create_model(Author)
collation = connection.features.test_collations['non_default']
old_field = Author._meta.get_field('name')
new_field = CharField(max_length=255, db_collation=collation)
new_field.set_attributes_from_name('name')
@ -3312,10 +3322,13 @@ class SchemaTests(TransactionTestCase):
@skipUnlessDBFeature('supports_collation_on_charfield')
def test_alter_field_type_and_db_collation(self):
collation = connection.features.test_collations.get('non_default')
if not collation:
self.skipTest('Language collations are not supported.')
with connection.schema_editor() as editor:
editor.create_model(Note)
collation = connection.features.test_collations['non_default']
old_field = Note._meta.get_field('info')
new_field = CharField(max_length=255, db_collation=collation)
new_field.set_attributes_from_name('info')