Beispiel #1
0
def get_task(request, flow_name):
    flow = _get_flow(request, flow_name)
    if flow is None:
        flow = create_flow('trytry.{0}.steps'.format(flow_name))
        flow.setup_flow()
        request.session['{0}_flow_id'.format(flow_name)] = flow.id
    command_result = {}
    if request.method == 'POST':
        data = request.POST.copy()
        # navigate through steps
        if data.get('navigate'):
            if data['navigate'] == 'prev':
                flow.current_step = flow.get_prev_step_name()
                flow.state = 'active'
            elif data['navigate'] == 'next':
                current_step = flow.get_next_step_name()
                if current_step is None:
                    flow.state = 'complete'
                else:
                    flow.current_step = current_step
                    flow.state = 'active'
            flow.save()
        if data.get('command'):
            command_result = flow.apply(data.get('command'))
            if flow.state == 'complete':
                flow.teardown_flow()
    result = {
        'task': flow.get_task(),
        'id': flow.id,
        'progress': get_progress(flow),
        'flow_name': str(flow),
        'step_prompt': flow.get_prompt()
    }
    result.update(command_result)
    return wrap_json(result)
Beispiel #2
0
 def test_pass_flow(self):
     flow = create_flow('trytry.simple_python.tests.simple_python')
     self.assertEqual(flow.state, 'new')
     # setup
     flow.setup_flow()
     self.assertEqual(flow.state, 'active')
     # step 1
     result = flow.apply('print "hello world"')
     self.assertTrue(result.goto_next)
     self.assertEqual(flow.current_step, 'Step2')
     # step 2, wrong action
     result = flow.apply('print "hello world"')
     self.assertFalse(result.goto_next)
     self.assertEqual(flow.current_step, 'Step2')
     # step 2
     result = flow.apply('print 1 + 1')
     self.assertTrue(result.goto_next)
     self.assertEqual(flow.current_step, 'Step2')
     self.assertEqual(flow.state, 'complete')
     # teardown
     flow.teardown_flow()
     self.assertEqual(flow.state, 'destroyed')
Beispiel #3
0
 def test_create_flow(self):
     flow = create_flow('trytry.simple_python.tests.simple_python')
     self.assertIsInstance(flow.get_current_step(), Step1)
     self.assertIsInstance(flow.get_next_step(), Step2)
     self.assertEqual(flow.get_prev_step(), None)