Пример #1
0
    def test_command_set_actions(self):
        c = Command('testNode', status='executing')
        a = Actions()
        a.setDefault('next')
        c.set_actions(a)

        self.assertEquals(c.actions, a)
Пример #2
0
    def test_getCommand(self):
        iq = self.iq
        cmd = Command(node='test', action='execute')
        iq.addChild(cmd.toElement())

        cmd2 = command.getCommand(iq)
        self.assertEquals(cmd2.toElement().toXml(), cmd.toElement().toXml())
Пример #3
0
 def test_can_process(self):
     node = StartHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='nodeTest', action='next')
     cmd_el = cmd.toElement()
     del cmd_el['sessionid']
     iq.addChild(cmd_el)
     self.assertTrue(node.can_process(iq))
Пример #4
0
    def test_command_addNote(self):
        c = Command('testNode', status='executing')
        n1 = Note('a test note')
        n2 = Note('another')
        c.addNote(n1)
        c.addNote(n2)

        self.assertEquals(len(c.notes), 2)
        self.assertEquals(c.notes[0], n1)
        self.assertEquals(c.notes[1], n2)        
Пример #5
0
    def setUp(self):
        c = Command(node='input', action='execute')
        self.cmd_in = self.iq()
        self.cmd_in.addChild(c.toElement())
        self.getRegistered = Mock(side_effect=utils.good_side_effect(set(['master.local', 'mini.local'])))
        self.getComponents = Mock(side_effect=utils.good_side_effect(collab.COLLAB_COMPONENTS))

        psnodes = disco.DiscoItems()
        [psnodes.append(disco.DiscoItem(testJid, nid)) for nid in set(['master.local', 'mini.local'])]
        self.getPSNodes = Mock(side_effect=utils.good_side_effect(psnodes))

        self.people = ['*****@*****.**', '*****@*****.**']
        jids = disco.DiscoItems()
        [jids.append(disco.DiscoItem(jid.JID(j))) for j in self.people]
        self.getAdmins = self.getPubs = self.getSubs = Mock(side_effect=utils.good_side_effect(jids))
Пример #6
0
    def test_EndPage(self):
        p = pages.EndPage('Im beginning to see the light')
        el = yield p.renderToElement(self.cmd_in, None)
        cmd = Command.fromElement(el)

        self.assertTrue(cmd.actions is None)
        self.assertTrue(cmd.form is None)
        self.assertEquals(len(cmd.notes), 1)
        self.assertEquals(cmd.notes[0].content, 'Im beginning to see the light')
Пример #7
0
    def test_parse_iq(self):
        node = NodeHandler('nodeTest', self.stateMngr, self.pageMngr)
        iq = self.iq
        cmd = Command(node='nodeTest', action='next')
        form = data_form.Form(
            formType='submit',
            formNamespace=collab.COLLAB_NS
            )

        form.addField(data_form.Field(
            var = 'machine',
            value = 'one'
            ))

        cmd.set_form(form)
        iq.addChild(cmd.toElement())

        vals = node._parse_iq(iq)
        self.assertEquals(vals['machine'], 'one')
Пример #8
0
    def test_command_set_form(self):
        c = Command('test', status='executing')
        form = data_form.Form(
            formType='form',
            title=u'Unregister a machine',
            instructions=[u'Please select the machine to be unregistered'],
            formNamespace=collab.COLLAB_NS
            )

        form.addField(data_form.Field(
            var = 'machine',
            label = u'Machine',
            desc = u'Please select a machine domain name',
            required = True,
            fieldType='list-multi',
            options = [data_form.Option(m) for m in ['one', 'two', 'three']]
            ))

        c.set_form(form)

        self.assertEquals(c.form, form)
