-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.test import TestCase | ||
from django.forms import ModelForm | ||
from django.test import TestCase | ||
from django.utils.translation import override | ||
|
||
from .app.models import Blog | ||
|
||
|
||
class ModelFormTest(TestCase): | ||
def test_modelform(self): | ||
class BlogForm(ModelForm): | ||
class Meta: | ||
model = Blog | ||
fields = ('title_i18n', 'body_i18n', ) | ||
|
||
article = Blog(title='English', title_nl='Nederlands') | ||
|
||
from modeltrans.migration import I18nDataMigration, I18nIndexMigration, get_translatable_models | ||
with override('nl'): | ||
form = BlogForm(instance=article, data={ | ||
'title_i18n': 'Nederlandse taal', | ||
'body_i18n': 'foo' | ||
}) | ||
form.save() | ||
|
||
from .app.models import Blog, Category | ||
article.refresh_from_db() | ||
self.assertEqual(article.title_nl, 'Nederlandse taal') | ||
self.assertEqual(article.title_en, 'English') | ||
|
||
with override('en'): | ||
form = BlogForm(instance=article, data={ | ||
'title_i18n': 'English language', | ||
'body_i18n': 'foo' | ||
}) | ||
form.save() | ||
|
||
# class ModelFormTest(TestCase): | ||
# def test_modelform(self): | ||
# | ||
# class BlogForm(ModelForm): | ||
# class Meta: | ||
# model = Blog | ||
# fields = ('title_i18n', 'body_i18n', ) | ||
article.refresh_from_db() | ||
self.assertEqual(article.title_nl, 'Nederlandse taal') | ||
self.assertEqual(article.title_en, 'English language') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters