def test_show_legend_as_heading(): """Verify the field legend can be displayed as the page heading.""" form = CheckboxesForm() form.helper = FormHelper() form.helper.layout = Layout(Field("method", context={"legend_tag": "h1"})) assert parse_form(form) == parse_contents(RESULT_DIR, "legend_heading.html")
def test_change_legend_size(): """Verify size of the field legend can be changed from the default.""" form = CheckboxesForm() form.helper = FormHelper() form.helper.layout = Layout( Field("method", context={"legend_size": Size.for_legend("l")})) assert parse_form(form) == parse_contents(RESULT_DIR, "legend_size.html")
def test_change_legend_size(): """Verify size of the field legend can be changed from the default.""" form = FieldsetForm() form.helper = FormHelper() form.helper.layout = Layout( Fieldset("name", "email", legend="Contact", legend_size=Size.LARGE)) assert parse_form(form) == parse_contents(RESULT_DIR, "legend_size.html")
def test_section_attributes(): """Verify extra attributes can be added to an accordion section.""" form = AccordionForm() form.helper.layout = Layout( Accordion(AccordionSection("Title", HTML("Contents"), key="value"))) assert parse_form(form) == parse_contents(RESULT_DIR, "section_attributes.html")
def test_change_label_size(): """Verify size of the field label can be changed from the default.""" form = FileUploadForm() form.helper = FormHelper() form.helper.layout = Layout( Field("file", context={"label_size": Size.for_label("l")})) assert parse_form(form) == parse_contents(RESULT_DIR, "label_size.html")
def test_threshold(): """Verify info is shown after a certain number of words has been entered.""" form = TextareaForm(initial={"description": "Field value"}) form.helper = FormHelper() form.helper.layout = Layout( Field.textarea("description", max_words=100, threshold=50)) assert parse_form(form) == parse_contents(RESULT_DIR, "threshold.html")
def test_small(): """Verify size of the radio buttons can be changed.""" form = RadiosForm() form.helper = FormHelper() form.helper.layout = Layout(Field("method", context={"radios_small": True})) assert parse_form(form) == parse_contents(RESULT_DIR, "buttons_small.html")
def test_show_label_as_heading(): """Verify the field label can be displayed as the page heading.""" form = TextareaForm() form.helper = FormHelper() form.helper.layout = Layout( Field("description", context={"label_tag": "h1"})) assert parse_form(form) == parse_contents(RESULT_DIR, "label_heading.html")
def test_checkbox_size(): """Verify size of the checkbox can be changed from the default.""" form = CheckboxForm() form.helper = FormHelper() form.helper.layout = Layout( Field("accept", context={"checkboxes_small": True})) assert parse_form(form) == parse_contents(RESULT_DIR, "checkbox_size.html")
def test_no_help_text_errors(): """Verify all the gds error attributes are displayed if no help text is given.""" form = TextInputForm(data={"name": ""}) form.fields["name"].help_text = "" assert not form.is_valid() assert parse_form(form) == parse_contents(RESULT_DIR, "no_help_text_errors.html")
def test_override_default_label_size(): """Verify a default label size can be overridden on the field.""" form = TextInputForm() form.helper = FormHelper() form.helper.label_size = Size.MEDIUM form.helper.layout = Layout(Field.text("name", label_size=Size.LARGE)) assert parse_form(form) == parse_contents(RESULT_DIR, "override_label_size.html")
def test_section_css_id(): """Verify the accordion section id can be set.""" form = AccordionForm() form.helper.layout = Layout( Accordion(AccordionSection("Title", HTML("Contents"), css_id="new_id"))) assert parse_form(form) == parse_contents(RESULT_DIR, "section_css_id.html")
def test_show_legend_as_heading(): """Verify the field legend can be displayed as the page heading.""" form = FieldsetForm() form.helper = FormHelper() form.helper.layout = Layout( Fieldset("name", "email", legend="Contact", legend_tag="h1")) assert parse_form(form) == parse_contents(RESULT_DIR, "legend_heading.html")
def test_inline(): """Verify radio buttons can be displayed in a row.""" form = RadiosForm() form.helper = FormHelper() form.helper.layout = Layout( Field("method", context={"radios_inline": True})) assert parse_form(form) == parse_contents(RESULT_DIR, "buttons_inline.html")
def test_character_count(): """Verify the field can show the maximum number of characters allowed.""" form = TextareaForm(initial={"description": "Field value"}) form.helper = FormHelper() form.helper.layout = Layout( Field.textarea("description", max_characters=100)) assert parse_form(form) == parse_contents(RESULT_DIR, "character_count.html")
def test_override_default_legend_size(): """Verify a default legend size can be overridden on the field.""" form = CheckboxesForm() form.helper = FormHelper() form.helper.legend_size = Size.MEDIUM form.helper.layout = Layout( Field.checkboxes("method", legend_size=Size.LARGE)) assert parse_form(form) == parse_contents(RESULT_DIR, "override_legend_size.html")
def test_basic_layout(): """Verify all the gds attributes are displayed. Note: when the tabs are rendered a lot of extra markup is added so the template only contains the basic HTML to get the component to work. When you inspect the content in a browser it will look quite different. """ form = TabsForm() assert parse_form(form) == parse_contents(RESULT_DIR, "layout.html")
def test_section_css_class(): """Verify an extra CSS class can be added to an accordion section.""" form = AccordionForm() form.helper.layout = Layout( Accordion( AccordionSection("Title", HTML("Contents"), css_class="extra-css-class"))) assert parse_form(form) == parse_contents(RESULT_DIR, "section_css_class.html")
def test_no_help_text_errors(): """Verify all the gds error attributes are displayed if no help text is given.""" form = FileUploadForm(data={}) form.fields["file"].help_text = "" assert parse_form(form) == parse_contents(RESULT_DIR, "no_help_text_errors.html")
def test_no_help_text(): """Verify field is rendered correctly if no help text is given.""" form = FileUploadForm() form.fields["file"].help_text = "" assert parse_form(form) == parse_contents(RESULT_DIR, "no_help_text.html")
def test_no_label(): """Verify field is rendered correctly if no label is given.""" form = FileUploadForm() form.fields["file"].label = "" assert parse_form(form) == parse_contents(RESULT_DIR, "no_label.html")
def test_initial_attributes(): """Verify all the gds attributes are displayed.""" form = FileUploadForm() assert parse_form(form) == parse_contents(RESULT_DIR, "initial.html")
def test_validation_error_attributes(): """Verify all the gds error attributes are displayed.""" form = FileUploadForm(data={}) assert not form.is_valid() assert parse_form(form) == parse_contents(RESULT_DIR, "validation_errors.html")
def test_css_id(): """Verify the id attribute can be set on the parent div.""" form = TabsForm() form.helper = FormHelper() form.helper.layout = Layout(Tabs(css_id="new_id")) assert parse_form(form) == parse_contents(RESULT_DIR, "css_id.html")
def test_no_help_text_errors(): """Verify all the gds error attributes are displayed if no help text is given.""" form = CheckboxForm(data={"accept": ""}) form.fields["accept"].help_text = "" assert parse_form(form) == parse_contents(RESULT_DIR, "no_help_text_errors.html")
def test_initial_attributes(): """Verify all the gds attributes are displayed.""" form = CheckboxForm(initial={"accept": True}) assert parse_form(form) == parse_contents(RESULT_DIR, "initial.html")
def test_panel_attribute(): """Verify the extra attributes can be added to a tab panel.""" form = TabsForm() form.helper = FormHelper() form.helper.layout = Layout(Tabs(TabPanel("Title", key="value"))) assert parse_form(form) == parse_contents(RESULT_DIR, "panel_attributes.html")
def test_panel_css_id(): """Verify the id attribute can be set on a tab panel.""" form = TabsForm() form.helper = FormHelper() form.helper.layout = Layout(Tabs(TabPanel("Title", css_id="new_id"))) assert parse_form(form) == parse_contents(RESULT_DIR, "panel_css_id.html")
def test_panel_css_class(): """Verify an extra CSS class can be added to a tab panel.""" form = TabsForm() form.helper = FormHelper() form.helper.layout = Layout(Tabs(TabPanel("Title", css_class="extra-css-class"))) assert parse_form(form) == parse_contents(RESULT_DIR, "panel_css_class.html")
def test_attribute(): """Verify the extra attributes can be added to the parent div.""" form = TabsForm() form.helper = FormHelper() form.helper.layout = Layout(Tabs(key="value")) assert parse_form(form) == parse_contents(RESULT_DIR, "attributes.html")