Пример #9
0
    def test_ConfigureCollabNodeLoadBalancerPage(self):
        p = pages.ConfigureCollabNodeLoadBalancerPage()
        el = yield p.renderToElement(self.cmd_in, None)
        cmd = Command.fromElement(el)

        self.assertTrue(cmd.actions is not None)
        self.assertTrue(cmd.form is not None)

        form = data_form.findForm(cmd.toElement(), collab.COLLAB_NS)
        self.assertTrue(form is not None)
        self.assertTrue('frequency' in form.fields)
        self.assertEquals(form.fields['frequency'].fieldType, 'text-single')
Пример #10
0
    def test_UnregisterMachinePage(self):
        p = pages.UnregisterMachinePage(self.getRegistered)
        el = yield p.renderToElement(self.cmd_in, None)
        cmd = Command.fromElement(el)

        self.assertTrue(self.getRegistered.called)
        self.assertTrue(cmd.actions is not None)
        self.assertTrue(cmd.form is not None)

        form = data_form.findForm(cmd.toElement(), collab.COLLAB_NS)
        self.assertTrue(form is not None)
        self.assertTrue('machines' in form.fields)
        self.assertEquals(form.fields['machines'].fieldType, 'list-multi')
Пример #11
0
    def test_InplaceConfigurePubsubNodePage(self):
        p = pages.InplaceConfigurePubsubNodePage(self.getPSNodes)
        el = yield p.renderToElement(self.cmd_in, None)
        cmd = Command.fromElement(el)

        self.assertTrue(self.getPSNodes.called)
        self.assertTrue(cmd.actions is not None)
        self.assertTrue(cmd.form is not None)

        form = data_form.findForm(cmd.toElement(), collab.COLLAB_NS)
        self.assertTrue(form is not None)
        self.assertTrue('name' in form.fields)
        self.assertEquals(form.fields['name'].fieldType, 'list-single')        
Пример #12
0
    def test_parse_iq_badForm(self):
        node = NodeHandler('nodeTest', self.stateMngr, self.pageMngr)
        iq = self.iq
        cmd = Command(node='nodeTest', action='next')
        form = data_form.Form(
            formType='submit',
            formNamespace='wrong'
            )

        form.addField(data_form.Field(
            var = 'machine',
            value = 'one'
            ))

        form.getValues = Mock(return_value=dict({'machine': 'one'}))
        cmd.set_form(form)
        iq.addChild(cmd.toElement())

        def raises():
            return node._parse_iq(iq)

        self.assertRaises(ValueError, raises)
        self.assertFalse(form.getValues.called)
Пример #13
0
    def test_CreateCollabNodePage(self):
        p = pages.CreateCollabNodePage(self.getRegistered, self.getComponents)
        el = yield p.renderToElement(self.cmd_in, None)
        cmd = Command.fromElement(el)

        self.assertTrue(self.getRegistered.called)
        self.assertTrue(self.getComponents.called)
        self.assertTrue(cmd.actions is not None)
        self.assertTrue(cmd.form is not None)

        form = data_form.findForm(cmd.toElement(), collab.COLLAB_NS)
        self.assertTrue(form is not None)
        self.assertTrue('component' in form.fields)
        self.assertTrue('machine' in form.fields)
        self.assertEquals(form.fields['component'].fieldType, 'list-single')
        self.assertEquals(form.fields['machine'].fieldType, 'list-single')        
Пример #14
0
    def test_ConfigurePubsubNodeSubscribersPage(self):
        p = pages.ConfigurePubsubNodeSubscribersPage(self.getSubs)
        p._getOptions = Mock(return_value=[])
        testState = {'name': 'george', 'admins': [], 'publishers': []}
        
        el = yield p.renderToElement(self.cmd_in, testState)
        cmd = Command.fromElement(el)

        self.assertTrue(self.getSubs.called)
        self.assertTrue(p._getOptions.called)
        self.assertTrue(cmd.actions is not None)
        self.assertTrue(cmd.form is not None)

        form = data_form.findForm(cmd.toElement(), collab.COLLAB_NS)
        self.assertTrue(form is not None)
        self.assertTrue('subscribers' in form.fields)
        self.assertEquals(form.fields['subscribers'].fieldType, 'list-multi')        
