Esempio n. 1
0
class TestBackend(unittest.TestCase):
    def setUp (self):
        self.router = MockRouter()
        self.backend = Backend(self.router)
        self.router.add_backend(self.backend)

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

    def test_start_stop (self):
        self.router.start()
        time.sleep(0.5)
        self.assertTrue(self.backend.running, "backend starts when router starts")
        self.router.stop()
        time.sleep(2.5)
        self.assertFalse(self.backend.running, "backend stops when router stops")
    
    def test_message (self):
        msg = self.backend.message("0000", "Good morning!") 
        self.assertEquals(type(msg), Message, "message() returns a message")

    def test_route (self):
        msg = self.backend.message("0000", "Good morning!") 
        self.backend.route(msg)
        self.assertTrue(self.router.message_waiting, "backend sends to router")
Esempio n. 2
0
class TestMessage(unittest.TestCase):
    def setUp (self):
        self.router = MockRouter()
        self.backend = Backend("testing", self.router)
        self.connection = Connection(self.backend, "12345")
        self.person = Person()
        self.person.add_connection(self.connection)
        #self.router.add_backend(self.backend)
        self.router.backends.append(self.backend)

    def test__init__ (self): 
        msg = Message(self.connection, "this is a test")
        self.assertEquals(msg.connection, self.connection, "connection is right (connection)")
        msg = Message(None, "this is a test", self.person)
        self.assertEquals(msg.connection, self.connection, "connection is right (person)")
        self.assertEquals(msg.text, "this is a test", "text is right")
        self.assertEquals(msg.responses, [], "responses is empty")
        self.assertRaises(Exception, Message)

    def test__unicode__ (self):
        msg = Message(self.connection, "this is a test")
        self.assertEquals(unicode(msg), "this is a test", "unicode is right")
    
    def test_peer (self):
        msg = Message(self.connection, "this is a test")
        self.assertEquals(msg.peer, "12345", "peer identifier is right")

    def test_send (self):
        self.router.start()
        msg = Message(self.connection, "this is a test")
        self.assertTrue(msg.send(), "message was sent")
        waiting = self.backend.next_message()
        self.assertEquals(msg, waiting, "the backend got the message")
        self.router.stop()

    def test_respond (self):
        msg = Message(self.connection, "this is a test")
        msg.respond("how did it go?")
        msg.respond("okay?")
        self.assertEquals(len(msg.responses), 2, "message queues responses")
        self.assertEquals(msg.responses[0].text, "how did it go?", "it went well")
        self.assertEquals(msg.responses[1].text, "okay?", "sure enough")

    def test_flush_responses (self):
        msg = Message(self.connection, "this is a test")
        self.router.start()
        msg.respond("how did it go?")
        msg.flush_responses()
        
        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "how did it go?", "the backend got the message (1)")
        msg.respond("again?")
        msg.respond("and again?")
        msg.flush_responses()

        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "again?", "the backend got the message (2)")
        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "and again?", "the backend got the message (3)")
        self.router.stop()
 def setUp(self):
     self.router = MockRouter()
     self.backend = Backend(self.router)
     self.connection = Connection(self.backend, "12345")
     self.person = Person()
     self.person.add_connection(self.connection)
     self.router.add_backend(self.backend)
Esempio n. 4
0
class TestBackend(unittest.TestCase):
    def setUp(self):
        self.router = MockRouter()
        self.backend = Backend(self.router)
        self.router.add_backend(self.backend)

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

    def test_start_stop(self):
        self.router.start()
        time.sleep(0.5)
        self.assertTrue(self.backend.running,
                        "backend starts when router starts")
        self.router.stop()
        time.sleep(2.5)
        self.assertFalse(self.backend.running,
                         "backend stops when router stops")

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

    def test_route(self):
        msg = self.backend.message("0000", "Good morning!")
        self.backend.route(msg)
        self.assertTrue(self.router.message_waiting, "backend sends to router")
