wcs/tests/test_snapshots.py

724 lines
25 KiB
Python

import io
import os
import shutil
import xml.etree.ElementTree as ET
import pytest
from admin_pages.test_all import create_role, create_superuser
from quixote.http_request import Upload
from utilities import clean_temporary_pub, create_temporary_pub, get_app, login
from wcs.blocks import BlockDef
from wcs.carddef import CardDef
from wcs.data_sources import NamedDataSource
from wcs.fields import ItemField
from wcs.formdef import FormDef
from wcs.qommon.form import UploadedFile
from wcs.qommon.misc import localstrftime
from wcs.wf.export_to_model import ExportToModel
from wcs.wf.form import FormWorkflowStatusItem, WorkflowFormFieldsFormDef
from wcs.workflows import Workflow
from wcs.wscalls import NamedWsCall
@pytest.fixture
def pub(request, emails):
pub = create_temporary_pub(
sql_mode=True,
templates_mode=True,
lazy_mode=True,
)
pub.cfg['identification'] = {'methods': ['password']}
pub.cfg['language'] = {'language': 'en'}
pub.write_cfg()
FormDef.wipe()
CardDef.wipe()
NamedDataSource.wipe()
pub.snapshot_class.wipe()
pub.user_class.wipe()
return pub
@pytest.fixture
def formdef_with_history(pub):
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = []
formdef.store()
for i in range(5):
formdef.name = 'testform %s' % i
formdef.description = 'this is a description (%s)' % i
formdef.store()
return formdef
def teardown_module(module):
clean_temporary_pub()
def test_snapshot_basics(pub):
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = []
formdef.store()
carddef = CardDef()
carddef.name = 'testcard'
carddef.fields = []
carddef.store()
formdef.name = 'testform2'
formdef.store()
carddef.name = 'testcard2'
carddef.store()
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
data_source.store()
assert pub.snapshot_class.count() == 5
# check we got correct data in the serializations
snapshot = pub.snapshot_class.get_latest('formdef', formdef.id)
assert '>testform2<' in snapshot.serialization
snapshot = pub.snapshot_class.get_latest('carddef', carddef.id)
assert '>testcard2<' in snapshot.serialization
def test_snapshot_instance(pub):
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = []
formdef.store()
carddef = CardDef()
carddef.name = 'testcard'
carddef.fields = []
carddef.store()
# remove existing snapshots as they may be duplicated if table_name was
# generated in a different second.
pub.snapshot_class.wipe()
carddef.name = 'testcard2'
carddef.store()
for i in range(10):
formdef.name = 'testform %s' % i
formdef.store()
assert pub.snapshot_class.count() == 11
snapshots = pub.snapshot_class.select_object_history(formdef)
assert len(snapshots) == 10
for i in range(10):
assert snapshots[i].serialization is None
assert pub.snapshot_class.get(snapshots[i].id).instance.name == 'testform %s' % (9 - i)
snapshots = pub.snapshot_class.select_object_history(carddef)
assert len(snapshots) == 1
def test_snapshot_user(pub):
user = pub.user_class()
user.name = 'User Name'
user.email = 'foo@localhost'
user.store()
carddef = CardDef()
carddef.name = 'testcard'
carddef.fields = []
carddef.store()
snapshot = pub.snapshot_class.select_object_history(carddef)[0]
assert snapshot.user is None
snapshot.user_id = user.id
snapshot.store()
snapshot = pub.snapshot_class.select_object_history(carddef)[0]
assert str(snapshot.user) == 'User Name'
snapshot.user_id = 'nope'
snapshot.store()
snapshot = pub.snapshot_class.select_object_history(carddef)[0]
assert str(snapshot.user) == 'unknown user'
def test_form_snapshot_comments(pub):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/forms/')
resp = resp.click('New Form')
resp.form['name'] = 'form title'
resp = resp.form.submit().follow()
# .store() then .disabled = True, then .store() again -> 2.
assert pub.snapshot_class.count() == 2
resp = resp.click('Confirmation Page')
assert resp.form['confirmation'].checked
resp.form['confirmation'].checked = False
resp = resp.form.submit().follow()
assert pub.snapshot_class.count() == 3
assert (
pub.snapshot_class.select(order_by='-timestamp')[0].comment
== 'Changed "Confirmation Page" parameters'
)
resp = resp.click(href='fields/')
resp.forms[0]['label'] = 'foobar'
resp.forms[0]['type'] = 'string'
resp = resp.forms[0].submit().follow()
assert pub.snapshot_class.select(order_by='-timestamp')[0].comment == 'New field "foobar"'
def test_form_snapshot_history(pub, formdef_with_history):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/forms/%s/' % formdef_with_history.id)
resp = resp.click('History')
assert [x.attrib['class'] for x in resp.pyquery.find('ul.snapshots-list li')] == [
'new-day',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
]
def test_form_snapshot_export(pub, formdef_with_history):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
snapshot = pub.snapshot_class.select_object_history(formdef_with_history)[2]
resp_export = resp.click(href='%s/export' % snapshot.id)
assert resp_export.content_type == 'application/x-wcs-snapshot'
assert '>testform 2<' in resp_export.text
def test_form_snapshot_restore(pub, formdef_with_history):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
# restore as new
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
snapshot = pub.snapshot_class.select_object_history(formdef_with_history)[2]
resp = resp.click(href='%s/restore' % snapshot.id)
assert resp.form['action'].value == 'as-new'
resp = resp.form.submit('submit')
assert FormDef.count() == 2
formdef = FormDef.get(resp.location.split('/')[-2])
assert formdef.url_name != formdef_with_history.url_name
assert not hasattr(formdef, 'snapshot_object')
# restore over
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
snapshot = pub.snapshot_class.select_object_history(formdef_with_history)[2]
resp = resp.click(href='%s/restore' % snapshot.id)
resp.form['action'].value = 'overwrite'
resp = resp.form.submit('submit')
assert FormDef.count() == 2
formdef = FormDef.get(resp.location.split('/')[-2])
assert formdef.id == formdef_with_history.id
assert formdef.url_name == formdef_with_history.url_name
def test_form_snapshot_restore_with_import_error(pub):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = [ItemField(id='1', label='Test', type='item', data_source={'type': 'unknown'})]
formdef.store()
assert pub.snapshot_class.count() == 1
snapshot = pub.snapshot_class.select_object_history(formdef)[0]
resp = app.get('/backoffice/forms/%s/history/%s/restore' % (formdef.id, snapshot.id))
resp = resp.form.submit('submit')
assert 'Can not restore snapshot (Unknown datasources [unknown])' in resp
def test_block_snapshot_browse(pub, blocks_feature):
create_superuser(pub)
create_role(pub)
BlockDef.wipe()
blockdef = BlockDef()
blockdef.name = 'testblock'
blockdef.fields = []
blockdef.store()
assert pub.snapshot_class.count() == 1
# check calling .store() without changes doesn't create snapshots
blockdef.store()
assert pub.snapshot_class.count() == 1
app = login(get_app(pub))
resp = app.get('/backoffice/forms/blocks/%s/history/' % blockdef.id)
snapshot = pub.snapshot_class.select_object_history(blockdef)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This block of fields is readonly.' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
def test_card_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
CardDef.wipe()
carddef = CardDef()
carddef.name = 'testcard'
carddef.fields = []
carddef.store()
assert pub.snapshot_class.count() == 1
# check calling .store() without changes doesn't create snapshots
carddef.store()
assert pub.snapshot_class.count() == 1
pub.custom_view_class.wipe()
custom_view = pub.custom_view_class()
custom_view.title = 'shared form view'
custom_view.formdef = carddef
custom_view.columns = {'list': [{'id': 'id'}]}
custom_view.filters = {}
custom_view.visibility = 'any'
custom_view.store()
# new version has custom views
carddef.name = 'test 1'
carddef.store()
# delete custom views
pub.custom_view_class.wipe()
app = login(get_app(pub))
resp = app.get('/backoffice/cards/%s/history/' % carddef.id)
snapshot = pub.snapshot_class.select_object_history(carddef)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This card model is readonly' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
resp = resp.click('Geolocation')
assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel']
assert pub.custom_view_class.count() == 0 # custom views are not restore on preview
def test_datasource_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
NamedDataSource.wipe()
datasource = NamedDataSource(name='test')
datasource.data_source = {'type': 'formula', 'value': repr([('1', 'un'), ('2', 'deux')])}
datasource.store()
assert pub.snapshot_class.count() == 1
# check calling .store() without changes doesn't create snapshots
datasource.store()
assert pub.snapshot_class.count() == 1
app = login(get_app(pub))
resp = app.get('/backoffice/forms/data-sources/%s/history/' % datasource.id)
snapshot = pub.snapshot_class.select_object_history(datasource)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This data source is readonly' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
with pytest.raises(IndexError):
resp = resp.click('Edit')
def test_form_snapshot_browse(pub, formdef_with_history):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
pub.custom_view_class.wipe()
custom_view = pub.custom_view_class()
custom_view.title = 'shared form view'
custom_view.formdef = formdef_with_history
custom_view.columns = {'list': [{'id': 'id'}]}
custom_view.filters = {}
custom_view.visibility = 'any'
custom_view.store()
# version 5 has custom views
formdef_with_history.name = 'testform 5'
formdef_with_history.description = 'this is a description (5)'
formdef_with_history.store()
assert pub.snapshot_class.count() == 7
# check calling .store() without changes doesn't create snapshots
formdef_with_history.store()
assert pub.snapshot_class.count() == 7
# delete custom views
pub.custom_view_class.wipe()
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
snapshot = pub.snapshot_class.select_object_history(formdef_with_history)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This form is readonly' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
assert '<a class="button disabled" href="#">&Lt;</a>' in resp.text
assert '<a class="button disabled" href="#">&LT;</a>' in resp.text
assert '<a class="button" href="../../%s/view/">&GT;</a>' % (snapshot.id - 1) in resp.text
assert '<a class="button" href="../../%s/view/">&Gt;</a>' % (snapshot.id - 6) in resp.text
resp = resp.click(href='../../%s/view/' % (snapshot.id - 1))
assert '<a class="button" href="../../%s/view/">&Lt;</a>' % snapshot.id in resp.text
assert '<a class="button" href="../../%s/view/">&LT;</a>' % snapshot.id in resp.text
assert '<a class="button" href="../../%s/view/">&GT;</a>' % (snapshot.id - 2) in resp.text
assert '<a class="button" href="../../%s/view/">&Gt;</a>' % (snapshot.id - 6) in resp.text
resp = resp.click(href='../../%s/view/' % (snapshot.id - 6))
assert '<a class="button" href="../../%s/view/">&Lt;</a>' % snapshot.id in resp.text
assert '<a class="button" href="../../%s/view/">&LT;</a>' % (snapshot.id - 5) in resp.text
assert '<a class="button disabled" href="#">&GT;</a>' in resp.text
assert '<a class="button disabled" href="#">&Gt;</a>' in resp.text
resp = resp.click(href='../../%s/view/' % snapshot.id)
resp = resp.click('Description')
assert resp.form['description'].value == 'this is a description (5)'
assert [x[0].name for x in resp.form.fields.values() if x[0].tag == 'button'] == ['cancel']
assert pub.custom_view_class.count() == 0 # custom views are not restore on preview
def test_form_snapshot_browse_with_import_error(pub):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = [ItemField(id='1', label='Test', type='item', data_source={'type': 'unknown'})]
formdef.store()
assert pub.snapshot_class.count() == 1
snapshot = pub.snapshot_class.select_object_history(formdef)[0]
# no error for missing datasource
resp = app.get('/backoffice/forms/%s/history/%s/view/' % (formdef.id, snapshot.id), status=200)
# other FormdefImportError
formdef.fields = [ItemField(id='1', label='Test', type='foobar')]
formdef.store()
assert pub.snapshot_class.count() == 2
snapshot = pub.snapshot_class.select_object_history(formdef)[0]
resp = app.get('/backoffice/forms/%s/history/%s/view/' % (formdef.id, snapshot.id), status=302)
assert resp.location == 'http://example.net/backoffice/forms/%s/history/' % formdef.id
resp = resp.follow()
assert 'Can not display snapshot (Unknown field type [foobar])' in resp
def test_workflow_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
Workflow.wipe()
workflow = Workflow(name='test')
workflow.store()
assert pub.snapshot_class.count() == 1
# check calling .store() without changes doesn't create snapshots
workflow.store()
assert pub.snapshot_class.count() == 1
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id)
snapshot = pub.snapshot_class.select_object_history(workflow)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This workflow is readonly' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
def test_workflow_snapshot_restore(pub):
create_superuser(pub)
create_role(pub)
Workflow.wipe()
workflow = Workflow(name='test')
workflow.store()
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id)
snapshot = pub.snapshot_class.select_object_history(workflow)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
# restore over
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id)
snapshot = pub.snapshot_class.select_object_history(workflow)[-1]
resp = resp.click(href='%s/restore' % snapshot.id)
resp.form['action'].value = 'overwrite'
resp = resp.form.submit('submit')
assert Workflow.count() == 1
assert not hasattr(Workflow.get(workflow.id), 'snapshot_object')
def test_workflow_with_model_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
Workflow.wipe()
if os.path.exists(os.path.join(pub.app_dir, 'models')):
shutil.rmtree(os.path.join(pub.app_dir, 'models'))
workflow = Workflow(name='test')
st1 = workflow.add_status('Status1', 'st1')
export_to = ExportToModel()
export_to.label = 'test'
upload = Upload('/foo/bar', content_type='application/vnd.oasis.opendocument.text')
file_content = b'''PK\x03\x04\x14\x00\x00\x08\x00\x00\'l\x8eG^\xc62\x0c\'\x00'''
upload.fp = io.BytesIO()
upload.fp.write(file_content)
upload.fp.seek(0)
export_to.model_file = UploadedFile('models', 'tmp', upload)
st1.items.append(export_to)
export_to.parent = st1
# export/import to get models stored in the expected way
workflow.store()
workflow = Workflow.import_from_xml_tree(
ET.fromstring(ET.tostring(workflow.export_to_xml(include_id=True))), include_id=True
)
assert len(os.listdir(os.path.join(pub.app_dir, 'models'))) == 2
workflow = Workflow.import_from_xml_tree(
ET.fromstring(ET.tostring(workflow.export_to_xml(include_id=True))), include_id=True
)
assert len(os.listdir(os.path.join(pub.app_dir, 'models'))) == 2
app = login(get_app(pub))
for i in range(3):
# check document model is not overwritten
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id)
snapshot = pub.snapshot_class.select_object_history(workflow)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This workflow is readonly' in resp.text
assert len(os.listdir(os.path.join(pub.app_dir, 'models'))) == 3 + i
def test_workflow_with_form_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
Workflow.wipe()
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
display_form = FormWorkflowStatusItem()
display_form.id = '_x'
display_form.varname = 'xxx'
display_form.formdef = WorkflowFormFieldsFormDef(item=display_form)
st1.items.append(display_form)
display_form.parent = st1
wf.store()
snapshot = pub.snapshot_class.select_object_history(wf)[0]
app = login(get_app(pub))
resp = app.get(
'/backoffice/workflows/%s/history/%s/view/status/st1/items/_x/fields/' % (wf.id, snapshot.id)
)
assert 'The fields are readonly' in resp.text # ok, no error
def test_wscall_snapshot_browse(pub):
create_superuser(pub)
create_role(pub)
NamedWsCall.wipe()
wscall = NamedWsCall(name='test')
wscall.store()
assert pub.snapshot_class.count() == 1
# check calling .store() without changes doesn't create snapshots
wscall.store()
assert pub.snapshot_class.count() == 1
app = login(get_app(pub))
resp = app.get('/backoffice/settings/wscalls/%s/history/' % wscall.id)
snapshot = pub.snapshot_class.select_object_history(wscall)[0]
resp = resp.click(href='%s/view/' % snapshot.id)
assert 'This webservice call is readonly' in resp.text
assert '<p>%s</p>' % localstrftime(snapshot.timestamp) in resp.text
with pytest.raises(IndexError):
resp = resp.click('Edit')
def test_form_snapshot_save(pub, formdef_with_history):
create_superuser(pub)
create_role(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/forms/%s/' % formdef_with_history.id)
resp = resp.click('Save snapshot')
resp.form['label'] = 'test snapshot'
resp = resp.form.submit('submit')
# add more snapshots
formdef = FormDef.get(id=formdef_with_history.id)
for i in range(10, 15):
formdef.description = 'this is a description (%s)' % i
formdef.store()
resp = app.get('/backoffice/forms/%s/history/' % formdef_with_history.id)
assert [x.attrib['class'] for x in resp.pyquery.find('ul.snapshots-list li')] == [
'new-day',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
'has-label',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
'collapsed',
]
def test_snaphost_workflow_status_item_comments(pub):
create_superuser(pub)
create_role(pub)
Workflow.wipe()
workflow = Workflow(name='test')
workflow.add_status(name='baz')
workflow.store()
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/1/')
resp = resp.click('baz')
resp.forms[0]['action-interaction'] = 'Webservice'
resp = resp.forms[0].submit()
resp = resp.follow()
resp = resp.click('Edit', href='items/1/')
resp.form['url'] = 'http://example.org'
resp = resp.forms[0].submit('submit')
resp = resp.follow()
resp = resp.follow()
resp = resp.click('Edit', href='items/1/')
resp.form['label'] = 'foo'
resp = resp.forms[0].submit('submit')
resp = resp.follow()
resp = resp.follow()
resp = resp.click(href='items/1/delete')
resp = resp.form.submit('submit')
resp = app.get('/backoffice/workflows/%s/history/' % workflow.id)
comments = [
x.text[18 : x.text.find('\n')]
for x in resp.html.find('ul', {'class': 'snapshots-list'}).find_all('li')
]
assert comments == [
'Deletion of action "Webservice (foo)" in status "baz"',
'Change in action "Webservice (foo)" in status "baz"',
'Change in action "Webservice" in status "baz"',
'New action "Webservice" in status "baz"',
'',
]
@pytest.fixture
def size_limit(pub):
pub.snapshot_class.WCS_MAX_LEN = 100
yield
pub.snapshot_class.WCS_MAX_LEN = 1000000
def test_workflow_snapshot_max_len(pub, size_limit):
formdef = FormDef()
formdef.name = 'testform'
formdef.fields = []
formdef.store()
Workflow.wipe()
workflow = Workflow(name='test')
workflow.store()
another_workflow = Workflow(name='other test')
another_workflow.store() # same object_type - check that other instances snapshots are not deleted
assert formdef.id == workflow.id # same id - check other object_type snapshots are not deleted
# first one: saved
assert pub.snapshot_class.count() == 3
first_id = pub.snapshot_class.select(order_by='id')[0].id
assert pub.snapshot_class.get(first_id).object_type == 'formdef'
assert pub.snapshot_class.get(first_id + 1).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 1).object_id == '1'
old_timestamp = pub.snapshot_class.get(first_id + 1).timestamp
assert pub.snapshot_class.get(first_id + 2).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 2).object_id == '2'
# save snapshot
pub.snapshot_class.snap(instance=workflow, label="snapshot !")
assert pub.snapshot_class.count() == 4
assert pub.snapshot_class.get(first_id).object_type == 'formdef'
assert pub.snapshot_class.get(first_id + 1).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 1).object_id == '1'
assert pub.snapshot_class.get(first_id + 1).label is None
assert pub.snapshot_class.get(first_id + 1).timestamp == old_timestamp
assert pub.snapshot_class.get(first_id + 1).instance.name == 'test'
assert pub.snapshot_class.get(first_id + 2).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 2).object_id == '2'
assert pub.snapshot_class.get(first_id + 3).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 3).object_id == '1'
assert pub.snapshot_class.get(first_id + 3).label == "snapshot !"
assert pub.snapshot_class.get(first_id + 3).instance.name == 'test'
# no changes
workflow.store()
assert pub.snapshot_class.count() == 4
assert pub.snapshot_class.get(first_id).object_type == 'formdef'
assert pub.snapshot_class.get(first_id + 1).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 1).object_id == '1'
assert pub.snapshot_class.get(first_id + 1).label is None
assert pub.snapshot_class.get(first_id + 1).timestamp == old_timestamp
assert pub.snapshot_class.get(first_id + 1).instance.name == 'test'
assert pub.snapshot_class.get(first_id + 2).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 2).object_id == '2'
assert pub.snapshot_class.get(first_id + 3).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 3).object_id == '1'
assert pub.snapshot_class.get(first_id + 3).label == "snapshot !"
assert pub.snapshot_class.get(first_id + 3).instance.name == 'test'
# with changes
workflow.name = 'foo bar'
workflow.store()
assert pub.snapshot_class.count() == 4
assert pub.snapshot_class.get(first_id).object_type == 'formdef'
assert pub.snapshot_class.get(first_id + 2).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 2).object_id == '2'
assert pub.snapshot_class.get(first_id + 3).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 3).object_id == '1'
assert pub.snapshot_class.get(first_id + 3).label == "snapshot !"
assert pub.snapshot_class.get(first_id + 3).instance.name == 'test'
assert pub.snapshot_class.get(first_id + 4).object_type == 'workflow'
assert pub.snapshot_class.get(first_id + 4).object_id == '1'
assert pub.snapshot_class.get(first_id + 4).label is None
assert pub.snapshot_class.get(first_id + 4).timestamp > old_timestamp
assert pub.snapshot_class.get(first_id + 4).instance.name == 'foo bar'
def test_pickle_erroneous_snapshot_object(pub):
# check snapshot object attribute is not restored
formdef = FormDef()
formdef.name = 'basic formdef'
formdef.snapshot_object = 'whatever'
formdef.store()
assert not hasattr(FormDef.get(formdef.id), 'snapshot_object')