'Test using commands with multiple payloads.'

def testMultiPayloads(self):

    results = []
    def handle_command(iq, session):
        def handle_form(forms, session):
            for form in forms:
                results.append(form.get_values()['FORM_TYPE'])
            session['payload'] = None
        form1 = self.xmpp['xep_0004'].makeForm('form')
        form1.addField(var='FORM_TYPE', ftype='hidden', value='form_1')
        form1.addField(var='foo', ftype='text-single', label='Foo')
        form2 = self.xmpp['xep_0004'].makeForm('form')
        form2.addField(var='FORM_TYPE', ftype='hidden', value='form_2')
        form2.addField(var='foo', ftype='text-single', label='Foo')
        session['payload'] = [form1, form2]
        session['next'] = handle_form
        session['has_next'] = False
        return session
    self.xmpp['xep_0050'].add_command('tester@localhost', 'foo', 'Do    Foo', handle_command)
    self.recv('\n                                        <iq    id="11"    type="set"    to="tester@localhost"    from="foo@bar">\n                                                <command    xmlns="http://jabber.org/protocol/commands"\n                                                                                    node="foo"\n                                                                                    action="execute"    />\n                                        </iq>\n                                ')
    self.send('\n                                        <iq    id="11"    type="result"    to="foo@bar">\n                                                <command    xmlns="http://jabber.org/protocol/commands"\n                                                                                    node="foo"\n                                                                                    status="executing"\n                                                                                    sessionid="_sessionid_">\n                                                        <actions>\n                                                                <complete    />\n                                                        </actions>\n                                                        <x    xmlns="jabber:x:data"    type="form">\n                                                                <field    var="FORM_TYPE"    type="hidden">\n                                                                        <value>form_1</value>\n                                                                </field>\n                                                                <field    var="foo"    label="Foo"    type="text-single"    />\n                                                        </x>\n                                                        <x    xmlns="jabber:x:data"    type="form">\n                                                                <field    var="FORM_TYPE"    type="hidden">\n                                                                        <value>form_2</value>\n                                                                </field>\n                                                                <field    var="foo"    label="Foo"    type="text-single"    />\n                                                        </x>\n                                                </command>\n                                        </iq>\n                                ')
    self.recv('\n                                        <iq    id="12"    type="set"    to="tester@localhost"    from="foo@bar">\n                                                <command    xmlns="http://jabber.org/protocol/commands"\n                                                                                    node="foo"\n                                                                                    action="complete"\n                                                                                    sessionid="_sessionid_">\n                                                    <x    xmlns="jabber:x:data"    type="submit">\n                                                                <field    var="FORM_TYPE"    type="hidden">\n                                                                        <value>form_1</value>\n                                                                </field>\n                                                                <field    var="foo"    type="text-single">\n                                                                        <value>bar</value>\n                                                                </field>\n                                                        </x>\n                                                        <x    xmlns="jabber:x:data"    type="submit">\n                                                                <field    var="FORM_TYPE"    type="hidden">\n                                                                        <value>form_2</value>\n                                                                </field>\n                                                                <field    var="foo"    type="text-single">\n                                                                        <value>bar</value>\n                                                                </field>\n                                                        </x>\n                                                </command>\n                                        </iq>\n                                ')
    self.send('\n                                        <iq    id="12"    type="result"    to="foo@bar">\n                                                <command    xmlns="http://jabber.org/protocol/commands"\n                                                                                    node="foo"\n                                                                                    status="completed"\n                                                                                    sessionid="_sessionid_"    />\n                                        </iq>\n                                ')
    self.assertEqual(results, [['form_1'], ['form_2']], ('Command    handler    was    not    executed:    %s' % results))
