def test_form_fails_validation_with_no_radio_buttons_selected(app_):
    with app_.test_request_context(method='POST', data={}):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert form.errors['contact_details_type'] == ['Not a valid choice']
def test_form_phone_number_validation_fails_with_invalid_phone_number_field(app_):
    data = {'contact_details_type': 'phone_number', 'phone_number': '1235 A'}

    with app_.test_request_context(method='POST', data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert form.errors['phone_number'] == ['Must be a valid phone number']
def test_form_email_validation_fails_with_invalid_email_address_field(app_):
    data = {'contact_details_type': 'email_address', 'email_address': '1@co'}

    with app_.test_request_context(method='POST', data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert len(form.errors['email_address']) == 2
def test_form_url_validation_fails_with_invalid_url_field(app_):
    data = {'contact_details_type': 'url', 'url': 'www.example.com'}

    with app_.test_request_context(method='POST', data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert len(form.errors['url']) == 1
def test_form_email_validation_fails_with_invalid_email_address_field(app_):
    data = {"contact_details_type": "email_address", "email_address": "1@co"}

    with app_.test_request_context(method="POST", data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert len(form.errors["email_address"]) == 2
def test_form_url_validation_fails_with_invalid_url_field(app_):
    data = {"contact_details_type": "url", "url": "www.example.com"}

    with app_.test_request_context(method="POST", data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert len(form.errors["url"]) == 1
def test_form_fails_validation_with_no_radio_buttons_selected(app_):
    with app_.test_request_context(method="POST", data={}):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert form.errors["contact_details_type"] == [
            "You need to choose an option"
        ]
def test_form_phone_number_validation_fails_with_invalid_phone_number_field(
        app_):
    data = {"contact_details_type": "phone_number", "phone_number": "1235 A"}

    with app_.test_request_context(method="POST", data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert form.errors["phone_number"] == ["Must be a valid phone number"]
def test_form_fails_validation_when_radio_button_selected_and_text_box_filled_in_do_not_match(
    app_,
    selected_radio_button,
    selected_text_box,
    text_box_data
):
    data = {'contact_details_type': selected_radio_button, selected_text_box: text_box_data}

    with app_.test_request_context(method='POST', data=data):
        form = ServiceContactDetailsForm()

        assert not form.validate_on_submit()
        assert len(form.errors) == 1
        assert form.errors[selected_radio_button] == ['This field is required.']
def test_form_only_validates_the_field_which_matches_the_selected_radio_button(
    app_,
    selected_field,
    url,
    email_address,
    phone_number,
):
    data = {'contact_details_type': selected_field,
            'url': url,
            'email_address': email_address,
            'phone_number': phone_number}

    with app_.test_request_context(method='POST', data=data):
        form = ServiceContactDetailsForm()

        assert form.validate_on_submit()
def test_form_only_validates_the_field_which_matches_the_selected_radio_button(
    app_,
    selected_field,
    url,
    email_address,
    phone_number,
):
    data = {
        "contact_details_type": selected_field,
        "url": url,
        "email_address": email_address,
        "phone_number": phone_number,
    }

    with app_.test_request_context(method="POST", data=data):
        form = ServiceContactDetailsForm()

        assert form.validate_on_submit()
Exemple #12
0
def service_set_contact_link(service_id):
    form = ServiceContactDetailsForm()

    if request.method == 'GET':
        contact_details = current_service.contact_link
        contact_type = check_contact_details_type(contact_details)
        field_to_update = getattr(form, contact_type)

        form.contact_details_type.data = contact_type
        field_to_update.data = contact_details

    if form.validate_on_submit():
        contact_type = form.contact_details_type.data

        current_service.update(contact_link=form.data[contact_type])
        return redirect(
            url_for('.service_settings', service_id=current_service.id))

    return render_template('views/service-settings/contact_link.html',
                           form=form)
def service_switch_can_upload_document(service_id):
    form = ServiceContactDetailsForm()

    # If turning the permission off, or turning it on and the service already has a contact_link,
    # don't show the form to add the link
    if current_service.has_permission('upload_document') or current_service.get('contact_link'):
        switch_service_permissions(service_id, 'upload_document')
        return redirect(url_for('.service_settings', service_id=service_id))

    if form.validate_on_submit():
        contact_type = form.contact_details_type.data

        service_api_client.update_service(
            current_service.id,
            contact_link=form.data[contact_type]
        )
        switch_service_permissions(service_id, 'upload_document')
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template('views/service-settings/contact_link.html', form=form)
Exemple #14
0
def service_switch_can_upload_document(service_id):
    if current_service.contact_link:
        return redirect(
            url_for('.service_set_permission',
                    service_id=service_id,
                    permission='upload_document'))

    form = ServiceContactDetailsForm()

    if form.validate_on_submit():
        contact_type = form.contact_details_type.data

        current_service.update(contact_link=form.data[contact_type])

        return redirect(
            url_for('.service_set_permission',
                    service_id=service_id,
                    permission='upload_document'))

    return render_template('views/service-settings/contact_link.html',
                           form=form)