From 1ec12c6feafa5d5712594029a1f44e1cf893f734 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 14 Jan 2022 09:22:58 +0100
Subject: [PATCH 1/3] misc: split backoffice_pages tests

---
 tests/backoffice_pages/test_all.py     | 300 ---------------------
 tests/backoffice_pages/test_columns.py | 344 +++++++++++++++++++++++++
 tests/backoffice_pages/test_filters.py |   1 -
 3 files changed, 344 insertions(+), 301 deletions(-)
 create mode 100644 tests/backoffice_pages/test_columns.py

diff --git a/tests/backoffice_pages/test_all.py b/tests/backoffice_pages/test_all.py
index d618e1de..66b253e0 100644
--- a/tests/backoffice_pages/test_all.py
+++ b/tests/backoffice_pages/test_all.py
@@ -567,306 +567,6 @@ def test_backoffice_legacy_urls(pub):
     resp = app.get('/backoffice/not-form-title/', status=404)
 
 
-def test_backoffice_columns(pub):
-    create_superuser(pub)
-    create_environment(pub)
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert resp.text.count('</th>') == 8  # six columns
-    resp.forms['listing-settings']['1'].checked = False
-    assert 'submission_channel' not in resp.forms['listing-settings'].fields
-    assert 'last_update_time' in resp.forms['listing-settings'].fields
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('</th>') == 7  # fixe columns
-    assert resp.text.count('data-link') == 17  # 17 rows
-    assert resp.text.count('FOO BAR') == 0  # no field 1 column
-
-    # change column order
-    assert (
-        resp.forms['listing-settings']['columns-order'].value
-        == 'id,time,last_update_time,user-label,2,status,1,3,anonymised'
-    )
-    resp.forms['listing-settings'][
-        'columns-order'
-    ].value = 'user-label,id,time,last_update_time,2,status,1,3,anonymised'
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.find('<span>User Label</span>') < resp.text.find('<span>Number</span>')
-
-
-def test_backoffice_channel_column(pub):
-    if not pub.site_options.has_section('variables'):
-        pub.site_options.add_section('variables')
-    pub.site_options.set('variables', 'welco_url', 'xxx')
-    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
-        pub.site_options.write(fd)
-
-    create_superuser(pub)
-    create_environment(pub)
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert resp.text.count('</th>') == 8  # six columns
-    resp.forms['listing-settings']['submission_channel'].checked = True
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('</th>') == 9  # seven columns
-    assert resp.text.count('data-link') == 17  # 17 rows
-    assert resp.text.count('<td>Web</td>') == 17
-
-
-def test_backoffice_submission_agent_column(pub):
-    user = create_user(pub)
-    create_environment(pub)
-
-    agent = pub.user_class(name='agent')
-    agent.store()
-
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert 'submission_agent' not in resp.forms['listing-settings'].fields
-
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.backoffice_submission_roles = user.roles
-    formdef.store()
-    resp = app.get('/backoffice/management/form-title/')
-    assert resp.text.count('</th>') == 8  # six columns
-    resp.forms['listing-settings']['submission_agent'].checked = True
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('</th>') == 9  # seven columns
-    assert resp.text.count('data-link') == 17  # 17 rows
-    assert '>agent<' not in resp.text
-    resp = resp.click('Export a Spreadsheet')
-    resp.form['format'] = 'csv'
-    resp = resp.form.submit('submit')
-    assert len(resp.text.splitlines()) == 18  # 17 + header line
-    assert ',"agent",' not in resp.text
-
-    for formdata in formdef.data_class().select():
-        formdata.submission_agent_id = str(agent.id)
-        formdata.store()
-
-    resp = app.get('/backoffice/management/form-title/')
-    resp.forms['listing-settings']['submission_agent'].checked = True
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('>agent<') == 17
-
-    resp = resp.click('Export a Spreadsheet')
-    resp.form['format'] = 'csv'
-    resp = resp.form.submit('submit')
-    assert len(resp.text.splitlines()) == 18  # 17 + header line
-    assert resp.text.count(',"agent"') == 17
-
-
-def test_backoffice_image_column(pub):
-    create_superuser(pub)
-    create_environment(pub)
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.fields.append(
-        fields.FileField(
-            id='4', label='file field', type='file', display_locations=['validation', 'summary', 'listings']
-        )
-    )
-    formdef.store()
-
-    upload = PicklableUpload('test.jpeg', 'image/jpeg')
-    with open(os.path.join(os.path.dirname(__file__), '..', 'image-with-gps-data.jpeg'), 'rb') as fd:
-        upload.receive([fd.read()])
-    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
-        formdata.data['4'] = upload
-        formdata.store()
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert 'download?f=4&thumbnail=1' not in resp.text
-
-
-def test_backoffice_file_column(pub):
-    create_superuser(pub)
-    create_environment(pub)
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.fields.append(
-        fields.FileField(
-            id='4', label='file field', type='file', display_locations=['validation', 'summary', 'listings']
-        )
-    )
-    formdef.store()
-
-    upload = PicklableUpload('a filename that is too long "and" will be ellipsised.txt', 'text/plain')
-    upload.receive([b'text'])
-    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
-        formdata.data['4'] = upload
-        formdata.store()
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert 'title="a filename that is too long &quot;and&quot; will be ellipsised.txt"' in resp
-    assert '<span>a filename that is too(…).txt</span>' in resp
-
-
-def test_backoffice_user_columns(pub):
-    create_superuser(pub)
-    create_environment(pub)
-
-    from wcs.admin.settings import UserFieldsFormDef
-
-    user_formdef = UserFieldsFormDef(pub)
-    user_formdef.fields.append(fields.StringField(id='_first_name', label='name', type='string'))
-    user_formdef.fields.append(fields.StringField(id='3', label='test', type='string'))
-    user_formdef.store()
-    pub.cfg['users']['field_name'] = ['3', '4']
-    pub.write_cfg()
-
-    user1 = pub.user_class(name='userA')
-    user1.form_data = {'_first_name': 'toto', '3': 'nono'}
-    user1.set_attributes_from_formdata(user1.form_data)
-    user1.store()
-    user2 = pub.user_class(name='userB')
-    user2.form_data = {'_first_name': 'tutu', '3': 'nunu'}
-    user2.set_attributes_from_formdata(user2.form_data)
-    user2.store()
-
-    formdef = FormDef.get_by_urlname('form-title')
-    for i, formdata in enumerate(formdef.data_class().select()):
-        formdata.user_id = user1.id if bool(i % 2) else user2.id
-        formdata.store()
-
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert resp.text.count('</th>') == 8  # six columns
-
-    if not pub.is_using_postgresql():
-        # no support for relation columns unless using SQL
-        assert 'user-label$3' not in resp.forms['listing-settings'].fields
-        return
-    resp.forms['listing-settings']['user-label$3'].checked = True
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('</th>') == 9
-    assert '<td>nono</td' in resp
-
-
-def test_backoffice_card_field_columns(pub):
-    user = create_superuser(pub)
-    create_environment(pub)
-
-    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
-
-    CardDef.wipe()
-    carddef = CardDef()
-    carddef.name = 'foo'
-    carddef.fields = [
-        fields.CommentField(id='0', label='...', type='comment'),
-        fields.StringField(id='1', label='Test', type='string', varname='foo'),
-        fields.DateField(id='2', label='Date', type='date'),
-        fields.BoolField(id='3', label='Bool', type='bool'),
-        fields.ItemField(id='4', label='Item', type='item', data_source=datasource),
-    ]
-    carddef.backoffice_submission_roles = user.roles
-    carddef.workflow_roles = {'_editor': user.roles[0]}
-    carddef.digest_templates = {'default': 'card {{ form_var_foo }}'}
-    carddef.store()
-    carddef.data_class().wipe()
-
-    card = carddef.data_class()()
-    card.data = {
-        '1': 'plop',
-        '2': time.strptime('2020-04-24', '%Y-%m-%d'),
-        '3': True,
-        '4': 'A',
-        '4_display': 'aa',
-    }
-    card.store()
-
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.geolocations = {'base': 'Geolocation'}
-    formdef.fields.append(
-        fields.ItemField(
-            id='4', label='card field', type='item', data_source={'type': 'carddef:foo', 'value': ''}
-        )
-    )
-    formdef.store()
-
-    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
-        formdata.data['4'] = str(card.id)
-        formdata.data['4_display'] = formdef.fields[-1].store_display_value(formdata.data, '4')
-        formdata.data['4_structured'] = formdef.fields[-1].store_structured_value(formdata.data, '4')
-        formdata.geolocations = {'base': {'lat': 48.83, 'lon': 2.32}}
-        formdata.store()
-
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert resp.text.count('</th>') == 8  # six columns
-    if not pub.is_using_postgresql():
-        # no support for relation columns unless using SQL
-        assert '4$1' not in resp.forms['listing-settings'].fields
-        return
-    assert '4$0' not in resp.forms['listing-settings'].fields
-    resp.forms['listing-settings']['4$1'].checked = True
-    resp.forms['listing-settings']['4$2'].checked = True
-    resp.forms['listing-settings']['4$3'].checked = True
-    resp.forms['listing-settings']['4$4'].checked = True
-    resp = resp.forms['listing-settings'].submit()
-    assert resp.text.count('</th>') == 12
-    assert resp.text.count('data-link') == 17  # 17 rows
-    assert resp.text.count('<td>plop</td>') == 17
-    assert resp.text.count('<td>2020-04-24</td>') == 17
-    assert resp.text.count('<td>Yes</td>') == 17
-    assert resp.text.count('<td>aa</td>') == 17
-
-    resp_csv = resp.click('Export a Spreadsheet')
-    resp_csv.form['format'] = 'csv'
-    resp_csv = resp_csv.form.submit('submit')
-    assert resp_csv.text.splitlines()[1].endswith(',"plop","2020-04-24","Yes","aa"')
-
-    resp_map = resp.click('Plot on a Map')
-    geojson_url = re.findall(r'data-geojson-url="(.*?)"', resp_map.text)[0]
-    resp_geojson = app.get(geojson_url)
-    assert {
-        'varname': None,
-        'label': 'card field - Test',
-        'value': 'plop',
-        'html_value': 'plop',
-    } in resp_geojson.json['features'][0]['properties']['display_fields']
-
-
-def test_backoffice_block_columns(pub):
-    create_environment(pub)
-    create_superuser(pub)
-
-    BlockDef.wipe()
-    block = BlockDef()
-    block.name = 'foobar'
-    block.fields = [
-        fields.StringField(id='123', required=True, label='Test', type='string'),
-    ]
-    block.store()
-
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.fields.append(
-        fields.BlockField(id='8', label='Block', type='block:foobar', varname='data', max_items=3),
-    )
-    formdef.store()
-
-    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
-        formdata.data['8'] = {
-            'data': [{'123': 'blah'}],
-            'schema': {'123': 'string'},
-        }
-        formdata.data['8_display'] = 'blah'
-        formdata.store()
-
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    # check Block / Test is not part of the possible columns
-    assert [x.text_content() for x in resp.pyquery('#columns-filter label')] == [
-        'Number',
-        'Created',
-        'Last Modified',
-        'User Label',
-        '1st field',
-        '2nd field',
-        'Status',
-        '3rd field',
-        'Block',
-        'Anonymised',
-    ]
-
-
 def test_backoffice_form_category_permissions(pub):
     user = create_user(pub)
     create_environment(pub)
