diff --git a/t/unit/test_models.py b/t/unit/test_models.py index 94fb0fa9..98f5c08a 100644 --- a/t/unit/test_models.py +++ b/t/unit/test_models.py @@ -2,19 +2,43 @@ import importlib -from django.test import TestCase +from django.test import TestCase, override_settings +from django.utils import six -from django_celery_beat.models import PeriodicTask +from django_celery_beat import models class ModelMigrationTests(TestCase): def test_periodic_task_name_max_length_defaults_to_200_in_model(self): - self.assertEqual(200, PeriodicTask._meta.get_field('name').max_length) + six.moves.reload_module(models) + self.assertEqual( + 200, models.PeriodicTask._meta.get_field('name').max_length) + + @override_settings(DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191) + def test_periodic_task_name_max_length_changed_to_191_in_model(self): + six.moves.reload_module(models) + self.assertEqual( + 191, models.PeriodicTask._meta.get_field('name').max_length) def test_periodic_task_name_max_length_defaults_to_200_in_migration(self): - initial_migration = importlib.import_module('django_celery_beat.migrations.0001_initial').Migration + initial_migration_module = importlib.import_module( + 'django_celery_beat.migrations.0001_initial') + six.moves.reload_module(initial_migration_module) + initial_migration = initial_migration_module.Migration periodic_task_creation = initial_migration.operations[2] fields = dict(periodic_task_creation.fields) self.assertEqual('PeriodicTask', periodic_task_creation.name) self.assertEqual(200, fields['name'].max_length) + + @override_settings(DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191) + def test_periodic_task_name_max_length_changed_to_191_in_migration(self): + initial_migration_module = importlib.import_module( + 'django_celery_beat.migrations.0001_initial') + six.moves.reload_module(initial_migration_module) + initial_migration = initial_migration_module.Migration + periodic_task_creation = initial_migration.operations[2] + fields = dict(periodic_task_creation.fields) + + self.assertEqual('PeriodicTask', periodic_task_creation.name) + self.assertEqual(191, fields['name'].max_length) diff --git a/tox.ini b/tox.ini index d301bdf5..48bbface 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,11 @@ recreate = False commands = pip install -U https://github.com/celery/celery/zipball/master#egg=celery pip install -U https://github.com/celery/kombu/zipball/master#egg=kombu - py.test -xv + py.test -xv --ignore=t/unit/test_models.py + +[testenv:models] +commands = + py.test -xv -k 'ModelMigrationTests' [testenv:apicheck] basepython = python3.5 @@ -70,4 +74,4 @@ usedevelop = true commands = pip install -U https://github.com/celery/celery/zipball/master#egg=celery pip install -U https://github.com/celery/kombu/zipball/master#egg=kombu - py.test -x --cov=django_celery_beat --cov-report=xml --no-cov-on-fail + py.test -x --cov=django_celery_beat --cov-report=xml --no-cov-on-fail --ignore=t/unit/test_models.py