Skip to content

Commit

Permalink
test models with DJANGO_CELERY_BEAT_NAME_MAX_LENGTH=191 in own proces…
Browse files Browse the repository at this point in the history
…s; pep8
  • Loading branch information
tuky authored and milind-shakya-sp committed Mar 4, 2019
1 parent 88a32e8 commit 74324f1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
32 changes: 28 additions & 4 deletions t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 74324f1

Please sign in to comment.