diff --git a/tests/backoffice_pages/test_columns.py b/tests/backoffice_pages/test_columns.py
new file mode 100644
index 00000000..183074fb
--- /dev/null
+++ b/tests/backoffice_pages/test_columns.py
@@ -0,0 +1,344 @@
+import os
+import re
+import time
+
+import pytest
+
+from wcs import fields
+from wcs.blocks import BlockDef
+from wcs.carddef import CardDef
+from wcs.formdef import FormDef
+from wcs.qommon.http_request import HTTPRequest
+from wcs.qommon.upload_storage import PicklableUpload
+
+from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, login
+from .test_all import create_environment, create_superuser, create_user
+
+
+def pytest_generate_tests(metafunc):
+    if 'pub' in metafunc.fixturenames:
+        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
+
+
+@pytest.fixture
+def pub(request, emails):
+    pub = create_temporary_pub(sql_mode=bool('sql' in request.param))
+
+    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
+    pub.set_app_dir(req)
+    pub.cfg['identification'] = {'methods': ['password']}
+    pub.cfg['language'] = {'language': 'en'}
+    pub.write_cfg()
+    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
+        fd.write(
+            '''
+    [api-secrets]
+    coucou = 1234
+    '''
+        )
+
+    return pub
+
+
+def teardown_module(module):
+    clean_temporary_pub()
+
+
+def test_backoffice_columns(pub):
+    create_superuser(pub)
+    create_environment(pub)
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert resp.text.count('</th>') == 8  # six columns
+    resp.forms['listing-settings']['1'].checked = False
+    assert 'submission_channel' not in resp.forms['listing-settings'].fields
+    assert 'last_update_time' in resp.forms['listing-settings'].fields
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('</th>') == 7  # fixe columns
+    assert resp.text.count('data-link') == 17  # 17 rows
+    assert resp.text.count('FOO BAR') == 0  # no field 1 column
+
+    # change column order
+    assert (
+        resp.forms['listing-settings']['columns-order'].value
+        == 'id,time,last_update_time,user-label,2,status,1,3,anonymised'
+    )
+    resp.forms['listing-settings'][
+        'columns-order'
+    ].value = 'user-label,id,time,last_update_time,2,status,1,3,anonymised'
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.find('<span>User Label</span>') < resp.text.find('<span>Number</span>')
+
+
+def test_backoffice_channel_column(pub):
+    if not pub.site_options.has_section('variables'):
+        pub.site_options.add_section('variables')
+    pub.site_options.set('variables', 'welco_url', 'xxx')
+    with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
+        pub.site_options.write(fd)
+
+    create_superuser(pub)
+    create_environment(pub)
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert resp.text.count('</th>') == 8  # six columns
+    resp.forms['listing-settings']['submission_channel'].checked = True
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('</th>') == 9  # seven columns
+    assert resp.text.count('data-link') == 17  # 17 rows
+    assert resp.text.count('<td>Web</td>') == 17
+
+
+def test_backoffice_submission_agent_column(pub):
+    user = create_user(pub)
+    create_environment(pub)
+
+    agent = pub.user_class(name='agent')
+    agent.store()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert 'submission_agent' not in resp.forms['listing-settings'].fields
+
+    formdef = FormDef.get_by_urlname('form-title')
+    formdef.backoffice_submission_roles = user.roles
+    formdef.store()
+    resp = app.get('/backoffice/management/form-title/')
+    assert resp.text.count('</th>') == 8  # six columns
+    resp.forms['listing-settings']['submission_agent'].checked = True
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('</th>') == 9  # seven columns
+    assert resp.text.count('data-link') == 17  # 17 rows
+    assert '>agent<' not in resp.text
+    resp = resp.click('Export a Spreadsheet')
+    resp.form['format'] = 'csv'
+    resp = resp.form.submit('submit')
+    assert len(resp.text.splitlines()) == 18  # 17 + header line
+    assert ',"agent",' not in resp.text
+
+    for formdata in formdef.data_class().select():
+        formdata.submission_agent_id = str(agent.id)
+        formdata.store()
+
+    resp = app.get('/backoffice/management/form-title/')
+    resp.forms['listing-settings']['submission_agent'].checked = True
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('>agent<') == 17
+
+    resp = resp.click('Export a Spreadsheet')
+    resp.form['format'] = 'csv'
+    resp = resp.form.submit('submit')
+    assert len(resp.text.splitlines()) == 18  # 17 + header line
+    assert resp.text.count(',"agent"') == 17
+
+
+def test_backoffice_image_column(pub):
+    create_superuser(pub)
+    create_environment(pub)
+    formdef = FormDef.get_by_urlname('form-title')
+    formdef.fields.append(
+        fields.FileField(
+            id='4', label='file field', type='file', display_locations=['validation', 'summary', 'listings']
+        )
+    )
+    formdef.store()
+
+    upload = PicklableUpload('test.jpeg', 'image/jpeg')
+    with open(os.path.join(os.path.dirname(__file__), '..', 'image-with-gps-data.jpeg'), 'rb') as fd:
+        upload.receive([fd.read()])
+    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
+        formdata.data['4'] = upload
+        formdata.store()
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert 'download?f=4&thumbnail=1' not in resp.text
+
+
+def test_backoffice_file_column(pub):
+    create_superuser(pub)
+    create_environment(pub)
+    formdef = FormDef.get_by_urlname('form-title')
+    formdef.fields.append(
+        fields.FileField(
+            id='4', label='file field', type='file', display_locations=['validation', 'summary', 'listings']
+        )
+    )
+    formdef.store()
+
+    upload = PicklableUpload('a filename that is too long "and" will be ellipsised.txt', 'text/plain')
+    upload.receive([b'text'])
+    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
+        formdata.data['4'] = upload
+        formdata.store()
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert 'title="a filename that is too long &quot;and&quot; will be ellipsised.txt"' in resp
+    assert '<span>a filename that is too(…).txt</span>' in resp
+
+
+def test_backoffice_user_columns(pub):
+    create_superuser(pub)
+    create_environment(pub)
+
+    from wcs.admin.settings import UserFieldsFormDef
+
+    user_formdef = UserFieldsFormDef(pub)
+    user_formdef.fields.append(fields.StringField(id='_first_name', label='name', type='string'))
+    user_formdef.fields.append(fields.StringField(id='3', label='test', type='string'))
+    user_formdef.store()
+    pub.cfg['users']['field_name'] = ['3', '4']
+    pub.write_cfg()
+
+    user1 = pub.user_class(name='userA')
+    user1.form_data = {'_first_name': 'toto', '3': 'nono'}
+    user1.set_attributes_from_formdata(user1.form_data)
+    user1.store()
+    user2 = pub.user_class(name='userB')
+    user2.form_data = {'_first_name': 'tutu', '3': 'nunu'}
+    user2.set_attributes_from_formdata(user2.form_data)
+    user2.store()
+
+    formdef = FormDef.get_by_urlname('form-title')
+    for i, formdata in enumerate(formdef.data_class().select()):
+        formdata.user_id = user1.id if bool(i % 2) else user2.id
+        formdata.store()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert resp.text.count('</th>') == 8  # six columns
+
+    if not pub.is_using_postgresql():
+        # no support for relation columns unless using SQL
+        assert 'user-label$3' not in resp.forms['listing-settings'].fields
+        return
+    resp.forms['listing-settings']['user-label$3'].checked = True
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('</th>') == 9
+    assert '<td>nono</td' in resp
+
+
+def test_backoffice_card_field_columns(pub):
+    user = create_superuser(pub)
+    create_environment(pub)
+
+    datasource = {'type': 'formula', 'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])}
+
+    CardDef.wipe()
+    carddef = CardDef()
+    carddef.name = 'foo'
+    carddef.fields = [
+        fields.CommentField(id='0', label='...', type='comment'),
+        fields.StringField(id='1', label='Test', type='string', varname='foo'),
+        fields.DateField(id='2', label='Date', type='date'),
+        fields.BoolField(id='3', label='Bool', type='bool'),
+        fields.ItemField(id='4', label='Item', type='item', data_source=datasource),
+    ]
+    carddef.backoffice_submission_roles = user.roles
+    carddef.workflow_roles = {'_editor': user.roles[0]}
+    carddef.digest_templates = {'default': 'card {{ form_var_foo }}'}
+    carddef.store()
+    carddef.data_class().wipe()
+
+    card = carddef.data_class()()
+    card.data = {
+        '1': 'plop',
+        '2': time.strptime('2020-04-24', '%Y-%m-%d'),
+        '3': True,
+        '4': 'A',
+        '4_display': 'aa',
+    }
+    card.store()
+
+    formdef = FormDef.get_by_urlname('form-title')
+    formdef.geolocations = {'base': 'Geolocation'}
+    formdef.fields.append(
+        fields.ItemField(
+            id='4', label='card field', type='item', data_source={'type': 'carddef:foo', 'value': ''}
+        )
+    )
+    formdef.store()
+
+    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
+        formdata.data['4'] = str(card.id)
+        formdata.data['4_display'] = formdef.fields[-1].store_display_value(formdata.data, '4')
+        formdata.data['4_structured'] = formdef.fields[-1].store_structured_value(formdata.data, '4')
+        formdata.geolocations = {'base': {'lat': 48.83, 'lon': 2.32}}
+        formdata.store()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    assert resp.text.count('</th>') == 8  # six columns
+    if not pub.is_using_postgresql():
+        # no support for relation columns unless using SQL
+        assert '4$1' not in resp.forms['listing-settings'].fields
+        return
+    assert '4$0' not in resp.forms['listing-settings'].fields
+    resp.forms['listing-settings']['4$1'].checked = True
+    resp.forms['listing-settings']['4$2'].checked = True
+    resp.forms['listing-settings']['4$3'].checked = True
+    resp.forms['listing-settings']['4$4'].checked = True
+    resp = resp.forms['listing-settings'].submit()
+    assert resp.text.count('</th>') == 12
+    assert resp.text.count('data-link') == 17  # 17 rows
+    assert resp.text.count('<td>plop</td>') == 17
+    assert resp.text.count('<td>2020-04-24</td>') == 17
+    assert resp.text.count('<td>Yes</td>') == 17
+    assert resp.text.count('<td>aa</td>') == 17
+
+    resp_csv = resp.click('Export a Spreadsheet')
+    resp_csv.form['format'] = 'csv'
+    resp_csv = resp_csv.form.submit('submit')
+    assert resp_csv.text.splitlines()[1].endswith(',"plop","2020-04-24","Yes","aa"')
+
+    resp_map = resp.click('Plot on a Map')
+    geojson_url = re.findall(r'data-geojson-url="(.*?)"', resp_map.text)[0]
+    resp_geojson = app.get(geojson_url)
+    assert {
+        'varname': None,
+        'label': 'card field - Test',
+        'value': 'plop',
+        'html_value': 'plop',
+    } in resp_geojson.json['features'][0]['properties']['display_fields']
+
+
+def test_backoffice_block_columns(pub):
+    create_environment(pub)
+    create_superuser(pub)
+
+    BlockDef.wipe()
+    block = BlockDef()
+    block.name = 'foobar'
+    block.fields = [
+        fields.StringField(id='123', required=True, label='Test', type='string'),
+    ]
+    block.store()
+
+    formdef = FormDef.get_by_urlname('form-title')
+    formdef.fields.append(
+        fields.BlockField(id='8', label='Block', type='block:foobar', varname='data', max_items=3),
+    )
+    formdef.store()
+
+    for formdata in formdef.data_class().select(lambda x: x.status == 'wf-new'):
+        formdata.data['8'] = {
+            'data': [{'123': 'blah'}],
+            'schema': {'123': 'string'},
+        }
+        formdata.data['8_display'] = 'blah'
+        formdata.store()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/management/form-title/')
+    # check Block / Test is not part of the possible columns
+    assert [x.text_content() for x in resp.pyquery('#columns-filter label')] == [
+        'Number',
+        'Created',
+        'Last Modified',
+        'User Label',
+        '1st field',
+        '2nd field',
+        'Status',
+        '3rd field',
+        'Block',
+        'Anonymised',
+    ]
diff --git a/tests/backoffice_pages/test_filters.py b/tests/backoffice_pages/test_filters.py
index 392a49e1..a9140ebf 100644
--- a/tests/backoffice_pages/test_filters.py
+++ b/tests/backoffice_pages/test_filters.py
@@ -794,7 +794,6 @@ def test_backoffice_block_field_filter(pub, local_user):
 
     app = login(get_app(pub))
     resp = app.get('/backoffice/management/form-title/')
-    # block subfields should not be proposed as columns
     assert '<label><input type="checkbox" name="1"/>Block Data / String</label>' not in resp
     assert '<label><input type="checkbox" name="2"/>Block Data / Item</label>' not in resp
     assert '<label><input type="checkbox" name="3"/>Block Data / Bool</label>' not in resp
-- 
2.34.1

