|
2 | 2 |
|
3 | 3 | import importlib
|
4 | 4 |
|
5 |
| -from django.test import TestCase |
| 5 | +from django.test import TestCase, override_settings |
| 6 | +from django.utils import six |
6 | 7 |
|
7 |
| -from django_celery_beat.models import PeriodicTask |
| 8 | +from django_celery_beat import models |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class ModelMigrationTests(TestCase):
|
11 | 12 | def test_periodic_task_name_max_length_defaults_to_200_in_model(self):
|
12 |
| - self.assertEqual(200, PeriodicTask._meta.get_field('name').max_length) |
| 13 | + six.moves.reload_module(models) |
| 14 | + self.assertEqual( |
| 15 | + 200, models.PeriodicTask._meta.get_field('name').max_length) |
| 16 | + |
| 17 | + @override_settings(DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191) |
| 18 | + def test_periodic_task_name_max_length_changed_to_191_in_model(self): |
| 19 | + six.moves.reload_module(models) |
| 20 | + self.assertEqual( |
| 21 | + 191, models.PeriodicTask._meta.get_field('name').max_length) |
13 | 22 |
|
14 | 23 | def test_periodic_task_name_max_length_defaults_to_200_in_migration(self):
|
15 |
| - initial_migration = importlib.import_module('django_celery_beat.migrations.0001_initial').Migration |
| 24 | + initial_migration_module = importlib.import_module( |
| 25 | + 'django_celery_beat.migrations.0001_initial') |
| 26 | + six.moves.reload_module(initial_migration_module) |
| 27 | + initial_migration = initial_migration_module.Migration |
16 | 28 | periodic_task_creation = initial_migration.operations[2]
|
17 | 29 | fields = dict(periodic_task_creation.fields)
|
18 | 30 |
|
19 | 31 | self.assertEqual('PeriodicTask', periodic_task_creation.name)
|
20 | 32 | self.assertEqual(200, fields['name'].max_length)
|
| 33 | + |
| 34 | + @override_settings(DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191) |
| 35 | + def test_periodic_task_name_max_length_changed_to_191_in_migration(self): |
| 36 | + initial_migration_module = importlib.import_module( |
| 37 | + 'django_celery_beat.migrations.0001_initial') |
| 38 | + six.moves.reload_module(initial_migration_module) |
| 39 | + initial_migration = initial_migration_module.Migration |
| 40 | + periodic_task_creation = initial_migration.operations[2] |
| 41 | + fields = dict(periodic_task_creation.fields) |
| 42 | + |
| 43 | + self.assertEqual('PeriodicTask', periodic_task_creation.name) |
| 44 | + self.assertEqual(191, fields['name'].max_length) |
0 commit comments