Esempio n. 5
0
 def setUp (self):
     self.router = MockRouter()
     self.backend = Backend("testing", self.router)
     self.connection = Connection(self.backend, "12345")
     self.person = Person()
     self.person.add_connection(self.connection)
     self.router.add_backend(self.backend)
Esempio n. 6
0
 def setUp(self):
     self.router = MockRouter()
     self.backend = Backend(self.router)
     self.router.add_backend(self.backend)
     if not self.apps:
         raise Exception(
             "You must define a list of apps in your TestScript class!")
     for app_class in self.apps:
         app = app_class(self.router)
         self.router.add_app(app)
Esempio n. 7
0
 def setUp (self, default_lang='en'):
     """ default_lang specifies the default language in ISO 639/X
     in in which sms messages are expected (note this code should
     correspond to the contents of contrib/locale/(code)
     (currently, we only support testing one language at a time)
     """
     self.router = MockRouter()
     self.backend = Backend(self.router)
     self.router.add_backend(self.backend)
     if not self.apps:
         raise Exception(
             "You must define a list of apps in your TestScript class!")
     for app_class in self.apps:
         app = app_class(self.router)
         self.router.add_app(app)
     i18n_init(default_lang, [[default_lang]] )
Esempio n. 8
0
 def setUp (self):
     self.router = MockRouter()
     self.backend = Backend(self.router)
     self.router.add_backend(self.backend)
Esempio n. 9
0
 def setUp (self):
     self.router = MockRouter()
     self.backend = Backend(self.router, "testing")
     self.router.add_backend(self.backend)
class TestMessage(unittest.TestCase):
    def setUp(self):
        self.router = MockRouter()
        self.backend = Backend(self.router)
        self.connection = Connection(self.backend, "12345")
        self.person = Person()
        self.person.add_connection(self.connection)
        self.router.add_backend(self.backend)

    def test__init__(self):
        msg = Message(self.connection, "this is a test")
        self.assertEquals(msg.connection, self.connection,
                          "connection is right (connection)")
        msg = Message(None, "this is a test", self.person)
        self.assertEquals(msg.connection, self.connection,
                          "connection is right (person)")
        self.assertEquals(msg.text, "this is a test", "text is right")
        self.assertEquals(msg.responses, [], "responses is empty")
        self.assertRaises(Exception, Message)

    def test__unicode__(self):
        msg = Message(self.connection, "this is a test")
        self.assertEquals(unicode(msg), "this is a test", "unicode is right")

    def test_peer(self):
        msg = Message(self.connection, "this is a test")
        self.assertEquals(msg.peer, "12345", "peer identifier is right")

    def test_send(self):
        self.router.start()
        msg = Message(self.connection, "this is a test")
        self.assertTrue(msg.send(), "message was sent")
        waiting = self.backend.next_message()
        self.assertEquals(msg, waiting, "the backend got the message")
        self.router.stop()

    def test_respond(self):
        msg = Message(self.connection, "this is a test")
        msg.respond("how did it go?")
        msg.respond("okay?")
        self.assertEquals(len(msg.responses), 2, "message queues responses")
        self.assertEquals(msg.responses[0].text, "how did it go?",
                          "it went well")
        self.assertEquals(msg.responses[1].text, "okay?", "sure enough")

    def test_flush_responses(self):
        msg = Message(self.connection, "this is a test")
        self.router.start()
        msg.respond("how did it go?")
        msg.flush_responses()

        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "how did it go?",
                          "the backend got the message (1)")
        msg.respond("again?")
        msg.respond("and again?")
        msg.flush_responses()

        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "again?",
                          "the backend got the message (2)")
        waiting = self.backend.next_message()
        self.assertEquals(waiting.text, "and again?",
                          "the backend got the message (3)")
        self.router.stop()
Esempio n. 11
0
 def setUp(self):
     self.router = MockRouter()
     self.backend = Backend(self.router)
     self.router.add_backend(self.backend)