Пример #15
0
    def test_fromElement(self):
        el = Element((collab.COMMAND_NS, 'command'))
        el['node'] = 'testNode'
        el['sessionid'] = 'sessionid1'
        el['status'] = 'completed'
        
        a = Actions()
        a.setDefault('next')
        el.addChild(a.toElement())

        form = data_form.Form(
            formType='form',
            title=u'Unregister a machine',
            instructions=[u'Please select the machine to be unregistered'],
            formNamespace=collab.COLLAB_NS
            )

        form.addField(data_form.Field(
            var = 'machine',
            label = u'Machine',
            desc = u'Please select a machine domain name',
            required = True,
            fieldType='list-multi',
            options = [data_form.Option(m) for m in ['one', 'two', 'three']]
            ))

        el.addChild(form.toElement())

        n1 = Note('a test note')
        el.addChild(n1.toElement())

        c = Command.fromElement(el)

        self.assertEquals(c.node, 'testNode')
        self.assertEquals(c.defaultUri, collab.COMMAND_NS)
        self.assertEquals(c.status, 'completed')
        self.assertEquals(c.sessionid, 'sessionid1')

        self.assertEquals(len(c.notes), 1)
        self.assertEquals(c.notes[0].toElement().toXml(), n1.toElement().toXml())
        self.assertEquals(c.form.toElement().toXml(), form.toElement().toXml())
        self.assertEquals(c.actions.toElement().toXml(), a.toElement().toXml())        
Пример #16
0
    def test_hasCommand(self):
        iq = self.iq
        cmd = Command(node='test', action='execute')
        iq.addChild(cmd.toElement())

        self.assertTrue(command.hasCommand(iq))
Пример #17
0
 def test_can_process_wrongNode(self):
     node = StartHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='wrongNode', action='cancel')
     iq.addChild(cmd.toElement())
     self.assertFalse(node.can_process(iq))
Пример #18
0
 def test_can_process_notPrev(self):
     prev = PrevHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='nodeTest', action='next')
     iq.addChild(cmd.toElement())
     self.assertFalse(prev.can_process(iq))
Пример #19
0
 def test_can_process(self):
     node = NodeHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='nodeTest', action='next')
     iq.addChild(cmd.toElement())
     self.assertTrue(node.can_process(iq))
Пример #20
0
def makeExecutingCommand(iq, status="executing"):
    cmd = getCommandElement(iq)
    c = Command(node=cmd["node"], status=status)
    if cmd.hasAttribute("sessionid"):
        c.sessionid = cmd["sessionid"]
    return c
Пример #21
0
    def setUp(self):
        def iq():
            iq = Element((None, "iq"))
            iq["type"] = "set"
            iq["to"] = "*****@*****.**"
            iq["from"] = "*****@*****.**"
            iq["id"] = "id1"
            return iq

        def cancel():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "cancel"
            return cmd

        def prev():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "prev"
            return cmd

        def nex():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "execute"
            return cmd

        def nex_start():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["action"] = "execute"
            return cmd

        def result_iq():
            iq = Element((None, "iq"))
            iq["type"] = "result"
            iq["to"] = "*****@*****.**"
            iq["from"] = "*****@*****.**"
            iq["id"] = "id1"
            return iq

        self.cancel_iq = iq()
        self.cancel_iq.addChild(cancel())

        self.prev_iq = iq()
        self.prev_iq.addChild(prev())

        self.cmd = Command(node="collabs_nodes_add", status="executing", sessionid="sessionid1")
        actions = Actions()
        actions.setDefault("next")
        self.cmd.set_actions(actions)

        form = data_form.Form(
            formType="form",
            title=u"Unregister a machine",
            instructions=[u"Please select the machine to be unregistered"],
            formNamespace=collab.COLLAB_NS,
        )

        form.addField(
            data_form.Field(
                var="machine",
                label=u"Machine",
                desc=u"Please select a machine domain name",
                required=True,
                fieldType="list-multi",
                options=[data_form.Option(m) for m in set(["master.local", "mini.local"])],
            )
        )
        self.cmd.set_form(form)

        self.next_iq = iq()
        cmd = self.next_iq.addChild(nex())
        x = cmd.addElement("x", defaultUri=data_form.NS_X_DATA)
        x["type"] = "submit"
        field = x.addElement("field")
        field["var"] = "service"
        field.addElement("value", content="something")

        self.next_start_iq = iq()
        self.next_start_iq.addChild(nex_start())

        self.state = dict({"one": 1})
