0002-workflow-add-a-trace-on-created-form-carddata-by-wf-.patch
tests/backoffice_pages/test_form_inspect.py | ||
---|---|---|
617 | 617 |
def test_inspect_page_actions_traces(pub): |
618 | 618 |
create_user(pub, is_admin=True) |
619 | 619 | |
620 |
FormDef.wipe() |
|
621 |
target_formdef = FormDef() |
|
622 |
target_formdef.name = 'target form' |
|
623 |
target_formdef.fields = [ |
|
624 |
fields.StringField(id='0', label='string', varname='foo_string'), |
|
625 |
] |
|
626 |
target_formdef.store() |
|
627 | ||
620 | 628 |
workflow = Workflow.get_default_workflow() |
621 | 629 |
workflow.id = '2' |
622 | 630 |
workflow.criticality_levels = [ |
... | ... | |
629 | 637 |
trigger = action.append_trigger('timeout') |
630 | 638 |
trigger.anchor = 'creation' |
631 | 639 |
trigger.timeout = '2' |
640 |
create = workflow.possible_status[1].add_action('create_formdata', id='_create', prepend=True) |
|
641 |
create.varname = 'create_formdata' |
|
642 |
create.formdef_slug = target_formdef.url_name |
|
643 |
create.mappings = [ |
|
644 |
Mapping(field_id='0', expression='foo bar'), |
|
645 |
] |
|
632 | 646 |
workflow.store() |
633 | 647 | |
634 |
FormDef.wipe() |
|
635 | 648 |
formdef = FormDef() |
636 | 649 |
formdef.name = 'form title' |
637 | 650 |
formdef.workflow_id = workflow.id |
... | ... | |
651 | 664 |
formdata.refresh_from_storage() |
652 | 665 |
assert formdata.get_criticality_level_object().name == 'yellow' |
653 | 666 | |
654 |
resp = login(get_app(pub)).get(formdata.get_url(backoffice=True), status=200) |
|
667 |
app = login(get_app(pub)) |
|
668 |
resp = app.get(formdata.get_url(backoffice=True), status=200) |
|
655 | 669 |
resp = resp.click('Data Inspector') |
656 | 670 |
assert '>Actions Tracing</' in resp |
657 | 671 |
assert [x.text for x in resp.pyquery('#inspect-timeline strong')] == ['Just Submitted', 'New'] |
... | ... | |
659 | 673 |
'Email', |
660 | 674 |
'Email', |
661 | 675 |
'Automatic Jump', |
676 |
'New Form Creation', |
|
662 | 677 |
'Criticality Levels', |
663 | 678 |
] |
664 | 679 |
action_links = [x.attrib['href'] for x in resp.pyquery('#inspect-timeline a.tracing-link')] |
... | ... | |
667 | 682 |
action_links[1] |
668 | 683 |
== 'http://example.net/backoffice/workflows/2/status/just_submitted/items/_notify_new_receiver_email/' |
669 | 684 |
) |
685 |
assert action_links[-2] == 'http://example.net/backoffice/workflows/2/status/new/items/_create/' |
|
670 | 686 |
assert action_links[-1] == 'http://example.net/backoffice/workflows/2/global-actions/1/items/1/' |
671 | 687 | |
672 | 688 |
# check details are available |
673 | 689 |
assert 'Email (to Recipient)' in [ |
674 | 690 |
x.text_content().split(' ', 2)[-1] for x in resp.pyquery('#inspect-timeline li') |
675 | 691 |
] |
692 | ||
693 |
# check links on target formdata |
|
694 |
target_formdata = target_formdef.data_class().select()[0] |
|
695 |
resp = app.get(target_formdata.get_url(backoffice=True) + 'inspect') |
|
696 |
assert '>Actions Tracing</' in resp |
|
697 |
assert [x.text for x in resp.pyquery('#inspect-timeline strong')] == ['Just Submitted', 'New'] |
|
698 |
assert [x.text for x in resp.pyquery('#inspect-timeline a.tracing-link') if x.text] == [ |
|
699 |
'New Form Creation', |
|
700 |
'Email', |
|
701 |
'Email', |
|
702 |
'Automatic Jump', |
|
703 |
] |
|
704 |
action_links = [x.attrib['href'] for x in resp.pyquery('#inspect-timeline a.tracing-link')] |
|
705 |
assert action_links[0] == 'http://example.net/backoffice/workflows/_default/status/just_submitted/' |
|
706 |
assert ( |
|
707 |
action_links[1] == 'http://example.net/backoffice/workflows/2/status/new/items/_create/' |
|
708 |
) # link on external workflow |
|
709 |
assert 'New Form Creation (external workflow)' in [ |
|
710 |
x.text_content().split(' ', 2)[-1] for x in resp.pyquery('#inspect-timeline li') |
|
711 |
] |
|
712 | ||
676 | 713 |
# and there's no crash when part of the workflow changes |
677 | 714 |
workflow.global_actions = [] |
678 | 715 |
workflow.store() |
679 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
716 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
680 | 717 |
workflow.possible_status[0].items = [] |
681 | 718 |
workflow.store() |
682 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
719 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
683 | 720 |
workflow.possible_status = [] |
684 | 721 |
workflow.store() |
685 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
722 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
686 | 723 | |
687 | 724 | |
688 | 725 |
def test_inspect_page_missing_carddef_error(pub): |
tests/workflow/test_carddata.py | ||
---|---|---|
11 | 11 |
from wcs.qommon.http_request import HTTPRequest |
12 | 12 |
from wcs.qommon.upload_storage import PicklableUpload |
13 | 13 |
from wcs.wf.create_formdata import Mapping |
14 |
from wcs.workflows import Workflow |
|
14 |
from wcs.workflows import ActionsTracingEvolutionPart, Workflow
|
|
15 | 15 | |
16 | 16 |
from ..utilities import clean_temporary_pub, create_temporary_pub |
17 | 17 | |
... | ... | |
89 | 89 |
formdata.perform_workflow() |
90 | 90 | |
91 | 91 |
assert carddef.data_class().count() == 1 |
92 |
# check evolutions & tracing |
|
93 |
carddata = carddef.data_class().select()[0] |
|
94 |
assert isinstance(carddata.evolution[0].parts[0], ActionsTracingEvolutionPart) |
|
95 |
assert carddata.evolution[0].parts[0].actions[0][1:] == ( |
|
96 |
'create_carddata', # item key |
|
97 |
'_create', # item id |
|
98 |
'new', # status |
|
99 |
wf.id, # workflow id |
|
100 |
) |
|
92 | 101 | |
93 | 102 |
errors = pub.loggederror_class.select() |
94 | 103 |
assert len(errors) == 2 |
tests/workflow/test_formdata.py | ||
---|---|---|
7 | 7 |
from wcs.formdef import FormDef |
8 | 8 |
from wcs.qommon.http_request import HTTPRequest |
9 | 9 |
from wcs.wf.create_formdata import Mapping |
10 |
from wcs.workflows import Workflow |
|
10 |
from wcs.workflows import ActionsTracingEvolutionPart, Workflow
|
|
11 | 11 | |
12 | 12 |
from ..utilities import clean_temporary_pub, create_temporary_pub |
13 | 13 | |
... | ... | |
78 | 78 |
del source_formdef._workflow |
79 | 79 |
formdata.perform_workflow() |
80 | 80 |
assert target_formdef.data_class().count() == 1 |
81 |
# check evolutions & tracing |
|
82 |
target_formdata = target_formdef.data_class().select()[0] |
|
83 |
assert isinstance(target_formdata.evolution[0].parts[0], ActionsTracingEvolutionPart) |
|
84 |
assert target_formdata.evolution[0].parts[0].actions[0][1:] == ( |
|
85 |
'create_formdata', # item key |
|
86 |
'_create', # item id |
|
87 |
'new', # status |
|
88 |
wf.id, # workflow id |
|
89 |
) |
|
81 | 90 | |
82 | 91 |
errors = pub.loggederror_class.select() |
83 | 92 |
assert len(errors) == 2 |
84 | 93 |
assert 'form_var_toto_string' in errors[0].exception_message |
85 | 94 |
assert errors[1].summary == 'Missing field: unknown (1), unknown (2)' |
86 |
assert errors[0].formdata_id == str(target_formdef.data_class().select()[0].id)
|
|
87 |
assert errors[1].formdata_id == str(target_formdef.data_class().select()[0].id)
|
|
95 |
assert errors[0].formdata_id == str(target_formdata.id)
|
|
96 |
assert errors[1].formdata_id == str(target_formdata.id)
|
|
88 | 97 | |
89 | 98 |
# add field labels cache |
90 | 99 |
pub.loggederror_class.wipe() |
wcs/wf/create_formdata.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import datetime |
|
17 | 18 |
import time |
18 | 19 |
import xml.etree.ElementTree as ET |
19 | 20 | |
... | ... | |
35 | 36 |
WidgetListAsTable, |
36 | 37 |
) |
37 | 38 |
from wcs.qommon.substitution import CompatibilityNamesDict |
38 |
from wcs.workflows import EvolutionPart, WorkflowStatusItem, register_item_class |
|
39 |
from wcs.workflows import ActionsTracingEvolutionPart, EvolutionPart, WorkflowStatusItem, register_item_class
|
|
39 | 40 | |
40 | 41 | |
41 | 42 |
class Mapping: |
... | ... | |
598 | 599 |
new_formdata.store() |
599 | 600 |
if formdef.enable_tracking_codes: |
600 | 601 |
code.formdata = new_formdata # this will .store() the code |
602 |
# add a link to current workflow & action |
|
603 |
date_now = datetime.datetime.now() |
|
601 | 604 |
new_formdata.perform_workflow(event=('workflow-created', formdata.get_display_id())) |
605 |
action_part = None |
|
606 |
for evo in new_formdata.evolution: |
|
607 |
for part in evo.parts or []: |
|
608 |
if isinstance(part, ActionsTracingEvolutionPart): |
|
609 |
# in first ActionsTracingEvolutionPart found |
|
610 |
action_part = part |
|
611 |
break |
|
612 |
if action_part: |
|
613 |
break |
|
614 |
if not action_part: |
|
615 |
# in a new ActionsTracingEvolutionPart if not found |
|
616 |
action_part = ActionsTracingEvolutionPart('workflow-created', []) |
|
617 |
evo.add_part(action_part) |
|
618 |
performed_action = ( |
|
619 |
date_now, |
|
620 |
self.key, |
|
621 |
self.id, |
|
622 |
self.parent.id, |
|
623 |
self.parent.parent.id, |
|
624 |
) |
|
625 |
action_part.actions.insert(0, performed_action) |
|
626 |
new_formdata._store_all_evolution = True |
|
602 | 627 |
new_formdata.store() |
603 | 628 | |
604 | 629 |
# update local object as it may have been modified by new_formdata |
605 |
- |