示例#1
0
 def setUp(self):
     kwargs = {}
     if self.apps:
         kwargs['apps'] = self.apps
     self.backend = self.create_backend({'name': 'mockbackend'})
     self.router = BlockingRouter(**kwargs)
     self.router.start()
示例#2
0
 def setUp(self):
     self.contact = self.create_contact()
     self.backend = self.create_backend({'name': 'mockbackend'})
     self.connection = self.create_connection({
         'backend': self.backend,
         'contact': self.contact
     })
     self.router = BlockingRouter()
示例#3
0
class TestScriptMixin(MockBackendRouter):
    """
    The scripted.TestScript class subclasses unittest.TestCase
    and allows you to define unit tests for your RapidSMS apps
    in the form of a 'conversational' script:
    
        from myapp.app import App as MyApp
        from rapidsms.tests.scripted import TestScript

        class TestMyApp (TestScript):
            apps = (MyApp,)
            testRegister = \"""
               8005551212 > register as someuser
               8005551212 < Registered new user 'someuser' for 8005551212!
            \"""

            testDirectMessage = \"""
               8005551212 > tell anotheruser what's up??
               8005550000 < someuser said "what's up??"
            \"""

    This TestMyApp class would then work exactly as any other
    unittest.TestCase subclass (so you could, for example, call
    unittest.main()).
    """
    apps = None

    def setUp(self):
        kwargs = {}
        if self.apps:
            kwargs['apps'] = self.apps
        self.backend = self.create_backend({'name': 'mockbackend'})
        self.router = BlockingRouter(**kwargs)
        self.router.start()

    def tearDown(self):
        self.router.stop()

    def assertInteraction(self, script):
        self.runParsedScript(self.parseScript(script))

    @classmethod
    def parseScript(cls, script):
        cmds  = []
        for line in map(lambda(x): x.strip(), script.split("\n")):
            if not line or line.startswith("#"): continue
            tokens = re.split(r'([<>])', line, 1)
            num, dir, txt = map(lambda (x):x.strip(), tokens)
            # allow users to optionally put dates in the number
            # 19232922@200804150730
            if "@" in num:
                num, datestr = num.split("@")
                date = datetime.strptime(datestr, "%Y%m%d%H%M")
            else:
                date = datetime.now()
            cmds.append((num, date, dir, txt))
        return cmds
示例#4
0
class OutgoingTest(MockBackendRouter, TestCase):

    def setUp(self):
        self.contact = self.create_contact()
        self.backend = self.create_backend({'name': 'mockbackend'})
        self.connection = self.create_connection({'backend': self.backend,
                                                  'contact': self.contact})
        self.router = BlockingRouter()

    def test_outgoing(self):
        """
        Router.outgoing should call backend.send() method
        and set message.sent flag respectively
        """
        msg = OutgoingMessage(self.connection, 'hello!')
        self.router.outgoing(msg)
        self.assertTrue(msg.sent)
        self.assertEqual(msg, self.outbox[0])
示例#5
0
class OutgoingTest(MockBackendRouter, TestCase):

    def setUp(self):
        self.contact = self.create_contact()
        self.backend = self.create_backend({'name': 'mockbackend'})
        self.connection = self.create_connection({'backend': self.backend,
                                                  'contact': self.contact})
        self.router = BlockingRouter()

    def test_outgoing(self):
        """
        Router.outgoing should call backend.send() method
        and set message.sent flag respectively
        """
        msg = OutgoingMessage(self.connection, 'hello!')
        self.router.send_outgoing(msg)
        self.assertTrue(msg.sent)
        self.assertEqual(msg, self.outbox[0])
示例#6
0
 def setUp(self):
     self.contact = self.create_contact()
     self.backend = self.create_backend({'name': 'mockbackend'})
     self.connection = self.create_connection({'backend': self.backend,
                                               'contact': self.contact})
     self.router = BlockingRouter()