Пример #22
0
class PageManagerTests(unittest.TestCase):

    timeout = 2

    def setUp(self):
        def iq():
            iq = Element((None, "iq"))
            iq["type"] = "set"
            iq["to"] = "*****@*****.**"
            iq["from"] = "*****@*****.**"
            iq["id"] = "id1"
            return iq

        def cancel():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "cancel"
            return cmd

        def prev():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "prev"
            return cmd

        def nex():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["sessionid"] = "sessionid1"
            cmd["action"] = "execute"
            return cmd

        def nex_start():
            cmd = Element((collab.COMMAND_NS, "command"))
            cmd["node"] = "collabs_nodes_add"
            cmd["action"] = "execute"
            return cmd

        def result_iq():
            iq = Element((None, "iq"))
            iq["type"] = "result"
            iq["to"] = "*****@*****.**"
            iq["from"] = "*****@*****.**"
            iq["id"] = "id1"
            return iq

        self.cancel_iq = iq()
        self.cancel_iq.addChild(cancel())

        self.prev_iq = iq()
        self.prev_iq.addChild(prev())

        self.cmd = Command(node="collabs_nodes_add", status="executing", sessionid="sessionid1")
        actions = Actions()
        actions.setDefault("next")
        self.cmd.set_actions(actions)

        form = data_form.Form(
            formType="form",
            title=u"Unregister a machine",
            instructions=[u"Please select the machine to be unregistered"],
            formNamespace=collab.COLLAB_NS,
        )

        form.addField(
            data_form.Field(
                var="machine",
                label=u"Machine",
                desc=u"Please select a machine domain name",
                required=True,
                fieldType="list-multi",
                options=[data_form.Option(m) for m in set(["master.local", "mini.local"])],
            )
        )
        self.cmd.set_form(form)

        self.next_iq = iq()
        cmd = self.next_iq.addChild(nex())
        x = cmd.addElement("x", defaultUri=data_form.NS_X_DATA)
        x["type"] = "submit"
        field = x.addElement("field")
        field["var"] = "service"
        field.addElement("value", content="something")

        self.next_start_iq = iq()
        self.next_start_iq.addChild(nex_start())

        self.state = dict({"one": 1})

    def tearDown(self):
        pass

    def test_PageManager_add_page(self):
        mngr = PageManager()
        p = CommandPage(self.cmd)
        mngr.add_page(p)
        self.assertEquals(len(mngr.pages), 1)
        self.assertEquals(mngr.pages[0], p)

    @defer.inlineCallbacks
    def test_PageManager_cancel_page(self):

        mngr = PageManager()
        mngr.index = 2
        iq = yield mngr.cancel_page(self.cancel_iq, self.state)

        self.assertEquals(mngr.index, 0)

        self.assertEquals(iq["to"], "*****@*****.**")
        self.assertEquals(iq["from"], "*****@*****.**")
        self.assertEquals(iq["id"], "id1")
        self.assertEquals(iq["type"], "result")

        cmd = iq.firstChildElement()
        self.assertEquals(cmd.defaultUri, collab.COMMAND_NS)
        self.assertEquals(cmd["sessionid"], "sessionid1")
        self.assertEquals(cmd["node"], "collabs_nodes_add")
        self.assertEquals(cmd["status"], "canceled")

    @defer.inlineCallbacks
    def test_PageManager_prev_page(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 1
        iq = yield mngr.prev_page(self.prev_iq, self.state)

        self.assertEquals(mngr.index, 0)

        self.assertEquals(iq["to"], "*****@*****.**")
        self.assertEquals(iq["from"], "*****@*****.**")
        self.assertEquals(iq["id"], "id1")
        self.assertEquals(iq["type"], "result")

        cmd = iq.firstChildElement()
        self.assertEquals(cmd.toXml(), self.cmd.toElement().toXml())

    @defer.inlineCallbacks
    def test_PageManager_prev_page_badIndex(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 0
        try:
            yield mngr.prev_page(self.prev_iq, self.state)
        except PageManagerError as e:
            pass

    @defer.inlineCallbacks
    def test_PageManager_prev_page_noPage(self):

        mngr = PageManager()
        mngr.index = 1
        try:
            yield mngr.prev_page(self.prev_iq, self.state)
        except PageManagerError as e:
            pass

    @defer.inlineCallbacks
    def test_PageManager_next_page(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 0
        iq = yield mngr.next_page(self.next_iq, self.state)

        self.assertEquals(mngr.index, 1)

        self.assertEquals(iq["to"], "*****@*****.**")
        self.assertEquals(iq["from"], "*****@*****.**")
        self.assertEquals(iq["id"], "id1")
        self.assertEquals(iq["type"], "result")

        cmd = iq.firstChildElement()
        self.assertEquals(cmd.toXml(), self.cmd.toElement().toXml())

    @defer.inlineCallbacks
    def test_PageManager_next_page_start(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 0
        iq = yield mngr.next_page(self.next_start_iq, self.state)

        self.assertEquals(mngr.index, 1)

        self.assertEquals(iq["to"], "*****@*****.**")
        self.assertEquals(iq["from"], "*****@*****.**")
        self.assertEquals(iq["id"], "id1")
        self.assertEquals(iq["type"], "result")

        cmd = iq.firstChildElement()
        self.assertEquals(cmd.toXml(), self.cmd.toElement().toXml())

    @defer.inlineCallbacks
    def test_PageManager_next_page_badIndex(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 1
        try:
            yield mngr.next_page(self.next_iq, self.state)
        except PageManagerError as e:
            pass

    @defer.inlineCallbacks
    def test_PageManager_next_page_noPage(self):

        mngr = PageManager()
        mngr.index = 0
        try:
            yield mngr.next_page(self.next_iq, self.state)
        except PageManagerError as e:
            pass

    @defer.inlineCallbacks
    def test_PageManager_ready(self):

        mngr = PageManager()
        mngr.add_page(CommandPage(self.cmd))
        mngr.index = 0
        self.assertFalse(mngr.ready())

        iq = yield mngr.next_page(self.next_start_iq, self.state)

        self.assertTrue(mngr.ready())
Пример #23
0
 def test_can_process_hasSessionId(self):
     node = StartHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='nodeTest', action='prev')
     iq.addChild(cmd.toElement())
     self.assertFalse(node.can_process(iq))
Пример #24
0
 def test_can_process(self):
     cancel = CancelHandler('nodeTest', self.stateMngr, self.pageMngr)
     iq = self.iq
     cmd = Command(node='nodeTest', action='cancel')
     iq.addChild(cmd.toElement())
     self.assertTrue(cancel.can_process(iq))
Пример #25
0
 def test_copyCommandElement(self):
     cmd = Command(node='test', action='execute')
     cmd_el = cmd.toElement()
     cmd2 = command.copyCommandElement(cmd_el)
     self.assertEquals(cmd2['node'], cmd_el['node'])
     self.assertEquals(cmd2['sessionid'], cmd_el['sessionid'])
Пример #26
0
 def test_copyCommand(self):
     cmd = Command(node='test', action='execute')
     cmd2 = command.copyCommand(cmd)
     self.assertEquals(cmd2.toElement().toXml(), cmd.toElement().toXml())
Пример #27
0
def cmd():
    c = Command(node='test', action='execute')
    return c.toElement()