

def test_instance_cache_has_changed(self):
    self.instance.activate_language('en')
    self.instance.title = 'Hello'
    self.instance.activate_language('fr')
    self.instance.title = 'Bonjour'
    self.instance.save()
    with self.assertNumQueries(1):
        self.instance.save()
    instance = FooModel.objects.get(pk=self.instance.pk)
    instance.activate_language('en')
    instance.title_en = 'Hi'
    instance.title_fr = 'Salut'
    with self.assertNumQueries(3):
        instance.save()
    self.assertEqual(instance.title, 'Hi')
    self.assertEqual(instance.title_en, 'Hi')
    self.assertEqual(instance.title_fr, 'Salut')
    instance = FooModel.objects.get(pk=self.instance.pk)
    instance.activate_language('en')
    self.assertEqual(instance.title, 'Hi')
    self.assertEqual(instance.title_en, 'Hi')
    self.assertEqual(instance.title_fr, 'Salut')
    instance = FooModel.objects.get(pk=self.instance.pk)
    instance.activate_language('en')
    instance.title = 'Howdy'
    with self.assertNumQueries(2):
        instance.save()
    self.assertEqual(instance.title_en, 'Howdy')
    self.assertEqual(instance.title_fr, 'Salut')
    instance.activate_language('en')
    instance.title = 'Plop'
    with self.assertNumQueries(2):
        instance.save()
    self.assertEqual(instance.title, 'Plop')
    self.assertEqual(instance.title_en, 'Plop')
    self.assertEqual(instance.title_fr, 'Salut')
    instance = FooModel.objects.get(pk=self.instance.pk)
    instance.activate_language('en')
    self.assertEqual(instance.title, 'Plop')
    self.assertEqual(instance.title_en, 'Plop')
    self.assertEqual(instance.title_fr, 'Salut')

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