misc: extend regex used for identifiers in subslugs (#87480)
gitea/combo/pipeline/head This commit looks good
Details
gitea/combo/pipeline/head This commit looks good
Details
This commit is contained in:
parent
3a6ebed4db
commit
e76a113f74
|
@ -106,7 +106,7 @@ def format_sub_slug(sub_slug):
|
|||
|
||||
if 'P<' not in sub_slug:
|
||||
# simple sub_slug without regex
|
||||
sub_slug = '(?P<%s>[a-z0-9]+)' % sub_slug
|
||||
sub_slug = '(?P<%s>[a-zA-Z0-9_-]+)' % sub_slug
|
||||
# search all named-groups in sub_slug
|
||||
for i, m in enumerate(re.finditer(r'P<[\w_-]+>', sub_slug)):
|
||||
# extract original name
|
||||
|
|
|
@ -952,7 +952,7 @@ def test_wcs_search_engines(settings, app):
|
|||
assert '&include-anonymised=off' in engine['url']
|
||||
|
||||
# create a page with sub_slug to enable card engines
|
||||
Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<foo_id>[a-z0-9]+)')
|
||||
Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<foo_id>[a-zA-Z0-9_-]+)')
|
||||
with mock.patch('combo.apps.wcs.utils.get_wcs_json') as mock_wcs:
|
||||
# no card model found
|
||||
mock_wcs.return_value = {}
|
||||
|
@ -970,7 +970,7 @@ def test_wcs_search_engines(settings, app):
|
|||
|
||||
# related page exists
|
||||
page = Page.objects.create(slug='bar', title='Bar')
|
||||
for sub_slug in ['(?P<card-bar_id>[a-z0-9]+)', 'card-bar_id']:
|
||||
for sub_slug in ['(?P<card-bar_id>[a-zA-Z0-9_-]+)', 'card-bar_id']:
|
||||
page.sub_slug = sub_slug
|
||||
page.save()
|
||||
search_engines = engines.get_engines()
|
||||
|
@ -988,7 +988,7 @@ def test_wcs_search_engines(settings, app):
|
|||
def test_wcs_errors(settings, app):
|
||||
settings.KNOWN_SERVICES = {'wcs': {'default': {'title': 'test', 'url': 'http://127.0.0.1:8999/'}}}
|
||||
settings.TEMPLATE_VARS['is_portal_agent'] = True
|
||||
Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<foo_id>[a-z0-9]+)')
|
||||
Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<foo_id>[a-zA-Z0-9_-]+)')
|
||||
|
||||
with mock.patch('combo.apps.wcs.utils.requests.get') as requests_get:
|
||||
mock_resp = Response()
|
||||
|
@ -1202,11 +1202,11 @@ def test_wcs_search_cell(requests_get, mock_wcs, settings, app):
|
|||
settings.TEMPLATE_VARS['is_portal_agent'] = True
|
||||
root_page = Page.objects.create(title='Root', slug='root', template_name='standard')
|
||||
card_page1 = Page.objects.create(
|
||||
slug='bar', title='Bar', sub_slug='(?P<card-bar_id>[a-z0-9]+)', parent=root_page
|
||||
slug='bar', title='Bar', sub_slug='(?P<card-bar_id>[a-zA-Z0-9_-]+)', parent=root_page
|
||||
)
|
||||
other_root_page = Page.objects.create(title='Other root', slug='other-root', template_name='standard')
|
||||
card_page2 = Page.objects.create(
|
||||
slug='bar-bis', title='Bar (bis)', sub_slug='(?P<card-bar_id>[a-z0-9]+)', parent=other_root_page
|
||||
slug='bar-bis', title='Bar (bis)', sub_slug='(?P<card-bar_id>[a-zA-Z0-9_-]+)', parent=other_root_page
|
||||
)
|
||||
mock_wcs.return_value = {
|
||||
'data': [{'id': 'card-bar', 'text': 'Card Bar', 'custom_views': [{'id': 'foo', 'text': 'Foo'}]}]
|
||||
|
@ -1334,7 +1334,7 @@ def test_profile_search_engines(settings, app):
|
|||
search_engines = engines.get_engines()
|
||||
assert 'users' not in search_engines
|
||||
|
||||
page = Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-z0-9]+)')
|
||||
page = Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-zA-Z0-9_-]+)')
|
||||
search_engines = engines.get_engines()
|
||||
assert 'users' in search_engines
|
||||
|
||||
|
@ -1346,7 +1346,7 @@ def test_profile_search_engines(settings, app):
|
|||
|
||||
def test_profile_add_search_engines(settings, app, admin_user):
|
||||
settings.KNOWN_SERVICES = {'authentic': {'default': {'title': 'authentic', 'url': 'https://authentic/'}}}
|
||||
Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-z0-9]+)')
|
||||
Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-zA-Z0-9_-]+)')
|
||||
|
||||
page = Page.objects.create(title='One', slug='one', template_name='standard')
|
||||
cell = SearchCell.objects.create(page=page, placeholder='content', order=0)
|
||||
|
@ -1415,7 +1415,7 @@ def test_profile_add_search_engines(settings, app, admin_user):
|
|||
|
||||
def test_search_profile(settings, app):
|
||||
settings.KNOWN_SERVICES = {'authentic': {'default': {'title': 'authentic', 'url': 'https://authentic/'}}}
|
||||
Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-z0-9]+)')
|
||||
Page.objects.create(slug='users', title='Users', sub_slug='(?P<name_id>[a-zA-Z0-9_-]+)')
|
||||
|
||||
page = Page.objects.create(title='One', slug='one', template_name='standard')
|
||||
cell = SearchCell.objects.create(page=page, placeholder='content', order=0)
|
||||
|
|
|
@ -1376,11 +1376,60 @@ def test_card_cell_table_list_mode_render_all_cards(mock_send, nocache, app, dis
|
|||
assert 'filter-internal-id' not in mock_send.call_args_list[0][0][0].url
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
def test_card_cell_list_mode_render_all_cards_custom_id(mock_send, nocache, app):
|
||||
page = Page.objects.create(title='xxx', slug='foo', template_name='standard')
|
||||
cell = WcsCardCell.objects.create(
|
||||
page=page,
|
||||
placeholder='content',
|
||||
order=0,
|
||||
display_mode='list',
|
||||
carddef_reference='default:card_with_custom_id',
|
||||
related_card_path='__all__',
|
||||
)
|
||||
|
||||
cell_url = reverse(
|
||||
'combo-public-ajax-page-cell',
|
||||
kwargs={'page_pk': page.pk, 'cell_reference': cell.get_reference()},
|
||||
)
|
||||
|
||||
# check url called
|
||||
mock_send.reset_mock()
|
||||
resp = app.get(page.get_online_url())
|
||||
assert len(resp.context['cells']) == 1
|
||||
extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)
|
||||
app.get(cell_url + '?ctx=' + extra_ctx[0])
|
||||
assert len(mock_send.call_args_list) == 1
|
||||
# cell rendering
|
||||
assert '/api/cards/card_with_custom_id/list' in mock_send.call_args_list[0][0][0].url
|
||||
assert 'filter-internal-id' not in mock_send.call_args_list[0][0][0].url
|
||||
|
||||
cell_div = resp.pyquery('.wcs-card-cell')[0]
|
||||
cell_url = cell_div.attrib['data-ajax-cell-url']
|
||||
extra_ctx = cell_div.attrib['data-extra-context']
|
||||
resp = app.get(cell_url + '?ctx=' + extra_ctx)
|
||||
assert [(PyQuery(x).text(), x.attrib['href']) for x in resp.pyquery('li a')] == [
|
||||
('foo', 'http://127.0.0.1:8999/backoffice/data/card_with_custom_id/foo_-Z/'),
|
||||
('bar', 'http://127.0.0.1:8999/backoffice/data/card_with_custom_id/bar_-Z/'),
|
||||
]
|
||||
|
||||
# add a combo page for card
|
||||
card_page = Page.objects.create(title='card', slug='card', template_name='standard')
|
||||
card_page.sub_slug = '(?P<card_with_custom_id_id>[a-z0-9]+)'
|
||||
card_page.save()
|
||||
|
||||
resp = app.get(cell_url + '?ctx=' + extra_ctx)
|
||||
assert [(PyQuery(x).text(), x.attrib['href']) for x in resp.pyquery('li a')] == [
|
||||
('foo', '/card/foo_-Z/'),
|
||||
('bar', '/card/bar_-Z/'),
|
||||
]
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
@pytest.mark.parametrize('display_mode', ['table', 'list'])
|
||||
def test_card_cell_table_list_mode_render_identifier(mock_send, nocache, app, display_mode):
|
||||
page = Page.objects.create(
|
||||
title='xxx', slug='foo', template_name='standard', sub_slug='(?P<card_model_1_id>[a-z0-9]+)'
|
||||
title='xxx', slug='foo', template_name='standard', sub_slug='(?P<card_model_1_id>[a-zA-Z0-9_-]+)'
|
||||
)
|
||||
cell = WcsCardCell.objects.create(
|
||||
page=page,
|
||||
|
@ -1456,7 +1505,7 @@ def test_card_cell_table_list_mode_render_identifier(mock_send, nocache, app, di
|
|||
# reset
|
||||
cell.card_ids = ''
|
||||
cell.save()
|
||||
page.sub_slug = '(?P<card_model_1_id>[a-z0-9]+)'
|
||||
page.sub_slug = '(?P<card_model_1_id>[a-zA-Z0-9_-]+)'
|
||||
page.save()
|
||||
|
||||
|
||||
|
@ -1779,7 +1828,7 @@ def test_card_cell_list_mode_render(mock_send, context, app):
|
|||
assert 'data-paginate-by="10"' in result
|
||||
|
||||
# create a page with the correct subslug
|
||||
page = Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<card_model_1_id>[a-z0-9]+)')
|
||||
page = Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<card_model_1_id>[a-zA-Z0-9_-]+)')
|
||||
|
||||
result = cell.render(context)
|
||||
assert '<h2>Card Model 1</h2>' in result
|
||||
|
@ -2308,7 +2357,7 @@ def test_card_cell_card_mode_render(mock_send, context, app):
|
|||
|
||||
# link page to model
|
||||
page.slug = 'plop'
|
||||
page.sub_slug = '(?P<card_model_1_id>[a-z0-9]+)'
|
||||
page.sub_slug = '(?P<card_model_1_id>[a-zA-Z0-9_-]+)'
|
||||
page.save()
|
||||
cell.related_card_path = ''
|
||||
cell.carddef_reference = 'default:card_model_1'
|
||||
|
@ -3186,7 +3235,7 @@ def test_card_cell_card_mode_render_all_cards(mock_send, nocache, app):
|
|||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
def test_card_cell_card_mode_render_identifier(mock_send, nocache, app):
|
||||
page = Page.objects.create(
|
||||
title='xxx', slug='foo', template_name='standard', sub_slug='(?P<card_model_1_id>[a-z0-9]+)'
|
||||
title='xxx', slug='foo', template_name='standard', sub_slug='(?P<card_model_1_id>[a-zA-Z0-9_-]+)'
|
||||
)
|
||||
cell = WcsCardCell.objects.create(
|
||||
page=page,
|
||||
|
|
|
@ -261,6 +261,22 @@ WCS_CARDS_DATA = {
|
|||
{'id': 42, 'fields': {}},
|
||||
{'id': 44, 'fields': {}},
|
||||
],
|
||||
'card_with_custom_id': [
|
||||
{
|
||||
'id': 'foo_-Z',
|
||||
'internal_id': '42',
|
||||
'text': 'foo',
|
||||
'url': '/backoffice/data/card_with_custom_id/foo_-Z/',
|
||||
'fields': {},
|
||||
},
|
||||
{
|
||||
'id': 'bar_-Z',
|
||||
'internal_id': '44',
|
||||
'text': 'bar',
|
||||
'url': '/backoffice/data/card_with_custom_id/bar_-Z/',
|
||||
'fields': {},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
WCS_CARDS_CUSTOM_VIEW_DATA = [
|
||||
|
|
Loading…
Reference in New Issue