tests: add checks for assigning invalid values in "edit card" action (#63088) #714

Merged
fpeters merged 1 commits from wip/63088-edit-carddata-invalid-data into main 2023-09-29 07:33:21 +02:00
1 changed files with 95 additions and 1 deletions

View File

@ -6,8 +6,9 @@ import pytest
from quixote import cleanup
from wcs import sessions
from wcs.blocks import BlockDef
from wcs.carddef import CardDef
from wcs.fields import DateField, FileField, ItemField, MapField, StringField
from wcs.fields import BlockField, DateField, FileField, ItemField, MapField, StringField
from wcs.formdef import FormDef
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.upload_storage import PicklableUpload
@ -1092,6 +1093,99 @@ def test_edit_carddata_from_created_object(pub):
assert carddata_reloaded.status == 'wf-2'
def test_edit_carddata_invalid_file_field(pub):
CardDef.wipe()
carddef = CardDef()
carddef.name = 'Foo Card'
carddef.fields = [
StringField(id='0', label='foo', varname='foo'),
FileField(id='4', label='File', varname='file'),
]
carddef.store()
carddef.data_class().wipe()
card_wf = Workflow(name='Card workflow')
st1 = card_wf.add_status('Status1')
edit = st1.add_action('edit_carddata', id='_edit')
edit.formdef_slug = carddef.url_name
edit.target_mode = 'manual'
edit.target_id = '{{ form_internal_id }}' # itself
edit.mappings = [
Mapping(field_id='0', expression='new value'),
Mapping(field_id='4', expression='{{ form_objects|getlist:"foo" }}'),
]
card_wf.store()
carddef.workflow = card_wf
carddef.store()
carddata = carddef.data_class()()
carddata.data = {'0': 'foo'}
carddata.store()
carddata.just_created()
carddata.store()
pub.loggederror_class.wipe()
carddata.perform_workflow()
assert pub.loggederror_class.count() == 1
assert pub.loggederror_class.select()[0].summary == 'Could not assign value to field "File"'
carddata.refresh_from_storage()
assert carddata.data == {'0': 'new value', '4': None}
def test_edit_carddata_invalid_block_field(pub):
BlockDef.wipe()
CardDef.wipe()
block = BlockDef()
block.name = 'foobar'
block.digest_template = 'X{{foobar_var_foo}}Y'
block.fields = [
StringField(id='123', required=True, label='Test', varname='foo'),
StringField(id='234', required=True, label='Test2', varname='bar'),
]
block.store()
carddef = CardDef()
carddef.name = 'Foo Card'
carddef.fields = [
StringField(id='0', label='foo', varname='foo'),
BlockField(id='1', label='block field', block_slug='foobar'),
]
carddef.store()
carddef.data_class().wipe()
card_wf = Workflow(name='Card workflow')
st1 = card_wf.add_status('Status1')
edit = st1.add_action('edit_carddata', id='_edit')
edit.formdef_slug = carddef.url_name
edit.target_mode = 'manual'
edit.target_id = '{{ form_internal_id }}' # itself
edit.mappings = [
Mapping(field_id='0', expression='new value'),
Mapping(field_id='1', expression='{{ form_objects|getlist:"foo" }}'),
]
card_wf.store()
carddef.workflow = card_wf
carddef.store()
carddata = carddef.data_class()()
carddata.data = {'0': 'foo'}
carddata.store()
carddata.just_created()
carddata.store()
pub.loggederror_class.wipe()
carddata.perform_workflow()
assert pub.loggederror_class.count() == 1
assert pub.loggederror_class.select()[0].summary == 'Could not assign value to field "block field"'
carddata.refresh_from_storage()
assert carddata.data == {'0': 'new value', '1': None, '1_display': None}
def test_assign_carddata_with_data_sourced_object(pub):
FormDef.wipe()
CardDef.wipe()