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_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_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_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_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_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_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_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_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_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_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_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_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_breadcrumbs(): links = [ ("Home", "/"), ("Previous", "/previous/"), ("Current", None), ] template = '{% include "gds/layout/breadcrumbs.html" %}' assert parse_template(template, crumbs=links) == parse_contents( RESULT_DIR, "breadcrumbs.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_error_summary(): """Verify an error summary is displayed correctly.""" template = """ {% load crispy_forms_tags %} {% if form.helper.form_show_errors and form.errors %} {% include 'gds/layout/error_summary.html' %} {% endif %} <div class="govuk-body"> {% crispy form %} </div> """ form = TextInputForm(data={"name": ""}) form.add_error(None, "Non-field error") page = render_template(template, form=form) assert parse_html(page) == parse_contents(RESULT_DIR, "error_summary.html")
def test_extra_attributes(): button = Button.primary("name", "Title", key="value") assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "attributes.html" )
def test_css_id(): button = Button.primary("name", "Title", css_id="new_id") assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "css_id.html" )
def test_css_class(): button = Button.primary("name", "Title", css_class="extra-css-class") assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "css_class.html" )
def test_disabled_button(): button = Button.primary("name", "Title", disabled=True) assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "disabled.html" )
def test_warning_button(): button = Button.warning("name", "Title") assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "warning.html" )
def test_secondary_button(): button = Button.secondary("name", "Title") assert parse_template(TEMPLATE, input=button) == parse_contents( RESULT_DIR, "secondary.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_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")