Testing scenario for workflow

How could i execute transitions for a workflow in a testing scenario ?

Here is Contract :

class Contract(Workflow, ModelSQL, ModelView):

    """HR contract."""

    __name__ = "hr.contract" 

Here is the scenario :

==========================
Contract workflow Scenario
==========================

Imports::

    >>> from datetime import date
    >>> from proteus import Model, Wizard
    >>> from trytond.tests.tools import activate_modules
    >>> from trytond.modules.hr.employee import Employee
    >>> from trytond.modules.hr.contract import Contract

Activate modules::

    >>> config = activate_modules('hr')

Create contract::

    >>> E = Model.get('company.employee', config)
    >>> e = E()
    >>> C = Model.get('hr.contract', config)
    >>> c = C()
    >>> c.employee = e
    >>> c.employee.birth_date = date.today()
    >>> c.reference = 'SolarEye444'
    >>> c.start_date = date.today()

Workflow simulation::

    >>> c.click('canceled')
    >>> c.save()
    >>> c.click('signed')
    >>> c.save()
    >>> c.state = 'canceled'
    >>> c.save()
    >>> c.state = 'signed'
    >>> c.save()

Scenario nothing fail however a contract can’t go from state = ‘canceled’ directly to a state ‘signed’

@classmethod

    def __setup__(cls):

        """Set up."""

        super(Contract, cls).__setup__()

        

        cls._transitions |= set((

            ('draft', 'printed'),

            ('draft', 'canceled'),

            ('printed', 'canceled'),

            ('printed', 'signed'),

            ('printed', 'draft'),

            ('canceled', 'draft'),            

        ))

        cls._buttons.update({

            'canceled': {

                'invisible': Eval('state').in_(

                    ['signed', 'canceled']), 

                'depends': ['state'],

            },

            'draft': {

                'invisible': Eval('state').in_(

                    ['signed', 'draft']),               

                'depends': ['state'],

            },

            'printed': {

                'invisible': Eval('state').in_(

                    ['canceled', 'signed', 'printed']),

                'depends': ['state'],

            },

            'signed': {

                'invisible': Eval('state') != 'printed',

                'depends': ['state'],

            },

        })

The transition decorator should be filtering out the invalid transitions, so try:

>>> c.click('canceled')
>>> c.save()
>>> c.state
'canceled'
>>> c.click('signed')
>>> c.save()
>>> c.state
'signed'

As there is not transition from ‘cancaled’ to ‘signed’, it is normal that clicking on ‘signed’ does not thing.
Also I guess the state is a readonly field, so user can not change it directly that’s why assignation does not thing with proteus.

As there is not transition from ‘cancaled’ to ‘signed’, it is normal that clicking on ‘signed’ does not thing.

=> Yes it is normal but test have to fail if i try to do so.

=> How could i test if workflow transition if it is ok or if it fail with conformity to the workflow schemas ?

Test the value of the state.
But there is no real point to test the Workflow.transition in your code as it is already tested by trytond.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.