Example #1
0
 def stop(self):
     # call superclass to stop--sets self._running
     # to False so that the 'run' loop will exit cleanly.
     BackendBase.stop(self)
     
     # logout from googlevoice
     if self.voice is not None:
         self.voice.logout()
Example #2
0
 def test_backend_has_model(self):
     backend = BackendBase(None, "mock")
     # the row should be created when .model is called.
     self.assertEqual(backend.model.__class__, Backend)
     self.assertEqual(backend.model.name, "mock")
     # check that the backend stub was committed to the db.
     self.assertEqual(Backend.objects.filter(name="mock").count(), 1)
Example #3
0
class TestBackendBase(unittest.TestCase):
    def setUp(self):
        self.router = MockRouter()
        self.backend = BackendBase(self.router, "testing")
        self.router.backends.append(self.backend)

    def test__properties(self):
        self.assertEquals(self.backend.name, "testing")
        self.assertEquals(self.backend.title, "Testing")
        self.assertEquals(self.backend.router, self.router)
        self.assertFalse(self.backend.running)

    def test_message(self):
        msg = self.backend.message("0000", "Good morning!") 
        self.assertEquals(type(msg), IncomingMessage, "message() returns an incomingmessage")

    def test_route(self):
        msg = self.backend.message("0000", "Good morning!") 
        self.backend.route(msg)
        self.assertTrue(msg in self.router.incoming, "backend routes to router")
Example #4
0
 def start(self):
     try:
         self.sent_messages = 0
         self.failed_messages = 0
         self.received_messages = 0
         
         self.info("Connecting via googlevoice...")
         self.voice = Voice()
         
         result = self.voice.login(email=self.config.get('login','email'), passwd=self.config.get('login','password'))
         #if result is None:
         #    raise #TODO find the exception this should raise
         
         # call the superclass to start the run loop -- it just sets
         # ._running to True and calls run, but let's not duplicate it.
         BackendBase.start(self)
         
     except:
         if getattr(self, "voice", None):
             self.voice.logout()
         
         raise
 def add_backend(self, name, module_name, config=None):
     """
     Find the backend named *module_name*, instantiate it, and add it
     to the dict of backends to be polled for incoming messages, once
     the router is started. Return the backend instance.
     """
     if not inspect.isclass(module_name):
         cls = BackendBase.find(module_name)
         if cls is None: return None
     else:
         cls = module_name
     config = self._clean_backend_config(config or {})
     backend = cls(self, name, **config)
     self.backends[name] = backend
     return backend
Example #6
0
def test_backend_has_model():
    backend = BackendBase(None, "mock")
    from ...models import Backend as B

    # before fetching the model via BackendBase, check that it does not
    # already exist in the db. (if it does, this test checks nothing.)
    assert_equals(B.objects.filter(name="mock").count(), 0)

    # the row should be created when .model is called.
    assert_equals(backend.model.__class__, B)
    assert_equals(backend.model.name, "mock")

    # check that the backend stub was committed to the db.
    assert_equals(B.objects.filter(name="mock").count(), 1)

    # tidy up the db.
    B.objects.filter(name="mock").delete()
 def add_backend(self, name, module_name, config=None):
     """
     Find the backend named *module_name*, instantiate it, and add it
     to the dict of backends to be polled for incoming messages, once
     the router is started. Return the backend instance.
     """
     if not inspect.isclass(module_name):
         try:
             cls = BackendBase.find(module_name)
         except AttributeError:
             cls = None
     elif issubclass(module_name, BackendBase):
         cls = module_name
     if not cls:
         return None
     config = self._clean_backend_config(config or {})
     backend = cls(self, name, **config)
     self.backends[name] = backend
     return backend
Example #8
0
    def add_backend(self, name, module_name, config=None):
        """
        Add RapidSMS backend to router. Installed backends will be used to
        send outgoing messages.

        :param name: Name of backend.
        :param module_name: :class:`BackendBase <rapidsms.backends.base.BackendBase>`
                            object or dotted path to backend class.
        :returns: :class:`BackendBase <rapidsms.backends.base.BackendBase>`
                  object if found, otherwise a ``ValueError`` exception
                  will be raised.
        """
        if isinstance(module_name, basestring):
            cls = BackendBase.find(module_name)
        elif issubclass(module_name, BackendBase):
            cls = module_name
        if not cls:
            raise ValueError('No such backend "%s"' % module_name)
        config = self._clean_backend_config(config or {})
        backend = cls(self, name, **config)
        self.backends[name] = backend
        return backend
Example #9
0
    def add_backend(self, name, module_name, config=None):
        """
        Add RapidSMS backend to router. Installed backends will be used to
        send outgoing messages.

        :param name: Name of backend.
        :param module_name: :class:`BackendBase <rapidsms.backends.base.BackendBase>`
                            object or dotted path to backend class.
        :returns: :class:`BackendBase <rapidsms.backends.base.BackendBase>`
                  object if found, otherwise a ``ValueError`` exception
                  will be raised.
        """
        if isinstance(module_name, basestring):
            cls = BackendBase.find(module_name)
        elif issubclass(module_name, BackendBase):
            cls = module_name
        if not cls:
            raise ValueError('No such backend "%s"' % module_name)
        config = self._clean_backend_config(config or {})
        backend = cls(self, name, **config)
        self.backends[name] = backend
        return backend
Example #10
0
 def start(self):
     self.bucket = []
     self.outgoing_bucket = []
     BackendBase.start(self)
Example #11
0
 def test_backend_finds_valid_backend_class(self):
     """Class should be returned if valid."""
     backend = BackendBase.find('rapidsms.backends.test_base.TestBackend')
     self.assertEqual(TestBackend, backend)
Example #12
0
def test_backend_finds_valid_backend_classes():
    backend = BackendBase.find('rapidsms.backends.kannel.outgoing')
    from rapidsms.backends.kannel.outgoing import KannelBackend
    assert_equals(backend, KannelBackend)
Example #13
0
 def test_backend_has_name(self):
     backend = BackendBase(None, "mock")
     self.assertEqual(repr(backend), "<backend: mock>")
     self.assertEqual(str(backend), "mock")
     self.assertEqual(backend.name, "mock")
Example #14
0
 def start(self):
     self.bucket = []
     self.outgoing_bucket = []
     BackendBase.start(self)
Example #15
0
def test_backend_has_name():
    backend = BackendBase(None, "mock")

    assert_equals(repr(backend), "<backend: mock>")
    assert_equals(unicode(backend), "mock")
    assert_equals(backend.name, "mock")
Example #16
0
def test_backend_finds_valid_backend_classes():
    backend = BackendBase.find('rapidsms.backends.kannel.outgoing')
    from rapidsms.backends.kannel.outgoing import KannelBackend
    assert_equals(backend, KannelBackend)
Example #17
0
 def setUp(self):
     self.router = MockRouter()
     self.backend = BackendBase(self.router, "testing")
     self.router.backends.append(self.backend)