summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-08-22 11:39:33 +1000
committerMarkus Holtermann <info@markusholtermann.eu>2015-08-27 09:52:53 +1000
commit91f701f4fc324cd2feb7dbf151338a358ca0ea18 (patch)
treed8373e20ec7ec1f9d281e03297dd06a45e301cb2 /tests
parent1175027641f512d33909cb766563328c6b171578 (diff)
Fixed #25280 -- Properly checked regex objects for equality to prevent infinite migrations
Thanks Sayid Munawar and Tim Graham for the report, investigation and review.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 5caec12db8..8bee31c217 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
+import re
+
from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser
+from django.core.validators import RegexValidator, validate_slug
from django.db import connection, models
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.graph import MigrationGraph
@@ -997,6 +1000,46 @@ class AutodetectorTests(TestCase):
self.assertOperationAttributes(changes, "testapp", 0, 0, old_name="Author", new_name="NewAuthor")
self.assertOperationAttributes(changes, "testapp", 0, 1, name="newauthor", table="author_three")
+ def test_identical_regex_doesnt_alter(self):
+ from_state = ModelState(
+ "testapp", "model", [("id", models.AutoField(primary_key=True, validators=[
+ RegexValidator(
+ re.compile('^[-a-zA-Z0-9_]+\\Z'),
+ "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.",
+ 'invalid'
+ )
+ ]))]
+ )
+ to_state = ModelState(
+ "testapp", "model", [("id", models.AutoField(primary_key=True, validators=[validate_slug]))]
+ )
+ before = self.make_project_state([from_state])
+ after = self.make_project_state([to_state])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ # Right number/type of migrations?
+ self.assertNumberMigrations(changes, "testapp", 0)
+
+ def test_different_regex_does_alter(self):
+ from_state = ModelState(
+ "testapp", "model", [("id", models.AutoField(primary_key=True, validators=[
+ RegexValidator(
+ re.compile('^[a-z]+\\Z', 32),
+ "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.",
+ 'invalid'
+ )
+ ]))]
+ )
+ to_state = ModelState(
+ "testapp", "model", [("id", models.AutoField(primary_key=True, validators=[validate_slug]))]
+ )
+ before = self.make_project_state([from_state])
+ after = self.make_project_state([to_state])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+ self.assertNumberMigrations(changes, "testapp", 1)
+ self.assertOperationTypes(changes, "testapp", 0, ["AlterField"])
+
def test_empty_foo_together(self):
"""
#23452 - Empty unique/index_together shouldn't generate a migration.