Support apps with custom label.

This commit is contained in:
Oleg Samokhin authored and David Wobrock committed 2025-04-21 16:43:45 +02:00
1 parent 572ab55cb0
commit 0ee05a2b30
10 files changed
+125 -22

No files matched your search

+2
View File
@@ -19,3 +19,5 @@ DATA_MIGRATIONS = "app_data_migrations"
MAKE_NOT_NULL_WITH_DJANGO_DEFAULT = "app_make_not_null_with_django_default"
MAKE_NOT_NULL_WITH_LIB_DEFAULT = "app_make_not_null_with_lib_default"
CREATE_INDEX_EXCLUSIVE = "app_create_index_exclusive"
CUSTOM_APP_NAME_DIRECTORY = "app_with_custom_name"
CUSTOM_APP_LABEL = "my_custom_name"
+30 -4
View File
@@ -34,22 +34,32 @@ class BaseBackwardCompatibilityDetection:
linter = self._launch_linter(app, commit_id)
self.assertTrue(linter.has_errors)
self.assertNotEqual(linter.nb_valid + linter.nb_erroneous, 0)
self.assertGreater(linter.nb_total, 0)
def _test_linter_finds_no_errors(self, app=None, commit_id=None):
linter = self._launch_linter(app, commit_id)
self.assertFalse(linter.has_errors)
self.assertNotEqual(linter.nb_valid + linter.nb_erroneous, 0)
self.assertGreater(linter.nb_total, 0)
def _test_linter_linted_no_migration(self, app=None, commit_id=None):
linter = self._launch_linter(app, commit_id)
self.assertEqual(linter.nb_valid, 0)
self.assertEqual(linter.nb_erroneous, 0)
self.assertEqual(linter.nb_total, 0)
def _launch_linter(self, app=None, commit_id=None):
linter = MigrationLinter(
linter = self._get_linter()
linter.lint_all_migrations(app_label=app, git_commit_id=commit_id)
return linter
def _get_linter(self):
return MigrationLinter(
self.test_project_path,
database=self.database,
no_cache=True,
)
linter.lint_all_migrations(app_label=app, git_commit_id=commit_id)
return linter
# *** Tests ***
def test_create_table_with_not_null_column(self):
app = fixtures.CREATE_TABLE_WITH_NOT_NULL_COLUMN
self._test_linter_finds_no_errors(app)
@@ -121,6 +131,22 @@ class BaseBackwardCompatibilityDetection:
with self.assertRaises(ValueError):
linter.get_sql("app_unique_together", "0003")
def test_custom_named_app(self):
# Folder name is not found.
app = fixtures.CUSTOM_APP_NAME_DIRECTORY
self._test_linter_linted_no_migration(app)
# Django app name is found.
app = fixtures.CUSTOM_APP_LABEL
self._test_linter_finds_no_errors(app)
# And with git ref:
app = fixtures.CUSTOM_APP_NAME_DIRECTORY
self._test_linter_linted_no_migration(app, commit_id="v0.1.4")
app = fixtures.CUSTOM_APP_LABEL
self._test_linter_finds_no_errors(app, commit_id="v0.1.4")
class SqliteBackwardCompatibilityDetectionTestCase(
BaseBackwardCompatibilityDetection, unittest.TestCase
Whitespace-only changes.
@@ -0,0 +1,8 @@
from __future__ import annotations
from django.apps import AppConfig
class DefaultConfig(AppConfig):
name = "tests.test_project.app_with_custom_name"
label = "my_custom_name"
@@ -0,0 +1,30 @@
# Generated by Django 2.2 on 2019-07-29 21:21
from __future__ import annotations
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("int_field", models.IntegerField()),
("char_field", models.CharField(max_length=255)),
],
)
]
Whitespace-only changes.
@@ -0,0 +1,8 @@
from __future__ import annotations
from django.db import models
class A(models.Model):
int_field = models.IntegerField()
char_field = models.CharField(max_length=255)
+1
View File
@@ -59,6 +59,7 @@ INSTALLED_APPS = [
"tests.test_project.app_make_not_null_with_django_default",
"tests.test_project.app_make_not_null_with_lib_default",
"tests.test_project.app_create_index_exclusive",
"tests.test_project.app_with_custom_name.apps.DefaultConfig",
]
if django.VERSION[0] >= 5: