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 |
671 |
assert [x.text for x in resp.pyquery('#inspect-timeline .event')] == [ |
|
672 |
'None', |
|
673 |
'Continuation', |
|
674 |
'Global action timeout', |
|
675 |
] |
|
657 | 676 |
assert [x.text for x in resp.pyquery('#inspect-timeline strong')] == ['Just Submitted', 'New'] |
658 | 677 |
assert [x.text for x in resp.pyquery('#inspect-timeline a.tracing-link') if x.text] == [ |
659 | 678 |
'Email', |
660 | 679 |
'Email', |
661 | 680 |
'Automatic Jump', |
681 |
'New Form Creation', |
|
662 | 682 |
'Criticality Levels', |
663 | 683 |
] |
684 |
event_links = [x.attrib['href'] for x in resp.pyquery('#inspect-timeline .event a')] |
|
685 |
assert event_links == [] |
|
664 | 686 |
action_links = [x.attrib['href'] for x in resp.pyquery('#inspect-timeline a.tracing-link')] |
665 | 687 |
assert action_links[0] == 'http://example.net/backoffice/workflows/2/status/just_submitted/' |
666 | 688 |
assert ( |
667 | 689 |
action_links[1] |
668 | 690 |
== 'http://example.net/backoffice/workflows/2/status/just_submitted/items/_notify_new_receiver_email/' |
669 | 691 |
) |
692 |
assert action_links[-2] == 'http://example.net/backoffice/workflows/2/status/new/items/_create/' |
|
670 | 693 |
assert action_links[-1] == 'http://example.net/backoffice/workflows/2/global-actions/1/items/1/' |
671 | 694 | |
672 | 695 |
# check details are available |
673 | 696 |
assert 'Email (to Recipient)' in [ |
674 | 697 |
x.text_content().split(' ', 2)[-1] for x in resp.pyquery('#inspect-timeline li') |
675 | 698 |
] |
699 | ||
700 |
# check links on target formdata |
|
701 |
target_formdata = target_formdef.data_class().select()[0] |
|
702 |
resp = app.get(target_formdata.get_url(backoffice=True) + 'inspect') |
|
703 |
assert '>Actions Tracing</' in resp |
|
704 |
assert [x.text for x in resp.pyquery('#inspect-timeline .event a')] == ['Created (by workflow action)'] |
|
705 |
event_links = [x.attrib['href'] for x in resp.pyquery('#inspect-timeline .event a')] |
|
706 |
assert ( |
|
707 |
event_links[0] == 'http://example.net/backoffice/workflows/2/status/new/items/_create/' |
|
708 |
) # link on external workflow |
|
709 | ||
676 | 710 |
# and there's no crash when part of the workflow changes |
677 | 711 |
workflow.global_actions = [] |
678 | 712 |
workflow.store() |
679 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
713 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
680 | 714 |
workflow.possible_status[0].items = [] |
681 | 715 |
workflow.store() |
682 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
716 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
683 | 717 |
workflow.possible_status = [] |
684 | 718 |
workflow.store() |
685 |
get_app(pub).get(formdata.get_url(backoffice=True) + 'inspect')
|
|
719 |
app.get(formdata.get_url(backoffice=True) + 'inspect')
|
|
686 | 720 | |
687 | 721 | |
688 | 722 |
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].external_workflow_id == wf.id |
|
96 |
assert carddata.evolution[0].parts[0].external_status_id == 'new' |
|
97 |
assert carddata.evolution[0].parts[0].external_item_id == '_create' |
|
92 | 98 | |
93 | 99 |
errors = pub.loggederror_class.select() |
94 | 100 |
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].external_workflow_id == wf.id |
|
85 |
assert target_formdata.evolution[0].parts[0].external_status_id == 'new' |
|
86 |
assert target_formdata.evolution[0].parts[0].external_item_id == '_create' |
|
81 | 87 | |
82 | 88 |
errors = pub.loggederror_class.select() |
83 | 89 |
assert len(errors) == 2 |
84 | 90 |
assert 'form_var_toto_string' in errors[0].exception_message |
85 | 91 |
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)
|
|
92 |
assert errors[0].formdata_id == str(target_formdata.id)
|
|
93 |
assert errors[1].formdata_id == str(target_formdata.id)
|
|
88 | 94 | |
89 | 95 |
# add field labels cache |
90 | 96 |
pub.loggederror_class.wipe() |
wcs/wf/create_formdata.py | ||
---|---|---|
35 | 35 |
WidgetListAsTable, |
36 | 36 |
) |
37 | 37 |
from wcs.qommon.substitution import CompatibilityNamesDict |
38 |
from wcs.workflows import EvolutionPart, WorkflowStatusItem, register_item_class |
|
38 |
from wcs.workflows import ActionsTracingEvolutionPart, EvolutionPart, WorkflowStatusItem, register_item_class
|
|
39 | 39 | |
40 | 40 | |
41 | 41 |
class Mapping: |
... | ... | |
598 | 598 |
new_formdata.store() |
599 | 599 |
if formdef.enable_tracking_codes: |
600 | 600 |
code.formdata = new_formdata # this will .store() the code |
601 |
# add a link to current workflow & action |
|
601 | 602 |
new_formdata.perform_workflow(event=('workflow-created', formdata.get_display_id())) |
603 |
action_part = None |
|
604 |
for evo in new_formdata.evolution: |
|
605 |
for part in evo.parts or []: |
|
606 |
if isinstance(part, ActionsTracingEvolutionPart): |
|
607 |
# in first ActionsTracingEvolutionPart found |
|
608 |
action_part = part |
|
609 |
break |
|
610 |
if action_part: |
|
611 |
break |
|
612 |
if not action_part: |
|
613 |
# in a new ActionsTracingEvolutionPart if not found |
|
614 |
action_part = ActionsTracingEvolutionPart('workflow-created', []) |
|
615 |
evo.add_part(action_part) |
|
616 |
action_part.external_workflow_id = self.parent.parent.id |
|
617 |
action_part.external_status_id = self.parent.id |
|
618 |
action_part.external_item_id = self.id |
|
619 |
new_formdata._store_all_evolution = True |
|
602 | 620 |
new_formdata.store() |
603 | 621 | |
604 | 622 |
# update local object as it may have been modified by new_formdata |
605 |
- |