def test_set_standard_field_with_single_lang(self): form_mixin = AttributeFormMixin() form_mixin.project = self.project form_mixin.fields = { 'building': ChoiceField(choices=(('barn', 'Barn'), ('house', 'House'))) } questionnaire = q_factories.QuestionnaireFactory(project=self.project) question = q_factories.QuestionFactory.create( type='S1', name='building', questionnaire=questionnaire, label='Name') q_factories.QuestionOptionFactory(question=question, name='barn', label='Barn', index=0) q_factories.QuestionOptionFactory(question=question, name='house', label='House', index=1) form_mixin.set_standard_field('building', empty_choice='Select house type') widget = form_mixin.fields['building'].widget assert isinstance(widget, XLangSelect) is True assert widget.choices == [('', 'Select house type'), ('barn', 'Barn'), ('house', 'House')] assert widget.xlang_labels == {}
def test_set_standard_field_with_options(self): form_mixin = AttributeFormMixin() form_mixin.project = self.project form_mixin.fields = { 'building': ChoiceField(choices=(('barn', 'Barn'), ('house', 'House'))) } questionnaire = q_factories.QuestionnaireFactory(project=self.project, default_language='de') question = q_factories.QuestionFactory.create( type='S1', name='building', questionnaire=questionnaire, label={ 'en': 'Name', 'de': 'Name' }) q_factories.QuestionOptionFactory(question=question, name='barn', label={ 'de': 'Scheune', 'en': 'Barn' }, index=0) q_factories.QuestionOptionFactory(question=question, name='house', label={ 'de': 'Haus', 'en': 'Haus' }, index=1) form_mixin.set_standard_field('building') widget = form_mixin.fields['building'].widget assert isinstance(widget, XLangSelect) is True assert widget.choices == [('barn', 'Scheune'), ('house', 'Haus')] assert widget.xlang_labels == { 'barn': { 'de': 'Scheune', 'en': 'Barn' }, 'house': { 'de': 'Haus', 'en': 'Haus' } }