def test_choices_addon(self): # No add-on passed, all choices are present. form = forms.DistributionChoiceForm() assert len(form.fields['channel'].choices) == 2 assert form.fields['channel'].choices[0][0] == 'listed' assert form.fields['channel'].choices[1][0] == 'unlisted' # Regular add-on, all choices are present. addon = addon_factory() form = forms.DistributionChoiceForm(addon=addon) assert len(form.fields['channel'].choices) == 2 assert form.fields['channel'].choices[0][0] == 'listed' assert form.fields['channel'].choices[1][0] == 'unlisted' # "Invisible" addons don't get to choose "On this site.". addon.disabled_by_user = True form = forms.DistributionChoiceForm(addon=addon) assert len(form.fields['channel'].choices) == 1 assert form.fields['channel'].choices[0][0] == 'unlisted' # Back to normal. addon.disabled_by_user = False form = forms.DistributionChoiceForm(addon=addon) assert len(form.fields['channel'].choices) == 2 assert form.fields['channel'].choices[0][0] == 'listed' assert form.fields['channel'].choices[1][0] == 'unlisted'
def test_lazy_choice_labels(self): """Tests that the labels in `choices` are still lazy We had a problem that the labels weren't properly marked as lazy which led to labels being returned in mixed languages depending on what server we hit in production. """ with translation.override('en-US'): form = forms.DistributionChoiceForm() label = form.fields['channel'].choices[0][1] expected = 'On this site.' label = str(label) assert label.startswith(expected) with translation.override('fr'): form = forms.DistributionChoiceForm() label = form.fields['channel'].choices[0][1] expected = 'Gestion via le site.' label = str(label) assert label.startswith(expected)