12 |
12 |
import wcs.qommon.storage as st
|
13 |
13 |
from wcs import fields, sql
|
14 |
14 |
from wcs.blocks import BlockDef
|
|
15 |
from wcs.carddef import CardDef
|
|
16 |
from wcs.data_sources import NamedDataSource
|
15 |
17 |
from wcs.formdata import Evolution
|
16 |
18 |
from wcs.formdef import FormDef
|
17 |
19 |
from wcs.qommon import force_str
|
18 |
20 |
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
|
19 |
|
from wcs.workflows import Workflow, WorkflowCriticalityLevel
|
|
21 |
from wcs.workflows import Workflow, WorkflowBackofficeFieldsFormDef, WorkflowCriticalityLevel
|
20 |
22 |
|
21 |
23 |
from .utilities import clean_temporary_pub, create_temporary_pub
|
22 |
24 |
|
... | ... | |
2278 |
2280 |
|
2279 |
2281 |
lazy = sql.LazyEvolutionList(dump)
|
2280 |
2282 |
assert list(pickle.loads(pickle.dumps(lazy))) == list(lazy)
|
|
2283 |
|
|
2284 |
|
|
2285 |
def test_python_datasource_migration(pub):
|
|
2286 |
FormDef.wipe()
|
|
2287 |
CardDef.wipe()
|
|
2288 |
Workflow.wipe()
|
|
2289 |
NamedDataSource.wipe()
|
|
2290 |
|
|
2291 |
ds1 = {'type': 'formula', 'value': repr([('un'), ('deux')])}
|
|
2292 |
ds2 = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
|
|
2293 |
ds3 = {'type': 'formula', 'value': repr([('1', 'un', 'foo'), ('2', 'deux', 'bar')])}
|
|
2294 |
ds4 = {'type': 'formula', 'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}])}
|
|
2295 |
failing_ds1 = {'type': 'formula', 'value': repr([{'id': '', 'text': 'un'}, {'id': '2', 'text': 'deux'}])}
|
|
2296 |
failing_ds2 = {'type': 'formula', 'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': ''}])}
|
|
2297 |
failing_ds3 = {'type': 'formula', 'value': 'xxx()'}
|
|
2298 |
|
|
2299 |
for i, ds in enumerate([ds1, ds2, ds3, ds4, failing_ds1, failing_ds2, failing_ds3]):
|
|
2300 |
formdef = FormDef()
|
|
2301 |
formdef.name = 'foobar %s' % i
|
|
2302 |
formdef.fields = [
|
|
2303 |
fields.ItemField(id='1', label='item', data_source=ds),
|
|
2304 |
]
|
|
2305 |
formdef.store()
|
|
2306 |
|
|
2307 |
for i, ds in enumerate([ds1, ds2, ds3, ds4, failing_ds1, failing_ds2, failing_ds3]):
|
|
2308 |
carddef = CardDef()
|
|
2309 |
carddef.name = 'foobar %s' % i
|
|
2310 |
carddef.fields = [
|
|
2311 |
fields.ItemField(id='1', label='item', data_source=ds),
|
|
2312 |
]
|
|
2313 |
carddef.store()
|
|
2314 |
|
|
2315 |
for i, ds in enumerate([ds1, ds2, ds3, ds4, failing_ds1, failing_ds2, failing_ds3]):
|
|
2316 |
wf = Workflow()
|
|
2317 |
wf.name = 'foobar %s' % i
|
|
2318 |
wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf)
|
|
2319 |
wf.backoffice_fields_formdef.fields = [
|
|
2320 |
fields.ItemField(id='1', label='item', data_source=ds),
|
|
2321 |
]
|
|
2322 |
wf.store()
|
|
2323 |
|
|
2324 |
for i, ds in enumerate([ds1, ds2, ds3, ds4, failing_ds1, failing_ds2, failing_ds3]):
|
|
2325 |
data_source = NamedDataSource(name='foobar %s' % i)
|
|
2326 |
data_source.data_source = ds
|
|
2327 |
data_source.store()
|
|
2328 |
|
|
2329 |
conn, cur = sql.get_connection_and_cursor()
|
|
2330 |
|
|
2331 |
cur.execute('UPDATE wcs_meta SET value = 70 WHERE key = %s', ('sql_level',))
|
|
2332 |
conn.commit()
|
|
2333 |
cur.close()
|
|
2334 |
|
|
2335 |
conn, cur = sql.get_connection_and_cursor()
|
|
2336 |
sql.migrate()
|
|
2337 |
|
|
2338 |
assert sql.is_reindex_needed('python_ds_migration', conn=conn, cur=cur) is True
|
|
2339 |
sql.reindex()
|
|
2340 |
|
|
2341 |
formdef = FormDef.get(1)
|
|
2342 |
assert formdef.fields[0].data_source == {
|
|
2343 |
'type': 'jsonvalue',
|
|
2344 |
'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
|
|
2345 |
}
|
|
2346 |
formdef = FormDef.get(2)
|
|
2347 |
assert formdef.fields[0].data_source == {
|
|
2348 |
'type': 'jsonvalue',
|
|
2349 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2350 |
}
|
|
2351 |
formdef = FormDef.get(3)
|
|
2352 |
assert formdef.fields[0].data_source == {
|
|
2353 |
'type': 'jsonvalue',
|
|
2354 |
'value': '[{"id": "1", "text": "un", "key": "foo"}, {"id": "2", "text": "deux", "key": "bar"}]',
|
|
2355 |
}
|
|
2356 |
formdef = FormDef.get(4)
|
|
2357 |
assert formdef.fields[0].data_source == {
|
|
2358 |
'type': 'jsonvalue',
|
|
2359 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2360 |
}
|
|
2361 |
formdef = FormDef.get(5)
|
|
2362 |
assert formdef.fields[0].data_source == failing_ds1
|
|
2363 |
formdef = FormDef.get(6)
|
|
2364 |
assert formdef.fields[0].data_source == failing_ds2
|
|
2365 |
formdef = FormDef.get(7)
|
|
2366 |
assert formdef.fields[0].data_source == failing_ds3
|
|
2367 |
|
|
2368 |
carddef = CardDef.get(1)
|
|
2369 |
assert carddef.fields[0].data_source == {
|
|
2370 |
'type': 'jsonvalue',
|
|
2371 |
'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
|
|
2372 |
}
|
|
2373 |
carddef = CardDef.get(2)
|
|
2374 |
assert carddef.fields[0].data_source == {
|
|
2375 |
'type': 'jsonvalue',
|
|
2376 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2377 |
}
|
|
2378 |
carddef = CardDef.get(3)
|
|
2379 |
assert carddef.fields[0].data_source == {
|
|
2380 |
'type': 'jsonvalue',
|
|
2381 |
'value': '[{"id": "1", "text": "un", "key": "foo"}, {"id": "2", "text": "deux", "key": "bar"}]',
|
|
2382 |
}
|
|
2383 |
carddef = CardDef.get(4)
|
|
2384 |
assert carddef.fields[0].data_source == {
|
|
2385 |
'type': 'jsonvalue',
|
|
2386 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2387 |
}
|
|
2388 |
carddef = CardDef.get(5)
|
|
2389 |
assert carddef.fields[0].data_source == failing_ds1
|
|
2390 |
carddef = CardDef.get(6)
|
|
2391 |
assert carddef.fields[0].data_source == failing_ds2
|
|
2392 |
carddef = CardDef.get(7)
|
|
2393 |
assert carddef.fields[0].data_source == failing_ds3
|
|
2394 |
|
|
2395 |
wf = Workflow.get(1)
|
|
2396 |
assert wf.backoffice_fields_formdef.fields[0].data_source == {
|
|
2397 |
'type': 'jsonvalue',
|
|
2398 |
'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
|
|
2399 |
}
|
|
2400 |
wf = Workflow.get(2)
|
|
2401 |
assert wf.backoffice_fields_formdef.fields[0].data_source == {
|
|
2402 |
'type': 'jsonvalue',
|
|
2403 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2404 |
}
|
|
2405 |
wf = Workflow.get(3)
|
|
2406 |
assert wf.backoffice_fields_formdef.fields[0].data_source == {
|
|
2407 |
'type': 'jsonvalue',
|
|
2408 |
'value': '[{"id": "1", "text": "un", "key": "foo"}, {"id": "2", "text": "deux", "key": "bar"}]',
|
|
2409 |
}
|
|
2410 |
wf = Workflow.get(4)
|
|
2411 |
assert wf.backoffice_fields_formdef.fields[0].data_source == {
|
|
2412 |
'type': 'jsonvalue',
|
|
2413 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2414 |
}
|
|
2415 |
wf = Workflow.get(5)
|
|
2416 |
assert wf.backoffice_fields_formdef.fields[0].data_source == failing_ds1
|
|
2417 |
wf = Workflow.get(6)
|
|
2418 |
assert wf.backoffice_fields_formdef.fields[0].data_source == failing_ds2
|
|
2419 |
wf = Workflow.get(7)
|
|
2420 |
assert wf.backoffice_fields_formdef.fields[0].data_source == failing_ds3
|
|
2421 |
|
|
2422 |
data_source = NamedDataSource.get(1)
|
|
2423 |
assert data_source.data_source == {
|
|
2424 |
'type': 'jsonvalue',
|
|
2425 |
'value': '[{"id": "un", "text": "un"}, {"id": "deux", "text": "deux"}]',
|
|
2426 |
}
|
|
2427 |
data_source = NamedDataSource.get(2)
|
|
2428 |
assert data_source.data_source == {
|
|
2429 |
'type': 'jsonvalue',
|
|
2430 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2431 |
}
|
|
2432 |
data_source = NamedDataSource.get(3)
|
|
2433 |
assert data_source.data_source == {
|
|
2434 |
'type': 'jsonvalue',
|
|
2435 |
'value': '[{"id": "1", "text": "un", "key": "foo"}, {"id": "2", "text": "deux", "key": "bar"}]',
|
|
2436 |
}
|
|
2437 |
data_source = NamedDataSource.get(4)
|
|
2438 |
assert data_source.data_source == {
|
|
2439 |
'type': 'jsonvalue',
|
|
2440 |
'value': '[{"id": "1", "text": "un"}, {"id": "2", "text": "deux"}]',
|
|
2441 |
}
|
|
2442 |
data_source = NamedDataSource.get(5)
|
|
2443 |
assert data_source.data_source == failing_ds1
|
|
2444 |
data_source = NamedDataSource.get(6)
|
|
2445 |
assert data_source.data_source == failing_ds2
|
|
2446 |
data_source = NamedDataSource.get(7)
|
|
2447 |
assert data_source.data_source == failing_ds3
|
|
2448 |
|
|
2449 |
# check it's no longer needed afterwards
|
|
2450 |
sql.migrate()
|
|
2451 |
assert sql.is_reindex_needed('python_ds_migration', conn=conn, cur=cur) is False
|