def test_message_delete(self): """ test deleting a message by DELETE """ from radarpost.mailbox import Message message1 = Message(title='Message 1') message2 = Message(title='Message 2') mb = self.create_test_mailbox() slug = get_mailbox_slug(self.config, mb.name) c = self.get_test_app() self.login_as_admin(c) message1.store(mb) message2.store(mb) assert message1.id in mb assert message2.id in mb c.delete(self.url_for('message_rest', mailbox_slug=slug, message_slug=message1.id)) assert message1.id not in mb assert message2.id in mb
def test_mailbox_trim(): """ create a mailbox add some dated messages trim out old messages check correct messages remain check old messages are not present """ from datetime import datetime, timedelta from radarpost.mailbox import Message, trim_mailbox # create a mailbox mb = create_test_mailbox() # insert 10 messages, each one day older # than the next, starting with today. now = datetime.utcnow() delta = timedelta(days=-1) cur = now messages = [] for i in range(10): m = Message() m.timestamp = cur m.store(mb) messages.append(m) cur += delta # all messages should be in the mailbox now for m in messages: assert m.id in mb # get rid of messages older than 5 days trim_mailbox(mb, timedelta(days=5)) for m in messages[:5]: assert m.id in mb for m in messages[5:]: assert not m.id in mb
def test_mailbox_trim_sub(): """ test trimming down a subscription to a maximum number of items. create a mailbox add some dated messages associated with some subscriptions. trim down one of the subscriptions check that old messages are gone and everything else remains """ from datetime import datetime, timedelta from radarpost.mailbox import Message, Subscription, trim_subscription # create a mailbox mb = create_test_mailbox() sub0 = 'sub0' sub1 = 'sub1' sub2 = 'sub2' # insert 10 messages, each one day older # than the next, starting with today. now = datetime.utcnow() delta = timedelta(days=-1) cur = now messages = [] other_messages = [] for i in range(125): m = Message() m.timestamp = cur m.source.subscription_id = sub1 m.store(mb) messages.append(m) # create some similar messages belonging to # different subscriptions bookending the one # we are going to delete from. m2 = Message() m2.timestamp = cur m2.source.subscription_id = sub0 m2.store(mb) other_messages.append(m2) m2 = Message() m2.timestamp = cur m2.source.subscription_id = sub2 m2.store(mb) other_messages.append(m2) cur += delta # all messages should be in the mailbox now for m in messages: assert m.id in mb for m in other_messages: assert m.id in mb subscription = Subscription(id=sub1) trim_subscription(mb, subscription, max_entries=51, batch_size=25) for i, m in enumerate(messages[:51]): assert m.id in mb for i, m in enumerate(messages[51:]): assert not m.id in mb # irrelevant messages should not have been touched. for m in other_messages: assert m.id in mb