carddef: import of carddef with reference to itself (#46639)

This commit is contained in:
Lauréline Guérin 2020-09-15 14:44:39 +02:00
parent c1b508141f
commit b0ae6cdb17
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 15 additions and 2 deletions

View File

@ -1,8 +1,12 @@
import pytest
import xml.etree.ElementTree as ET
from django.utils.six import BytesIO
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.template import Template
from wcs.carddef import CardDef
from wcs.fields import ItemField
from wcs.fields import StringField
from utilities import create_temporary_pub, clean_temporary_pub
@ -68,13 +72,18 @@ def test_xml_export_import(pub):
carddef.name = 'foo'
carddef.fields = [
StringField(id='1', label='Test', type='string', varname='foo'),
ItemField(
id='2', label='card field', type='item',
data_source={'type': 'carddef:foo'})
]
carddef.store()
carddef_xml = carddef.export_to_xml()
assert carddef_xml.tag == 'carddef'
carddef.data_class().wipe()
carddef2 = CardDef.import_from_xml_tree(carddef_xml)
carddef2 = CardDef.import_from_xml(BytesIO(ET.tostring(carddef_xml)))
assert carddef2.name == 'foo'
assert carddef2.fields[1].data_source == {'type': 'carddef:foo'}
def test_template_access(pub):

View File

@ -1043,8 +1043,12 @@ class FormDef(StorableObject):
unknown_datasources.add(data_source.get('type'))
elif data_source.get('type') and data_source.get('type').startswith('carddef:'):
# check if carddef exists
url_name = data_source['type'][8:]
if formdef.xml_root_node == 'carddef' and formdef.url_name == url_name:
# reference to itself, it's ok
continue
try:
CardDef.get_by_urlname(data_source['type'][8:])
CardDef.get_by_urlname(url_name)
except KeyError:
unknown_datasources.add(data_source.get('type'))
if unknown_datasources: