diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0013_alter_blacklistedtoken_options_and_more.py b/rest_framework_simplejwt/token_blacklist/migrations/0013_alter_blacklistedtoken_options_and_more.py new file mode 100644 index 000000000..9212c7cf4 --- /dev/null +++ b/rest_framework_simplejwt/token_blacklist/migrations/0013_alter_blacklistedtoken_options_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 5.1.7 on 2025-03-23 06:56 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("token_blacklist", "0012_alter_outstandingtoken_user"), + ] + + operations = [ + migrations.AlterModelOptions( + name="blacklistedtoken", + options={ + "verbose_name": "Blacklisted Token", + "verbose_name_plural": "Blacklisted Tokens", + }, + ), + migrations.AlterModelOptions( + name="outstandingtoken", + options={ + "ordering": ("user",), + "verbose_name": "Outstanding Token", + "verbose_name_plural": "Outstanding Tokens", + }, + ), + ] diff --git a/tests/test_migrations.py b/tests/test_migrations.py new file mode 100644 index 000000000..6e8d08b47 --- /dev/null +++ b/tests/test_migrations.py @@ -0,0 +1,42 @@ +from io import StringIO +from typing import Optional + +import pytest +from django.core.management import call_command +from django.test import TestCase + + +class MigrationTestCase(TestCase): + def test_no_missing_migrations(self): + """ + Ensures all model changes are reflected in migrations. + If this test fails, there are model changes that require a new migration. + + Behavior: + - Passes silently if no migrations are required + - Fails with a detailed message if migrations are need + """ + + output = StringIO() + + # Initialize exception variable to track migration check result + exec: Optional[SystemExit] = None + + try: + # Check for pending migrations without actually creating them + call_command( + "makemigrations", "--check", "--dry-run", stdout=output, stderr=output + ) + except SystemExit as e: + # Capture the SystemExit if migrations are needed (the command will had ended with exit code 1) + exec = e + + # If an exception was raised, verify it indicates no migration changes are required + if exec is not None: + self.assertEqual( + exec.code, + 0, # 0 means no migrations needed + f"Model changes detected that require migrations!\n" + f"Please run `python manage.py makemigrations` to create the necessary migrations.\n\n" + f"Detected Changes:\n{output.getvalue()}", + )