0001-wcs-Improved-error-reporting-when-importing-a-file-o.patch
tests/test_blockdef_import.py | ||
---|---|---|
1 |
import io |
|
2 | ||
3 |
import pytest |
|
4 | ||
5 |
from wcs.blocks import BlockDef, BlockdefImportError |
|
6 | ||
7 | ||
8 |
def test_import_root_node_error(): |
|
9 |
export = b'<wrong_root_node><name>Name</name></wrong_root_node>' |
|
10 |
with pytest.raises(BlockdefImportError) as excinfo: |
|
11 |
BlockDef.import_from_xml(io.BytesIO(export)) |
|
12 |
assert '<wrong_root_node>' in excinfo.value.msg |
tests/test_formdef_import.py | ||
---|---|---|
867 | 867 |
'Unknown field types: foobaz; ' |
868 | 868 |
'Unknown fields blocks: foobar, foobaz' |
869 | 869 |
) |
870 | ||
871 | ||
872 |
def test_import_formdef_root_node_error(): |
|
873 |
export = b'<wrong_root_node><name>Name</name></wrong_root_node>' |
|
874 |
with pytest.raises(FormdefImportError) as excinfo: |
|
875 |
FormDef.import_from_xml(io.BytesIO(export)) |
|
876 |
assert '<wrong_root_node>' in excinfo.value.msg |
tests/test_workflow_import.py | ||
---|---|---|
1135 | 1135 |
'Unknown mail templates: unknown-mt-1, unknown-mt-2; ' |
1136 | 1136 |
'Unknown roles: unknown-role1, unknown-role2' |
1137 | 1137 |
) |
1138 | ||
1139 | ||
1140 |
def test_import_root_node_error(): |
|
1141 |
export = b'<wrong_root_node><name>Name</name></wrong_root_node>' |
|
1142 |
with pytest.raises(WorkflowImportError) as excinfo: |
|
1143 |
Workflow.import_from_xml(io.BytesIO(export)) |
|
1144 |
assert '<wrong_root_node>' in excinfo.value.msg |
wcs/blocks.py | ||
---|---|---|
176 | 176 |
tree = tree.getroot() |
177 | 177 | |
178 | 178 |
if tree.tag != cls.xml_root_node: |
179 |
raise BlockdefImportError(_('Unexpected root node')) |
|
179 |
raise BlockdefImportError( |
|
180 |
_( |
|
181 |
'Provided xml file doesn\'t seems to be a block definition: it starts with a <%s> tag.)' |
|
182 |
% tree.tag |
|
183 |
) |
|
184 |
) |
|
180 | 185 | |
181 | 186 |
if include_id and tree.attrib.get('id'): |
182 | 187 |
blockdef.id = tree.attrib.get('id') |
wcs/formdef.py | ||
---|---|---|
1351 | 1351 |
tree = tree.getroot() |
1352 | 1352 | |
1353 | 1353 |
if tree.tag != cls.xml_root_node: |
1354 |
raise FormdefImportError(_('Unexpected root node')) |
|
1354 |
raise FormdefImportError( |
|
1355 |
_( |
|
1356 |
'Provided xml file doesn\'t seems to be a form definition: it starts with a <%s> tag.)' |
|
1357 |
% tree.tag |
|
1358 |
) |
|
1359 |
) |
|
1355 | 1360 | |
1356 | 1361 |
if include_id and tree.attrib.get('id'): |
1357 | 1362 |
formdef.id = tree.attrib.get('id') |
wcs/workflows.py | ||
---|---|---|
851 | 851 |
if not ET.iselement(tree): |
852 | 852 |
tree = tree.getroot() |
853 | 853 | |
854 |
if tree.tag != 'workflow': |
|
855 |
raise WorkflowImportError(_('Not a workflow')) |
|
854 |
if tree.tag != cls.xml_root_node: |
|
855 |
raise WorkflowImportError( |
|
856 |
_( |
|
857 |
'Provided xml file doesn\'t seems to be a workflow definition: it starts with a <%s> tag.)' |
|
858 |
% tree.tag |
|
859 |
) |
|
860 |
) |
|
856 | 861 | |
857 | 862 |
if include_id and tree.attrib.get('id'): |
858 | 863 |
workflow.id = tree.attrib.get('id') |
859 |
- |