예제 #1
0
 def test_create_instance_translated_nolang(self):
     with translation.override('en'):
         obj = Normal(language_code='en', translated_field="English")
         obj.save()
         en = Normal.objects.language('en').get(pk=obj.pk)
         self.assertEqual(en.translated_field, "English")
         self.assertEqual(en.language_code, "en")
예제 #2
0
 def test_create_instance_shared_nolang(self):
     with LanguageOverride('en'):
         obj = Normal(language_code='en', shared_field="shared")
         obj.save()
         en = Normal.objects.language('en').get(pk=obj.pk)
         self.assertEqual(en.shared_field, "shared")
         self.assertEqual(en.language_code, "en")
예제 #3
0
파일: fixtures.py 프로젝트: jqb/django-hvad
 def create_normal(self, data, translations=None):
     obj = Normal(shared_field=data.shared_field)
     for code in translations or self.translations:
         obj.translate(code)
         obj.translated_field = data.translated_field[code]
         obj.save()
     return obj
예제 #4
0
파일: basic.py 프로젝트: kohout/django-hvad
 def test_create_instance_translated_nolang(self):
     with LanguageOverride('en'):
         obj = Normal(language_code='en', translated_field = "English")
         obj.save()
         en = Normal.objects.language('en').get(pk=obj.pk)
         self.assertEqual(en.translated_field, "English")
         self.assertEqual(en.language_code, "en")
예제 #5
0
 def test_create_instance_shared_nolang(self):
     with translation.override('en'):
         obj = Normal(language_code='en', shared_field = "shared")
         obj.save()
         en = Normal.objects.language('en').get(pk=obj.pk)
         self.assertEqual(en.shared_field, "shared")
         self.assertEqual(en.language_code, "en")
예제 #6
0
 def create_normal(self, data, translations=None):
     obj = Normal(shared_field=data.shared_field)
     for code in translations or self.translations:
         obj.translate(code)
         obj.translated_field = data.translated_field[code]
         obj.save()
     return obj
예제 #7
0
 def test_create_instance_shared_nolang(self):
     with LanguageOverride("en"):
         obj = Normal(language_code="en", shared_field="shared")
         obj.save()
         en = Normal.objects.language("en").get(pk=obj.pk)
         self.assertEqual(en.shared_field, "shared")
         self.assertEqual(en.language_code, "en")
예제 #8
0
 def test_create_instance_both(self):
     obj = Normal(language_code="en", shared_field="shared", translated_field="English")
     obj.save()
     en = Normal.objects.language("en").get(pk=obj.pk)
     self.assertEqual(en.shared_field, "shared")
     self.assertEqual(en.translated_field, "English")
     self.assertEqual(en.language_code, "en")
예제 #9
0
 def test_filtered_get(self):
     obj = Normal(shared_field='field_1')
     obj.translate('en')
     obj.translated_field = 'field_2'
     obj.save()
     qs = Normal.objects.language('en') | Normal.objects.language('de')
     found = qs.filter(shared_field='field_1').get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
예제 #10
0
파일: basic.py 프로젝트: kohout/django-hvad
 def test_filtered_get(self):
     obj = Normal(shared_field='field_1')
     obj.translate('en')
     obj.translated_field = 'field_2'
     obj.save()
     qs = Normal.objects.language('en') | Normal.objects.language('de')
     found = qs.filter(shared_field='field_1').get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
예제 #11
0
 def test_create_instance_both(self):
     obj = Normal(language_code='en', shared_field = "shared",
                  translated_field = "English")
     obj.save()
     en = Normal.objects.language('en').get(pk=obj.pk)
     self.assertEqual(en.shared_field, "shared")
     self.assertEqual(en.translated_field, "English")
     self.assertEqual(en.language_code, "en")
예제 #12
0
 def test_filtered_get(self):
     obj = Normal(shared_field="field_1")
     obj.translate("en")
     obj.translated_field = "field_2"
     obj.save()
     qs = Normal.objects.language("en") | Normal.objects.language("de")
     found = qs.filter(shared_field="field_1").get(pk=obj.pk)
     self.assertEqual(found.pk, obj.pk)
예제 #13
0
파일: basic.py 프로젝트: kohout/django-hvad
 def test_create_instance_simple(self):
     obj = Normal(language_code='en')
     obj.shared_field = "shared"
     obj.translated_field = "English"
     obj.save()
     en = Normal.objects.language('en').get(pk=obj.pk)
     self.assertEqual(en.shared_field, "shared")
     self.assertEqual(en.translated_field, "English")
     self.assertEqual(en.language_code, "en")
예제 #14
0
    def test_translated_foreignkey_set(self):
        cache = Related._meta.translations_cache

        normal = Normal(language_code='en')
        normal.save()
        related = Related(language_code='en')
        related.translated = normal
        self.assertNotIn('translated_id', related.__dict__)
        self.assertIn('translated_id', getattr(related, cache).__dict__)
        self.assertEqual(getattr(related, cache).__dict__['translated_id'], normal.pk)

        related.translated_id = 4242
        self.assertNotIn('translated_id', related.__dict__)
        self.assertIn('translated_id', getattr(related, cache).__dict__)
        self.assertEqual(getattr(related, cache).__dict__['translated_id'], 4242)