0001-carddef-import-of-carddef-with-reference-to-itself-4.patch
tests/test_carddef.py | ||
---|---|---|
1 | 1 |
import pytest |
2 |
import xml.etree.ElementTree as ET |
|
3 | ||
4 |
from django.utils.six import BytesIO |
|
2 | 5 | |
3 | 6 |
from wcs.qommon.http_request import HTTPRequest |
4 | 7 |
from wcs.qommon.template import Template |
5 | 8 |
from wcs.carddef import CardDef |
9 |
from wcs.fields import ItemField |
|
6 | 10 |
from wcs.fields import StringField |
7 | 11 | |
8 | 12 |
from utilities import create_temporary_pub, clean_temporary_pub |
... | ... | |
68 | 72 |
carddef.name = 'foo' |
69 | 73 |
carddef.fields = [ |
70 | 74 |
StringField(id='1', label='Test', type='string', varname='foo'), |
75 |
ItemField( |
|
76 |
id='2', label='card field', type='item', |
|
77 |
data_source={'type': 'carddef:foo'}) |
|
71 | 78 |
] |
72 | 79 |
carddef.store() |
73 | 80 |
carddef_xml = carddef.export_to_xml() |
74 | 81 |
assert carddef_xml.tag == 'carddef' |
82 |
carddef.data_class().wipe() |
|
75 | 83 | |
76 |
carddef2 = CardDef.import_from_xml_tree(carddef_xml)
|
|
84 |
carddef2 = CardDef.import_from_xml(BytesIO(ET.tostring(carddef_xml)))
|
|
77 | 85 |
assert carddef2.name == 'foo' |
86 |
assert carddef2.fields[1].data_source == {'type': 'carddef:foo'} |
|
78 | 87 | |
79 | 88 | |
80 | 89 |
def test_template_access(pub): |
wcs/formdef.py | ||
---|---|---|
1043 | 1043 |
unknown_datasources.add(data_source.get('type')) |
1044 | 1044 |
elif data_source.get('type') and data_source.get('type').startswith('carddef:'): |
1045 | 1045 |
# check if carddef exists |
1046 |
url_name = data_source['type'][8:] |
|
1047 |
if formdef.xml_root_node == 'carddef' and formdef.url_name == url_name: |
|
1048 |
# reference to itself, it's ok |
|
1049 |
continue |
|
1046 | 1050 |
try: |
1047 |
CardDef.get_by_urlname(data_source['type'][8:])
|
|
1051 |
CardDef.get_by_urlname(url_name)
|
|
1048 | 1052 |
except KeyError: |
1049 | 1053 |
unknown_datasources.add(data_source.get('type')) |
1050 | 1054 |
if unknown_datasources: |
1051 |
- |