Esempio n. 1
0
    def testModelFormInSecondaryLanguage(self):
        translation.activate('fr')
        form = BarForm()
        # When we are in French name and description point to French fields (not the English)
        # name_fr and description_fr are actually redundant
        # But we want name_fr and description_fr to take precedence over name and description
        data = {'name': 'Test', 'name_fr': 'French Test', 'price': 13,
            'quantity': 3, 'description': 'This is a test', 'description_fr': 'French Description',
        }
        form = BarForm(data=data)

        # These translations are not meant to be correct it is solely for the purpose of testing
        self.assertEqual(unicode(form['name'].label), u'Neom')
        self.assertEqual(unicode(form['name_fr'].label), u'Neom (Français)')
        self.assertEqual(unicode(form['description'].label), u'Description')  # This does not get translated because Django generates the verbose_name as a string
        self.assertEqual(unicode(form['description_fr'].label), u'Déscriptione (Français)')
        bar = form.save()

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

        translation.activate('fr')
        self.assertEqual(bar.name, 'French Test')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, 'French Description')
Esempio n. 2
0
 def testModelForm(self):
     form = BarForm()
     self.assertEqual(len(form.fields), 7)
     self.assertTrue('name' in form.fields)
     self.assertTrue('name_fr' in form.fields)
     self.assertTrue('price' in form.fields)
     self.assertTrue('categories' in form.fields)
     self.assertTrue('quantity' in form.fields)
     self.assertTrue('description' in form.fields)
     self.assertTrue('description_fr' in form.fields)
     
     data = {'name': 'Test', 'name_fr': 'French Test', 'price': 13,
         'quantity': 3, 'description': 'This is a test', 'description_fr': 'French Description',
     }
     form = BarForm(data=data)
     self.assertEqual(unicode(form['name'].label), u'Name')
     self.assertEqual(unicode(form['name_fr'].label), u'Name (French)')
     self.assertEqual(unicode(form['description'].label), u'Description')
     self.assertEqual(unicode(form['description_fr'].label), u'Description (French)')
     bar = form.save()
     self.assertEqual(bar._language, 'en')
     self.assertEqual(bar.name, 'Test')
     self.assertEqual(bar.price, 13)
     self.assertEqual(bar.quantity, 3)
     self.assertEqual(bar.description, 'This is a test')
     bar_fr = bar.get_translation('fr')
     self.assertEqual(bar_fr._language, 'fr')
     self.assertEqual(bar_fr.name, 'French Test')
     self.assertEqual(bar_fr.price, 13)
     self.assertEqual(bar_fr.quantity, 3)
     self.assertEqual(bar_fr.description, 'French Description')
     
     # Create the form with an instance
     data2 = {'name': 'Changed', 'name_fr': 'Changed French', 'price': 43,
         'quantity': 22, 'description': 'Changed description',
         'description_fr': 'Changed description French'
     }
     form = BarForm(instance=bar, data=data2)
     bar = form.save()
     self.assertEqual(bar._language, 'en')
     self.assertEqual(bar.name, 'Changed')
     self.assertEqual(bar.price, 43)
     self.assertEqual(bar.quantity, 22)
     self.assertEqual(bar.description, 'Changed description')
     bar_fr = bar.get_translation('fr')
     self.assertEqual(bar_fr._language, 'fr')
     self.assertEqual(bar_fr.name, 'Changed French')
     self.assertEqual(bar_fr.price, 43)
     self.assertEqual(bar_fr.quantity, 22)
     self.assertEqual(bar_fr.description, 'Changed description French')
Esempio n. 3
0
    def testModelForm(self):
        form = BarForm()
        self.assertEqual(len(form.fields), 7)
        self.assertTrue('name' in form.fields)
        self.assertTrue('name_fr' in form.fields)
        self.assertTrue('price' in form.fields)
        self.assertTrue('categories' in form.fields)
        self.assertTrue('quantity' in form.fields)
        self.assertTrue('description' in form.fields)
        self.assertTrue('description_fr' in form.fields)

        data = {'name': 'Test', 'name_fr': 'French Test', 'price': 13,
            'quantity': 3, 'description': 'This is a test', 'description_fr': 'French Description',
        }
        form = BarForm(data=data)
        self.assertEqual(unicode(form['name'].label), u'Name')
        self.assertEqual(unicode(form['name_fr'].label), u'Name (French)')
        self.assertEqual(unicode(form['description'].label), u'Description')
        self.assertEqual(unicode(form['description_fr'].label), u'Description (French)')
        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, 'French Test')
        self.assertEqual(bar.price, 13)
        self.assertEqual(bar.quantity, 3)
        self.assertEqual(bar.description, 'French Description')

        translation.activate('en')
        # Create the form with an instance
        data2 = {'name': 'Changed', 'name_fr': 'Changed French', 'price': 43,
            'quantity': 22, 'description': 'Changed description',
            'description_fr': 'Changed description French'
        }
        form = BarForm(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, 'Changed French')
        self.assertEqual(bar.price, 43)
        self.assertEqual(bar.quantity, 22)
        self.assertEqual(bar.description, 'Changed description French')