Esempio n. 1
0
 def testModelFormWithFieldsSpecifiedInSecondaryLanguage(self):
     translation.activate('fr')
     form = BarFormWithFieldsSpecified()
     self.assertEqual(len(form.fields), 4)
     self.assertTrue('name' in form.fields)
     self.assertTrue('price' in form.fields)
     self.assertTrue('quantity' in form.fields)
     self.assertTrue('description' in form.fields)
     
     data = {'name': 'Test French', 'price': 13,
         'quantity': 3, 'description': 'This is a French test',
     }
     form = BarFormWithFieldsSpecified(data=data)
     bar_fr = form.save()
     self.assertEqual(bar_fr._language, 'fr')
     self.assertEqual(bar_fr.name, 'Test French')
     self.assertEqual(bar_fr.price, 13)
     self.assertEqual(bar_fr.quantity, 3)
     self.assertEqual(bar_fr.description, 'This is a French test')
     bar_en = bar_fr.get_translation('en')
     self.assertEqual(bar_en._language, 'en')
     self.assertEqual(bar_en.name, '')
     self.assertEqual(bar_en.price, 13)
     self.assertEqual(bar_en.quantity, 3)
     self.assertEqual(bar_en.description, '')
     
     # Create the form with an instance
     data2 = {'name': 'Changed', 'price': 43,
         'quantity': 22, 'description': 'Changed description',
     }
     form = BarFormWithFieldsSpecified(instance=bar_fr, data=data2)
     bar_fr = form.save()
     self.assertEqual(bar_fr._language, 'fr')
     self.assertEqual(bar_fr.name, 'Changed')
     self.assertEqual(bar_fr.price, 43)
     self.assertEqual(bar_fr.quantity, 22)
     self.assertEqual(bar_fr.description, 'Changed description')
     bar_en = bar_fr.get_translation('en')
     self.assertEqual(bar_en._language, 'en')
     self.assertEqual(bar_en.name, '')
     self.assertEqual(bar_en.price, 43)
     self.assertEqual(bar_en.quantity, 22)
     self.assertEqual(bar_en.description, '')
Esempio n. 2
0
    def testModelFormWithFieldsSpecified(self):
        form = BarFormWithFieldsSpecified()
        self.assertEqual(len(form.fields), 4)
        self.assertTrue('name' in form.fields)
        self.assertTrue('price' in form.fields)
        self.assertTrue('quantity' in form.fields)
        self.assertTrue('description' in form.fields)

        data = {'name': 'Test', 'price': 13,
            'quantity': 3, 'description': 'This is a test',
        }
        form = BarFormWithFieldsSpecified(data=data)
        bar = form.save()
        self.assertEqual(bar.name, 'Test')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, 'This is a test')

        translation.activate('fr')
        self.assertEqual(bar.name, '')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, '')

        translation.activate('en')
        # Create the form with an instance
        data2 = {'name': 'Changed', 'price': 43,
            'quantity': 22, 'description': 'Changed description',
        }
        form = BarFormWithFieldsSpecified(instance=bar, data=data2)
        bar = form.save()
        self.assertEqual(bar.name, 'Changed')
        self.assertEqual(bar.price, 43)
        self.assertEqual(bar.quantity, 22)
        self.assertEqual(bar.description, 'Changed description')

        translation.activate('fr')
        self.assertEqual(bar.name, '')
        self.assertEqual(bar.price, 43)
        self.assertEqual(bar.quantity, 22)
        self.assertEqual(bar.description, '')
Esempio n. 3
0
    def testModelFormWithFieldsSpecifiedInSecondaryLanguage(self):
        translation.activate('fr')
        form = BarFormWithFieldsSpecified()
        self.assertEqual(len(form.fields), 4)
        self.assertTrue('name' in form.fields)
        self.assertTrue('price' in form.fields)
        self.assertTrue('quantity' in form.fields)
        self.assertTrue('description' in form.fields)

        data = {'name': 'Test French', 'price': 13,
            'quantity': 3, 'description': 'This is a French test',
        }
        form = BarFormWithFieldsSpecified(data=data)
        bar = form.save()
        self.assertEqual(bar.name, 'Test French')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, 'This is a French test')

        translation.activate('en')
        self.assertEqual(bar.name, '')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, '')

        translation.activate('fr')
        # Create the form with an instance
        data2 = {'name': 'Changed', 'price': 43,
            'quantity': 22, 'description': 'Changed description',
        }
        form = BarFormWithFieldsSpecified(instance=bar, data=data2)
        bar = form.save()
        self.assertEqual(bar.name, 'Changed')
        self.assertEqual(bar.price, 43)
        self.assertEqual(bar.quantity, 22)
        self.assertEqual(bar.description, 'Changed description')

        translation.activate('en')
        self.assertEqual(bar.name, '')
        self.assertEqual(bar.price, 43)
        self.assertEqual(bar.quantity, 22)
        self.assertEqual(bar.description, '')