Skip to content

fix: add missing migration for token_blacklist app #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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",
},
),
]
42 changes: 42 additions & 0 deletions tests/test_migrations.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution, thank you!

Original file line number Diff line number Diff line change
@@ -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()}",
)
Loading