コード例 #1
0
ファイル: test_transports.py プロジェクト: djangosms/core
    def test_signals(self):
        from djangosms.core.transports import pre_route
        from djangosms.core.transports import post_route

        s1 = []
        s2 = []

        def before_route(sender=None, **kwargs):
            s1.append(sender)
            self.assertEqual(sender.requests.count(), 0)
        pre_route.connect(before_route)

        def after_route(sender=None, **kwargs):
            s2.append(sender)
            self.assertEqual(sender.requests.count(), 1)
        post_route.connect(after_route)

        from djangosms.core.tests.transports import Dummy
        from djangosms.core.router import route

        def echo(*args, **kwargs):
            return ""

        router = functools.partial(route, table=(
            (r'^\+echo', echo),
            ))

        transport = Dummy("dummy", router=router)
        transport.incoming("test", "+echo")

        self.assertTrue(len(s1), 1)
        self.assertTrue(len(s2), 1)
コード例 #2
0
ファイル: test_transports.py プロジェクト: djangosms/core
    def test_message_error(self):
        from djangosms.core.tests.transports import Dummy
        from djangosms.core.router import route

        def broken(*args, **kwargs):
            raise RuntimeError("test")

        router = functools.partial(route, table=(
            (r'^\+break', broken),
            ))

        transport = Dummy("dummy", router=router)

        from django.conf import settings
        DEBUG = settings.DEBUG
        try:
            settings.DEBUG = False
            import warnings
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                transport.incoming("test", "+break")

            self.assertEqual(len(w), 1)
            self.assertTrue('RuntimeError' in str(w[0]))
        finally:
            settings.DEBUG = DEBUG
コード例 #3
0
ファイル: test_transports.py プロジェクト: djangosms/core
    def test_configuration_error(self):
        from djangosms.core.tests.transports import Dummy
        from djangosms.core.router import route

        router = functools.partial(route, table=(
            (object(),)))

        transport = Dummy("dummy", router=router)

        from django.conf import settings
        DEBUG = settings.DEBUG
        try:
            settings.DEBUG = False
            import warnings
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                transport.incoming("test", "+bad")

            self.assertEqual(len(w), 1)
            self.assertTrue('ImproperlyConfigured' in str(w[0]))
        finally:
            settings.DEBUG = DEBUG