Exemple #1
0
def test_add_app_class():
    """
    Router.add_app should also accept an instantiated AppBase
    """
    router = BaseRouter()
    router.add_app(AppBase)
    assert_equals(len(router.apps), 1)
Exemple #2
0
def test_no_app_doesnt_raise_error():
    """
    If an INSTALLED_APP does not contain an app module, don't
    raise an exception
    """
    router = BaseRouter()
    app = router.add_app('django.conrib.admin')
    assert_equals(app, None)
Exemple #3
0
def test_add_backend_class():
    """
    Router.add_backend should also accept an instantiated BackendBase
    """
    router = BaseRouter()
    router.add_backend("mockbackend", BackendBase)
    assert_equals(len(router.backends), 1)
    assert_true("mockbackend" in router.backends.keys())
    assert_equals("mockbackend", router.backends['mockbackend'].name)
def test_add_backend_class():
    """
    Router.add_backend should also accept an instantiated BackendBase
    """
    router = BaseRouter()
    router.add_backend("mockbackend", BackendBase)
    assert_equals(len(router.backends), 1)
    assert_true("mockbackend" in router.backends.keys())
    assert_equals("mockbackend", router.backends['mockbackend'].name)
Exemple #5
0
def test_router_finds_apps():
    router = BaseRouter()
    router.add_app("rapidsms.contrib.default")
    from rapidsms.contrib.default.app import App

    assert_equals(len(router.apps), 1)
    app = router.get_app("rapidsms.contrib.default")

    assert_equals(type(app), App)
Exemple #6
0
def test_router_finds_backends():
    """
    Router should find backend with module path
    """
    router = BaseRouter()
    test_backend = "rapidsms.backends.base"
    backend = router.add_backend("mockbackend", test_backend)

    assert_equals(router.backends["mockbackend"], backend)
    assert_equals(len(router.backends), 1)
def test_router_finds_backends():
    """
    Router should find backend with module path
    """
    router = BaseRouter()
    test_backend = "rapidsms.backends.base"
    backend = router.add_backend("mockbackend", test_backend)

    assert_equals(router.backends["mockbackend"], backend)
    assert_equals(len(router.backends), 1)
Exemple #8
0
def test_router_downcases_backend_configs():
    """
    Backend configuration should automatically be lowercased
    """
    router = BaseRouter()
    test_backend = "rapidsms.backends.base"
    test_conf = { "a": 1, "B": 2, "Cc": 3 }

    backend = router.add_backend("mockbackend", test_backend, test_conf)

    assert_equals(len(backend._config), 3)
    assert_equals("a"  in backend._config, True)
    assert_equals("b"  in backend._config, True)
    assert_equals("cc" in backend._config, True)
    assert_equals("B"  in backend._config, False)
    assert_equals("Cc" in backend._config, False)
def test_router_downcases_backend_configs():
    """
    Backend configuration should automatically be lowercased
    """
    router = BaseRouter()
    test_backend = "rapidsms.backends.base"
    test_conf = {"a": 1, "B": 2, "Cc": 3}

    backend = router.add_backend("mockbackend", test_backend, test_conf)

    assert_equals(len(backend._config), 3)
    assert_equals("a" in backend._config, True)
    assert_equals("b" in backend._config, True)
    assert_equals("cc" in backend._config, True)
    assert_equals("B" in backend._config, False)
    assert_equals("Cc" in backend._config, False)
Exemple #10
0
def test_router_calls_all_app_phases():
    class MockMsg(object):
        connection = None
        text = ''
        handled = False

    class MockApp(AppBase):
        start_phases = ["start"]
        incoming_phases = ["filter", "parse", "handle", "default", "cleanup"]
        outgoing_phases = ["outgoing"]
        stop_phases = ["stop"]
        called_phases = []

        def _append_phase(self, phase, *args, **kwargs):
            self.called_phases.append(phase)
            return False

        def __init__(self, router):
            phases = self.start_phases + self.incoming_phases +\
                     self.outgoing_phases + self.stop_phases
            for phase in phases:
                setattr(self, phase, curry(self._append_phase, phase))
            super(MockApp, self).__init__(router)

    router = BaseRouter()
    app = MockApp(router)
    router.apps.append(app)
    router.receive_incoming(MockMsg())
    assert_equals(app.called_phases, app.incoming_phases)
    app.called_phases = []
    router.send_outgoing(MockMsg())
    assert_equals(app.called_phases, app.outgoing_phases)
    app.called_phases = []
    router.start()
    assert_equals(app.called_phases, app.start_phases)
    app.called_phases = []
    router.stop()
    assert_equals(app.called_phases, app.stop_phases)
Exemple #11
0
def test_router_calls_all_app_phases():
    class MockMsg(object):
        connection = None
        text = ''
        handled = False

    class MockApp(AppBase):
        start_phases = ["start"]
        incoming_phases = ["filter", "parse", "handle", "default", "cleanup"]
        outgoing_phases = ["outgoing"]
        stop_phases = ["stop"]
        called_phases = []

        def _append_phase(self, phase, *args, **kwargs):
            self.called_phases.append(phase)
            return False

        def __init__(self, router):
            phases = self.start_phases + self.incoming_phases +\
                     self.outgoing_phases + self.stop_phases
            for phase in phases:
                setattr(self, phase, curry(self._append_phase, phase))
            super(MockApp, self).__init__(router)

    router = BaseRouter()
    app = MockApp(router)
    router.apps.append(app)
    router.receive_incoming(MockMsg())
    assert_equals(app.called_phases, app.incoming_phases)
    app.called_phases = []
    router.send_outgoing(MockMsg())
    assert_equals(app.called_phases, app.outgoing_phases)
    app.called_phases = []
    router.start()
    assert_equals(app.called_phases, app.start_phases)
    app.called_phases = []
    router.stop()
    assert_equals(app.called_phases, app.stop_phases)
Exemple #12
0
def test_router_raises_on_uninstalled_apps():
    assert_raises(KeyError, BaseRouter().get_app, "rapidsms.contrib.default")
Exemple #13
0
def test_router_returns_none_on_invalid_apps():
    assert_equals(BaseRouter().get_app("not.a.valid.app"), None)