wcs: change data logic in tests (#59803)
This commit is contained in:
parent
1e211d2643
commit
b6cb9194b7
|
@ -120,32 +120,47 @@ WCS_CARDDEFS_DATA = [
|
|||
{'title': 'Card Model 3', 'slug': 'card_model_3'},
|
||||
]
|
||||
|
||||
WCS_CARDS_DATA = [
|
||||
{
|
||||
'id': 11,
|
||||
'display_id': '10-11',
|
||||
'display_name': 'Card Model 1 - n°10-11',
|
||||
'digest': 'a a a',
|
||||
'text': 'aa',
|
||||
'url': '/backoffice/data/card_model_1/11/',
|
||||
},
|
||||
{
|
||||
'id': 12,
|
||||
'display_id': '10-12',
|
||||
'display_name': 'Card Model 1 - n°10-12',
|
||||
'digest': 'b b b',
|
||||
'text': 'bb',
|
||||
'url': '/backoffice/data/card_model_1/12/',
|
||||
},
|
||||
{
|
||||
'id': 13,
|
||||
'display_id': '10-13',
|
||||
'display_name': 'Card Model 1 - n°10-13',
|
||||
'digest': 'c c c',
|
||||
'text': 'cc',
|
||||
'url': '/backoffice/data/card_model_1/13/',
|
||||
},
|
||||
]
|
||||
WCS_CARDS_DATA = {
|
||||
'card_model_1': [
|
||||
{
|
||||
'id': 11,
|
||||
'display_id': '10-11',
|
||||
'display_name': 'Card Model 1 - n°10-11',
|
||||
'digest': 'a a a',
|
||||
'text': 'aa',
|
||||
'url': '/backoffice/data/card_model_1/11/',
|
||||
'fields': {
|
||||
'fielda': 'a',
|
||||
'fieldb': True,
|
||||
'fieldc': '2020-09-28',
|
||||
'fieldd': {'filename': 'file.pdf', 'url': 'http://127.0.0.1:8999/download?f=42'},
|
||||
'fielde': 'lorem<strong>ipsum\n\nhello world',
|
||||
'fieldf': 'lorem<strong>ipsum\n\nhello world',
|
||||
'fieldg': 'test@localhost',
|
||||
'fieldh': 'https://www.example.net/',
|
||||
'related': 'Foo Bar',
|
||||
'related_raw': 42,
|
||||
'related_structured': {'id': 42, 'text': 'blah'},
|
||||
},
|
||||
},
|
||||
{
|
||||
'id': 12,
|
||||
'display_id': '10-12',
|
||||
'display_name': 'Card Model 1 - n°10-12',
|
||||
'digest': 'b b b',
|
||||
'text': 'bb',
|
||||
'url': '/backoffice/data/card_model_1/12/',
|
||||
},
|
||||
{
|
||||
'id': 13,
|
||||
'display_id': '10-13',
|
||||
'display_name': 'Card Model 1 - n°10-13',
|
||||
'digest': 'c c c',
|
||||
'text': 'cc',
|
||||
'url': '/backoffice/data/card_model_1/13/',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
WCS_CARDS_CUSTOM_VIEW_DATA = [
|
||||
{
|
||||
|
@ -166,45 +181,25 @@ WCS_CARDS_CUSTOM_VIEW_DATA = [
|
|||
},
|
||||
]
|
||||
|
||||
WCS_CARDDEF_SCHEMA = {
|
||||
'name': 'Card Model 1',
|
||||
'fields': [
|
||||
{'label': 'Field A', 'varname': 'fielda', 'type': 'string'},
|
||||
{'label': 'Field B', 'varname': 'fieldb', 'type': 'bool'},
|
||||
{'label': 'Field C', 'varname': 'fieldc', 'type': 'date'},
|
||||
{'label': 'Field D', 'varname': 'fieldd', 'type': 'file'},
|
||||
{'label': 'Field E', 'varname': 'fielde', 'type': 'text'},
|
||||
{'label': 'Field F', 'varname': 'fieldf', 'type': 'text', 'pre': True},
|
||||
{'label': 'Field G', 'varname': 'fieldg', 'type': 'email'},
|
||||
{'label': 'Field H', 'varname': 'fieldh', 'type': 'string'},
|
||||
{'label': 'Related', 'varname': 'related', 'type': 'item'},
|
||||
{'label': 'Page', 'type': 'page'},
|
||||
{'label': 'Comment', 'type': 'comment'},
|
||||
{'label': 'Title', 'type': 'title'},
|
||||
{'label': 'Subtitle', 'type': 'subtitle'},
|
||||
{'label': 'Empty', 'varname': None, 'type': 'string'},
|
||||
],
|
||||
}
|
||||
|
||||
WCS_CARD_DATA = {
|
||||
'id': 11,
|
||||
'display_id': '10-11',
|
||||
'display_name': 'Card Model 1 - n°10-11',
|
||||
'digest': 'a a a',
|
||||
'text': 'aa',
|
||||
'url': '/backoffice/data/card_model_1/11/',
|
||||
'fields': {
|
||||
'fielda': 'a',
|
||||
'fieldb': True,
|
||||
'fieldc': '2020-09-28',
|
||||
'fieldd': {'filename': 'file.pdf', 'url': 'http://127.0.0.1:8999/download?f=42'},
|
||||
'fielde': 'lorem<strong>ipsum\n\nhello world',
|
||||
'fieldf': 'lorem<strong>ipsum\n\nhello world',
|
||||
'fieldg': 'test@localhost',
|
||||
'fieldh': 'https://www.example.net/',
|
||||
'related': 'Foo Bar',
|
||||
'related_raw': 42,
|
||||
'related_structured': {'id': 42, 'text': 'blah'},
|
||||
WCS_CARDDEF_SCHEMAS = {
|
||||
'card_model_1': {
|
||||
'name': 'Card Model 1',
|
||||
'fields': [
|
||||
{'label': 'Field A', 'varname': 'fielda', 'type': 'string'},
|
||||
{'label': 'Field B', 'varname': 'fieldb', 'type': 'bool'},
|
||||
{'label': 'Field C', 'varname': 'fieldc', 'type': 'date'},
|
||||
{'label': 'Field D', 'varname': 'fieldd', 'type': 'file'},
|
||||
{'label': 'Field E', 'varname': 'fielde', 'type': 'text'},
|
||||
{'label': 'Field F', 'varname': 'fieldf', 'type': 'text', 'pre': True},
|
||||
{'label': 'Field G', 'varname': 'fieldg', 'type': 'email'},
|
||||
{'label': 'Field H', 'varname': 'fieldh', 'type': 'string'},
|
||||
{'label': 'Related', 'varname': 'related', 'type': 'item'},
|
||||
{'label': 'Page', 'type': 'page'},
|
||||
{'label': 'Comment', 'type': 'comment'},
|
||||
{'label': 'Title', 'type': 'title'},
|
||||
{'label': 'Subtitle', 'type': 'subtitle'},
|
||||
{'label': 'Empty', 'varname': None, 'type': 'string'},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -249,14 +244,20 @@ def get_data_from_url(url):
|
|||
return WCS_USER_DRAFTS_DATA
|
||||
if '/api/cards/@list' in url:
|
||||
return WCS_CARDDEFS_DATA
|
||||
if '/api/cards/card_model_1/@schema' in url:
|
||||
return WCS_CARDDEF_SCHEMA
|
||||
if 'api/cards/card_model_1/11/' in url:
|
||||
return WCS_CARD_DATA
|
||||
m_schema = re.match(r'/api/cards/([a-z0-9_]+)/@schema', url)
|
||||
if m_schema:
|
||||
return WCS_CARDDEF_SCHEMAS.get(m_schema.group(1)) or {}
|
||||
m_card = re.match(r'/api/cards/([a-z0-9_]+)/(\d+)/', url)
|
||||
if m_card:
|
||||
try:
|
||||
return [d for d in WCS_CARDS_DATA[m_card.group(1)] if d['id'] == int(m_card.group(2))][0]
|
||||
except IndexError:
|
||||
return {}
|
||||
if 'api/cards/card_model_1/list/foo' in url:
|
||||
return WCS_CARDS_CUSTOM_VIEW_DATA
|
||||
if 'api/cards/card_model_1/list' in url:
|
||||
return WCS_CARDS_DATA
|
||||
m_list = re.match(r'/api/cards/([a-z0-9_]+)/list', url)
|
||||
if m_list:
|
||||
return WCS_CARDS_DATA[m_list.group(1)]
|
||||
return []
|
||||
|
||||
|
||||
|
@ -2175,7 +2176,7 @@ def test_card_cell_render_identifier(mock_send, nocache, app):
|
|||
for i in range(0, 3):
|
||||
assert '/api/cards/card_model_1/list' in mock_send.call_args_list[i * 2 + 1][0][0].url
|
||||
assert (
|
||||
'/api/cards/card_model_1/%s/' % WCS_CARDS_DATA[i]['id']
|
||||
'/api/cards/card_model_1/%s/' % WCS_CARDS_DATA['card_model_1'][i]['id']
|
||||
in mock_send.call_args_list[i * 2 + 2][0][0].url
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue