def test_upload_form_validate(test_session, upload_form_fields,
                              valid_extensions):
    upload_paths = user_custom_paths(test_session, is_upload=True)
    validation_status = upload_form_validate(upload_form_fields, upload_paths,
                                             valid_extensions)
    # valid with fixture data
    assert validation_status["valid"]
    validation_status = upload_form_validate(upload_form_fields,
                                             ["web-app-upload/other/gds"],
                                             valid_extensions)
    # not valid if granted paths don't match
    assert not validation_status["valid"]
    invalid_form_fields = {}
    invalid_form_fields.update(upload_form_fields)
    invalid_form_fields["file_ext"] = "xls"
    validation_status = upload_form_validate(invalid_form_fields, upload_paths,
                                             valid_extensions)
    # not valid if file type is not matched
    assert not validation_status["valid"]
def test_route_upload_allowed(test_client, test_upload_session):

    bucket_name = "test_bucket"
    paths = user_custom_paths(test_upload_session, True)

    with test_client.session_transaction() as client_session:
        client_session.update(test_upload_session)

    stubber = stubs.mock_s3_list_objects(bucket_name, paths, True)
    with stubber:

        response = test_client.get("/upload")
        body = response.data.decode()
        assert response.status_code == 200
        assert '<h2 class="govuk-heading-m">File settings</h2>' in body
        assert '<h2 class="govuk-heading-m">Upload history</h2>' in body
        assert "local_authority/haringey/people1.csv" in body
        assert "local_authority/haringey/nested/nested_people1.csv" in body
        assert "local_authority/barnet/people4.csv" in body
        assert "local_authority/haringey/people1.csv-metadata.json" not in body
def test_user_custom_paths(test_session):
    download_paths = user_custom_paths(test_session, is_upload=False)
    assert "web-app-prod-data/local_authority/haringey" in download_paths
    upload_paths = user_custom_paths(test_session, is_upload=True)
    assert "web-app-upload/local_authority/barnet" in upload_paths