

def test_new_instance_cache(self):
    self.instance.activate_language('en')
    self.instance.title = 'Hello'
    self.assertTrue(self.instance._linguist.translations['title']['en'])
    cached_obj = self.instance._linguist.translations['title']['en']
    self.assertEqual(cached_obj.language, 'en')
    self.assertIsNone(cached_obj.object_id)
    self.assertEqual(cached_obj.field_value, 'Hello')
    self.assertEqual(cached_obj.is_new, True)
    self.assertEqual(cached_obj.identifier, 'foo')
    self.assertEqual(cached_obj.field_name, 'title')
    self.instance.activate_language('fr')
    self.instance.title = 'Bonjour'
    self.assertEqual(self.instance.cached_translations_count, 2)
    self.assertTrue(self.instance._linguist.translations['title']['fr'])
    cached_obj = self.instance._linguist.translations['title']['fr']
    self.assertEqual(cached_obj.language, 'fr')
    self.assertIsNone(cached_obj.object_id)
    self.assertEqual(cached_obj.field_value, 'Bonjour')
    self.assertEqual(cached_obj.is_new, True)
    self.assertEqual(cached_obj.identifier, 'foo')
    self.assertEqual(cached_obj.field_name, 'title')

dataset/ETHPy150Open ulule/django-linguist/linguist/tests/test_model_mixin.py ModelMixinTest.test_new_instance_cache/original