Exemplo n.º 1
0
    def test_failover(self):
        proto1 = createProtocolDescriptor("Proto1",
            failure=TemporaryFailure(""),
            )
        proto3 = createProtocolDescriptor("Proto3",
            failure=PermanentFailure(""),
            )
        proto4 = createProtocolDescriptor("Proto4",
            failure=Exception(""),
            )
        proto2 = createProtocolDescriptor("Proto2")
        chain = ProtocolChain([proto1], {})

        #Without failover, it should fail
        self.assertRaises(
            ScriptError,
            attrgetter("protocol"),
            chain,
            )

        chain = ProtocolChain([proto1, proto3, proto4, proto2], {})
        self.assertTrue(
            isinstance(chain.protocol, proto2.get_class()),
            )
Exemplo n.º 2
0
    def test_delproto(self):
        proto1 = createProtocolDescriptor("Proto1", {"a":"a"})
        chain = ProtocolChain([proto1], {})
        #Before aquiring, delete does nothing
        del chain.protocol

        #Aquire
        proto = chain.protocol
        #Now we delete
        del chain.protocol
        #Last protocol, can't work now
        self.assertRaises(
            ScriptError,
            attrgetter("protocol"),
            chain,
            )
        #Del again should do nothing
        del chain.protocol
Exemplo n.º 3
0
from django.template import Template, Context

from lib6ko.run import (
    Executer,
    ScriptError,
    )

from lib6ko.tests.mocks.protocols import (
    createProtocolDescriptor,
    FakeConsoleProtocol,
    )
from lib6ko.tests.mocks.models import MockAP

FakeConsole = createProtocolDescriptor("FakeConsole",
    base_protocol_class = FakeConsoleProtocol,
    )


def execute(executer, template, params={}, ap=MockAP(), context_factory=Context):
    return executer.execute_template(template, ap, params, context_factory)

class TestExecuter(unittest.TestCase):
    def test_execute_no_commands(self):
        e = Executer([])

        t = Template("")
        res = execute(e, t)
        self.assertEquals(res, "")

        t = Template("{% for i in a %}{{ i }}{% endfor %}")
Exemplo n.º 4
0
 def test_singlelike(self):
     proto1 = createProtocolDescriptor("Proto1", {"a":"a"})
     chain = ProtocolChain([proto1], {})
     proto = chain.protocol
     self.assertEquals(proto, chain.protocol)