Пример #1
0
 def setUp(self):
     self.source_contact = self.create_contact(data={'first_name': 'John',
                                                     'last_name': 'Smith'})
     self.dest_contact = self.create_contact(data={'first_name': 'John',
                                                   'last_name': 'Smith'})
     self.backend = self.create_backend(data={'name': 'mockbackend'})
     self.unreg_conn = self.create_connection({'backend': self.backend})
     self.source_conn = self.create_connection({'contact': self.source_contact,
                                                'backend': self.backend,
                                                'identity': '5678'})
     self.dest_conn = self.create_connection({'contact': self.dest_contact,
                                              'backend': self.backend,
                                              'identity': '1234'})
     self.router = MockRouter()
     self.app = BroadcastApp(router=self.router)
     self.rule = self.create_forwarding_rule(data={'keyword': 'abc'})
     self.rule.source.contacts.add(self.source_contact)
Пример #2
0
 def setUp(self):
     self.source_contact = self.create_contact(data={"first_name": "John", "last_name": "Smith"})
     self.dest_contact = self.create_contact(data={"first_name": "John", "last_name": "Smith"})
     self.backend = self.create_backend(data={"name": "mockbackend"})
     self.unreg_conn = self.create_connection({"backend": self.backend})
     self.source_conn = self.create_connection(
         {"contact": self.source_contact, "backend": self.backend, "identity": "5678"}
     )
     self.dest_conn = self.create_connection(
         {"contact": self.dest_contact, "backend": self.backend, "identity": "1234"}
     )
     self.router = MockRouter()
     self.app = BroadcastApp(router=self.router)
     self.rule = self.create_forwarding_rule(data={"keyword": "abc"})
     self.rule.source.contacts.add(self.source_contact)
Пример #3
0
class BroadcastForwardingTest(BroadcastCreateDataTest):
    def setUp(self):
        self.source_contact = self.create_contact(data={"first_name": "John", "last_name": "Smith"})
        self.dest_contact = self.create_contact(data={"first_name": "John", "last_name": "Smith"})
        self.backend = self.create_backend(data={"name": "mockbackend"})
        self.unreg_conn = self.create_connection({"backend": self.backend})
        self.source_conn = self.create_connection(
            {"contact": self.source_contact, "backend": self.backend, "identity": "5678"}
        )
        self.dest_conn = self.create_connection(
            {"contact": self.dest_contact, "backend": self.backend, "identity": "1234"}
        )
        self.router = MockRouter()
        self.app = BroadcastApp(router=self.router)
        self.rule = self.create_forwarding_rule(data={"keyword": "abc"})
        self.rule.source.contacts.add(self.source_contact)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.handle(msg)
        return msg

    def test_non_matching_rule(self):
        """ tests that no response comes for non-matching keywords """
        msg = self._send(self.source_conn, "non-matching-keyword")
        self.assertEqual(len(msg.responses), 0)

    def test_unregistered(self):
        """ tests the response from an unregistered user """
        msg = self._send(self.unreg_conn, "abc")
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.not_registered)

    def test_wrong_group(self):
        """ tests the response from a user in non-source group """
        msg = self._send(self.dest_conn, "abc")
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.not_registered)

    def test_creates_broadcast(self):
        """ tests the response from a user in non-source group """
        msg = self._send(self.source_conn, "abc my-message")
        now = datetime.datetime.now()
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(Broadcast.objects.count(), 1)
        bc = Broadcast.objects.get()
        self.assertDateEqual(bc.date_created, now)
        self.assertDateEqual(bc.date, now)
        self.assertEqual(bc.schedule_frequency, "one-time")
        expected_msg = "From {name} ({number}): {msg} my-message".format(
            name=self.source_contact.name, number=self.source_conn.identity, msg=self.rule.message
        )
        self.assertEqual(bc.body, expected_msg)
        self.assertEqual(list(bc.groups.all()), [self.rule.dest])
        self.assertEqual(msg.responses[0].text, self.app.thank_you)

    def test_unicode_broadcast_body(self):
        """ Make sure unicode strings can be broadcasted """
        text = u"abc " + self.random_unicode_string(2)
        msg = self._send(self.source_conn, text)
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(Broadcast.objects.count(), 1)

    def test_rule_tracking(self):
        """Test the broadcast is correctly associated with the rule via FK."""
        msg = self._send(self.source_conn, "abc my-message")
        self.assertEqual(Broadcast.objects.count(), 1)
        bc = Broadcast.objects.get()
        self.assertEqual(bc.forward, self.rule)
Пример #4
0
class BroadcastForwardingTest(BroadcastCreateDataTest):

    def setUp(self):
        self.source_contact = self.create_contact(data={'first_name': 'John',
                                                        'last_name': 'Smith'})
        self.dest_contact = self.create_contact(data={'first_name': 'John',
                                                      'last_name': 'Smith'})
        self.backend = self.create_backend(data={'name': 'mockbackend'})
        self.unreg_conn = self.create_connection({'backend': self.backend})
        self.source_conn = self.create_connection({'contact': self.source_contact,
                                                   'backend': self.backend,
                                                   'identity': '5678'})
        self.dest_conn = self.create_connection({'contact': self.dest_contact,
                                                 'backend': self.backend,
                                                 'identity': '1234'})
        self.router = MockRouter()
        self.app = BroadcastApp(router=self.router)
        self.rule = self.create_forwarding_rule(data={'keyword': 'abc'})
        self.rule.source.contacts.add(self.source_contact)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.handle(msg)
        return msg

    def test_non_matching_rule(self):
        """ tests that no response comes for non-matching keywords """
        msg = self._send(self.source_conn, 'non-matching-keyword')
        self.assertEqual(len(msg.responses), 0)

    def test_unregistered(self):
        """ tests the response from an unregistered user """
        msg = self._send(self.unreg_conn, 'abc')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.not_registered)

    def test_wrong_group(self):
        """ tests the response from a user in non-source group """
        msg = self._send(self.dest_conn, 'abc')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.not_registered)

    def test_creates_broadcast(self):
        """ tests the response from a user in non-source group """
        msg = self._send(self.source_conn, 'abc my-message')
        now = datetime.datetime.now()
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(Broadcast.objects.count(), 1)
        bc = Broadcast.objects.get()
        self.assertDateEqual(bc.date_created, now)
        self.assertDateEqual(bc.date, now)
        self.assertEqual(bc.schedule_frequency, 'one-time')
        expected_msg = 'From {name} ({number}): {msg} my-message'\
                       .format(name=self.source_contact.name,
                               number=self.source_conn.identity,
                               msg=self.rule.message)
        self.assertEqual(bc.body, expected_msg)
        self.assertEqual(list(bc.groups.all()), [self.rule.dest])
        self.assertEqual(msg.responses[0].text,
                         self.app.thank_you)

    def test_unicode_broadcast_body(self):
        """ Make sure unicode strings can be broadcasted """
        text = u'abc ' + self.random_unicode_string(2)
        msg = self._send(self.source_conn, text)
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(Broadcast.objects.count(), 1)

    def test_rule_tracking(self):
        """Test the broadcast is correctly associated with the rule via FK."""
        msg = self._send(self.source_conn, 'abc my-message')
        self.assertEqual(Broadcast.objects.count(), 1)
        bc = Broadcast.objects.get()
        self.assertEqual(bc.forward, self.rule)