jeudi 24 mai 2018

Django : Migration translation not loaded (test)

Here is my test class :

class FrontTest(LiveServerTestCase):

    serialized_rollback=True
    fixtures = ['event.json']

The keywork "serialized_rollback=True" will apply migrations for each test case.

My class is loading a fixture, here it is :

{
   "model": "mezzanine_agenda.event",
   "pk": 5,
   "fields": {
      "comments_count": 0,
      "keywords_string": "",
      "rating_count": 0,
      "rating_sum": 0,
      "rating_average": 0.0,
      "site": 1,
      "title": "event search",
      "title_fr": "event search",
      "title_en": "",
      "slug": "event-search",
      "_meta_title": "",
      "description": "event search",
      "description_fr": "event search",
      "description_en": "event search",
      "gen_description": true,
      "created": "2018-05-22T09:49:07.515Z",
      "updated": "2018-05-24T07:58:24.273Z",
      "status": 2,
      "publish_date": "2018-05-22T09:49:07Z",
      "expiry_date": "2018-05-23T13:31:31Z",
      "short_url": "unset",
      "in_sitemap": true,
      "content": "",
      "content_fr": "",
      "content_en": "",
      "user": [
         "admin"
      ],
      "sub_title": "",
      "sub_title_fr": "",
      "sub_title_en": "",
      "parent": null,
      "category": null,
      "start": "2018-05-22T09:49:04Z",
      "end": "2018-05-23T13:32:18Z",
      "date_text": "",
      "location": null,
      "facebook_event": null,
      "shop": null,
      "external_id": null,
      "is_full": false,
      "brochure": "",
      "no_price_comments": null,
      "no_price_comments_fr": null,
      "no_price_comments_en": null,
      "mentions": "",
      "mentions_fr": "",
      "mentions_en": "",
      "allow_comments": false,
      "rank": null,
      "prices": []
   }
}

And i've a migration which defines the event model :

class Migration(migrations.Migration):

    initial = True
    print('OK') # Testing if migration is really called
    dependencies = [
        ('sites', '0002_alter_domain_unique'),
        ('blog', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Event',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('comments_count', models.IntegerField(default=0, editable=False)),
                ('keywords_string', models.CharField(blank=True, editable=False, max_length=500)),
                ('rating_count', models.IntegerField(default=0, editable=False)),
                ('rating_sum', models.IntegerField(default=0, editable=False)),
                ('rating_average', models.FloatField(default=0, editable=False)),
                ('title', models.CharField(max_length=500, verbose_name='Title')),
                ('title_fr', models.CharField(max_length=500, null=True, verbose_name='Title')),
                ('title_en', models.CharField(max_length=500, null=True, verbose_name='Title')),
                ('slug', models.CharField(blank=True, help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL')),
                ('_meta_title', models.CharField(blank=True, help_text='Optional title to be used in the HTML title tag. If left blank, the main title field will be used.', max_length=500, null=True, verbose_name='Title')),
                ('description', models.TextField(blank=True, verbose_name='Description')),
                ('description_fr', models.TextField(blank=True, null=True, verbose_name='Description')),
                ('description_en', models.TextField(blank=True, null=True, verbose_name='Description')),
                ('gen_description', models.BooleanField(default=True, help_text='If checked, the description will be automatically generated from content. Uncheck if you want to manually set a custom description.', verbose_name='Generate description')),
                ('created', models.DateTimeField(editable=False, null=True)),
                ('updated', models.DateTimeField(editable=False, null=True)),
                ('status', models.IntegerField(choices=[(1, 'Draft'), (2, 'Published')], default=2, help_text='With Draft chosen, will only be shown for admin users on the site.', verbose_name='Status')),
                ('publish_date', models.DateTimeField(blank=True, db_index=True, help_text="With Published chosen, won't be shown until this time", null=True, verbose_name='Published from')),
                ('expiry_date', models.DateTimeField(blank=True, help_text="With Published chosen, won't be shown after this time", null=True, verbose_name='Expires on')),
                ('short_url', models.URLField(blank=True, null=True)),
                ('in_sitemap', models.BooleanField(default=True, verbose_name='Show in sitemap')),
                ('content', mezzanine.core.fields.RichTextField(verbose_name='Content')),
                ('content_fr', mezzanine.core.fields.RichTextField(null=True, verbose_name='Content')),
                ('content_en', mezzanine.core.fields.RichTextField(null=True, verbose_name='Content')),
                ('start', models.DateTimeField(verbose_name='Start')),
                ('end', models.DateTimeField(blank=True, null=True, verbose_name='End')),
                ('facebook_event', models.BigIntegerField(blank=True, null=True, verbose_name='Facebook')),
                ('allow_comments', models.BooleanField(default=False, verbose_name='Allow comments')),
                ('featured_image', mezzanine.core.fields.FileField(blank=True, max_length=255, null=True, verbose_name='Featured Image')),
                ('featured_image_description', models.TextField(blank=True, verbose_name='featured image description')),
                ('featured_image_header', mezzanine.core.fields.FileField(blank=True, max_length=1024, verbose_name='featured image header')),
                ('external_id', models.IntegerField(blank=True, null=True, verbose_name='external_id')),
                ('brochure', mezzanine.core.fields.FileField(blank=True, max_length=1024, verbose_name='brochure')),
                ('blog_posts', models.ManyToManyField(blank=True, related_name='events', to='blog.BlogPost', verbose_name='blog posts')),
            ],

And finally, when i run any test case from FrontTest() :

OK
django.core.serializers.base.DeserializationError: Problem installing fixture '/srv/lib/mezzanine-organization/organization/agenda/fixtures/event.json': Event has no field named 'title_fr'

Do you know why this error occured ? BTW, i'm using django translation

Aucun commentaire:

Enregistrer un commentaire