Example #1
0
 def setUp(self):
     super(OfflineDistributeTest, self).setUp()
     self.distributor = OfflineDistributor(self.config)
     self.sender = Mock(spec=Sender)
     self.distributor._sender = self.sender
     self.store = self.distributor._store
     self.msg = load_msg('sample')
Example #2
0
class OfflineDistributeTest(BaseTest):
    def setUp(self):
        super(OfflineDistributeTest, self).setUp()
        self.distributor = OfflineDistributor(self.config)
        self.sender = Mock(spec=Sender)
        self.distributor._sender = self.sender
        self.store = self.distributor._store
        self.msg = load_msg('sample')

    def _test_update_no_msgs(self):
        self.assertFalse(self.distributor.update())
        self.assertEqual(self.sender.send.call_count, 0)

    def test_update_nothing_new(self):
        self._test_update_no_msgs()

    def _test_update(self, fileList, *addresses):
        for f in fileList:
            archive_msg(self.store, f, *addresses)

        self.assertTrue(self.distributor.update())

        for user in addresses:
            self.assertEqual(self.store.messages_for_user(user), [])
        self.assertEqual(self.sender.send.call_count, len(addresses))

    def test_update_one_msg_one_addr(self):
        self._test_update(['sample'], u'*****@*****.**')

    def test_update_one_msg_multiple_addr(self):
        self._test_update(['sample2'], u'*****@*****.**', u'*****@*****.**')

    def test_update_multiple_msg_one_addr(self):
        self._test_update(['sample3', 'sample4'], u'*****@*****.**')

    def test_update_multiple_msg_multiple_addr(self):
        self._test_update(['sample5', 'sample7'], u'*****@*****.**',
                          u'*****@*****.**')

    def test_update_old_msgs(self):
        address = u'*****@*****.**'
        archive_msg(self.store, 'sample8', address)
        get_digests(
            self.store,
            address)[0].scheduled_at = datetime.now() - timedelta(days=100)
        self.store._db.session.flush()

        self._test_update_no_msgs()

    def test_update_done_msgs(self):
        address = u'*****@*****.**'
        archive_msg(self.store, 'sample9', address)
        self.store.mark_digest_as_sent(address)

        self._test_update_no_msgs()
Example #3
0
class OfflineDistributeTest(BaseTest):
    def setUp(self):
        super(OfflineDistributeTest, self).setUp()
        self.distributor = OfflineDistributor(self.config)
        self.sender = Mock(spec=Sender)
        self.distributor._sender = self.sender
        self.store = self.distributor._store
        self.msg = load_msg("sample")

    def _test_update_no_msgs(self):
        self.assertFalse(self.distributor.update())
        self.assertEqual(self.sender.send.call_count, 0)

    def test_update_nothing_new(self):
        self._test_update_no_msgs()

    def _test_update(self, fileList, *addresses):
        for f in fileList:
            archive_msg(self.store, f, *addresses)

        self.assertTrue(self.distributor.update())

        for user in addresses:
            self.assertEqual(self.store.messages_for_user(user), [])
        self.assertEqual(self.sender.send.call_count, len(addresses))

    def test_update_one_msg_one_addr(self):
        self._test_update(["sample"], u"*****@*****.**")

    def test_update_one_msg_multiple_addr(self):
        self._test_update(["sample2"], u"*****@*****.**", u"*****@*****.**")

    def test_update_multiple_msg_one_addr(self):
        self._test_update(["sample3", "sample4"], u"*****@*****.**")

    def test_update_multiple_msg_multiple_addr(self):
        self._test_update(["sample5", "sample7"], u"*****@*****.**", u"*****@*****.**")

    def test_update_old_msgs(self):
        address = u"*****@*****.**"
        archive_msg(self.store, "sample8", address)
        get_digests(self.store, address)[0].scheduled_at = datetime.now() - timedelta(days=100)
        self.store._db.session.flush()

        self._test_update_no_msgs()

    def test_update_done_msgs(self):
        address = u"*****@*****.**"
        archive_msg(self.store, "sample9", address)
        self.store.mark_digest_as_sent(address)

        self._test_update_no_msgs()
Example #4
0
 def setUp(self):
     super(OfflineDistributeTest, self).setUp()
     self.distributor = OfflineDistributor(self.config)
     self.sender = Mock(spec=Sender)
     self.distributor._sender = self.sender
     self.store = self.distributor._store
     self.msg = load_msg("sample")
Example #5
0
# This script creates a Distributor and updates its status. As a
# config file, it takes the config.py file that is in the same
# directory.
from config import py
from deliver.distribute import OfflineDistributor
d = OfflineDistributor(py)
d.update()