def test_transinput(self): models.Translation.objects.create( id=666, locale='en-us', localized_string='test value en') models.Translation.objects.create( id=666, locale='fr', localized_string='test value fr') models.Translation.objects.create( id=666, locale='de', localized_string=None) widget = widgets.TransInput() assert not widget.is_hidden doc = pq(widget.render('foo', 666)) assert doc.attr('id') == 'trans-foo' assert doc.attr('class') == 'trans' assert doc.attr('data-name') == 'foo' assert len(doc('input')) == 3 assert doc('input')[0].get('lang') == 'en-us' assert doc('input')[0].get('name') == 'foo_en-us' assert doc('input')[1].get('lang') == 'fr' assert doc('input')[1].get('name') == 'foo_fr' assert doc('input')[2].get('lang') == 'init' assert doc('input')[2].get('name') == 'foo_init'
def test_transinput_renders_attrs(self): models.Translation.objects.create( id=666, locale='en-us', localized_string='test value en' ) widget = widgets.TransInput(attrs={'rows': 5, 'cols': 20}) doc = pq(widget.render('foo', 666)) assert doc('input')[0].get('rows') == '5' assert doc('input')[0].get('cols') == '20'
def test_value_from_datadict(self): data = {'f_en-US': 'woo', 'f_de': 'herr', 'f_fr_delete': ''} actual = widgets.TransInput().value_from_datadict(data, [], 'f') expected = {'en-US': 'woo', 'de': 'herr', 'fr': None} assert actual == expected