8 |
8 |
|
9 |
9 |
from quixote import cleanup
|
10 |
10 |
|
|
11 |
from wcs.categories import Category
|
11 |
12 |
from wcs.formdef import FormDef, fields
|
|
13 |
from wcs.workflows import Workflow
|
12 |
14 |
from qommon.misc import indent_xml as indent
|
13 |
15 |
|
14 |
16 |
from utilities import create_temporary_pub
|
... | ... | |
35 |
37 |
formdef2.export_to_json(include_id=include_id, indent=2)
|
36 |
38 |
|
37 |
39 |
def assert_xml_import_export_works(formdef, include_id=False):
|
38 |
|
formdef2 = FormDef.import_from_xml_tree(
|
39 |
|
formdef.export_to_xml(include_id=include_id), include_id=include_id)
|
|
40 |
formdef_xml = formdef.export_to_xml(include_id=include_id)
|
|
41 |
formdef2 = FormDef.import_from_xml_tree(formdef_xml, include_id=include_id)
|
40 |
42 |
assert_compare_formdef(formdef, formdef2, include_id=include_id)
|
41 |
43 |
return formdef2
|
42 |
44 |
|
... | ... | |
157 |
159 |
assert fd2.workflow_options == formdef.workflow_options
|
158 |
160 |
fd2 = assert_json_import_export_works(formdef)
|
159 |
161 |
assert fd2.workflow_options == formdef.workflow_options
|
|
162 |
|
|
163 |
def test_workflow_reference():
|
|
164 |
Workflow.wipe()
|
|
165 |
FormDef.wipe()
|
|
166 |
|
|
167 |
wf = Workflow()
|
|
168 |
wf.name = 'test workflow'
|
|
169 |
wf.store()
|
|
170 |
|
|
171 |
formdef = FormDef()
|
|
172 |
formdef.name = 'foo'
|
|
173 |
formdef.workflow_id = wf.id
|
|
174 |
f2 = assert_xml_import_export_works(formdef)
|
|
175 |
assert f2.workflow_id == formdef.workflow_id
|
|
176 |
|
|
177 |
f2 = assert_xml_import_export_works(formdef, include_id=True)
|
|
178 |
assert f2.workflow_id == formdef.workflow_id
|
|
179 |
|
|
180 |
formdef_xml_with_id = formdef.export_to_xml(include_id=True)
|
|
181 |
formdef_xml_without_id = formdef.export_to_xml(include_id=False)
|
|
182 |
|
|
183 |
# check there's no reference to a non-existing workflow
|
|
184 |
Workflow.wipe()
|
|
185 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=False).workflow_id is None
|
|
186 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=True).workflow_id is None
|
|
187 |
|
|
188 |
# check an import that is not using id fields will find the workflow by its
|
|
189 |
# name
|
|
190 |
wf = Workflow()
|
|
191 |
wf.id = '2'
|
|
192 |
wf.name = 'test workflow'
|
|
193 |
wf.store()
|
|
194 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=False).workflow_id == '2'
|
|
195 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=True).workflow_id is None
|
|
196 |
|
|
197 |
def test_category_reference():
|
|
198 |
Category.wipe()
|
|
199 |
FormDef.wipe()
|
|
200 |
|
|
201 |
cat = Category()
|
|
202 |
cat.name = 'test category'
|
|
203 |
cat.store()
|
|
204 |
|
|
205 |
formdef = FormDef()
|
|
206 |
formdef.name = 'foo'
|
|
207 |
formdef.category_id = cat.id
|
|
208 |
f2 = assert_xml_import_export_works(formdef)
|
|
209 |
assert f2.category_id == formdef.category_id
|
|
210 |
|
|
211 |
f2 = assert_xml_import_export_works(formdef, include_id=True)
|
|
212 |
assert f2.category_id == formdef.category_id
|
|
213 |
|
|
214 |
formdef_xml_with_id = formdef.export_to_xml(include_id=True)
|
|
215 |
formdef_xml_without_id = formdef.export_to_xml(include_id=False)
|
|
216 |
|
|
217 |
# check there's no reference to a non-existing category
|
|
218 |
Category.wipe()
|
|
219 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=False).category_id is None
|
|
220 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=True).category_id is None
|
|
221 |
|
|
222 |
# check an import that is not using id fields will find the category by its
|
|
223 |
# name
|
|
224 |
cat = Category()
|
|
225 |
cat.id = '2'
|
|
226 |
cat.name = 'test category'
|
|
227 |
cat.store()
|
|
228 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=False).category_id == '2'
|
|
229 |
assert FormDef.import_from_xml_tree(formdef_xml_with_id, include_id=True).category_id is None
|