Example #1
0
 def test_moderator_controlled(self):
    self.assertEqual(0, self.mlist1.subscribers.count())
    self.mlist1.moderator_controlled = True
    self.mlist1.save()
    self.mlist1.moderators.add(self.user1)
    self.mlist1.subscribers.add(self.user2)
    self.assertEqual(1, self.mlist1.subscribers.count())
    
    checker = DEFAULT_MAIL_CHECKER(self.mlist1)
    
    # check that non-moderator emails are rejected
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 3', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    incoming = checker.fetch_mail()
    self.assertEqual(len(incoming), 1)
    IncomingMail.objects.process_incoming()
    outgoing = OutgoingMail.objects.all()
    self.assertEqual(len(outgoing), 0)
    income = IncomingMail.objects.get(pk=incoming[0].id)
    self.assertEqual(income.state, 'reject')
    
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 4', 'Who are you. Who who who who.', sent_time=datetime.now() - timedelta(minutes=10))
    incoming = checker.fetch_mail()
    self.assertEqual(len(incoming), 1)
    IncomingMail.objects.process_incoming()
    outgoing = OutgoingMail.objects.all()
    self.assertEqual(len(outgoing), 1)
    income = IncomingMail.objects.get(pk=incoming[0].id)
    self.assertEqual(income.state, 'send')
Example #2
0
 def fetch_mail(self):
    """Fetches mailing and returns True if successful and False if it failed"""
    from interlink.mail import DEFAULT_MAIL_CHECKER
    checker = DEFAULT_MAIL_CHECKER(self)
    try:
       checker.fetch_mail()
       return True
    except:
       traceback.print_exc()
       return False
Example #3
0
 def test_mail_checking(self):
    self.assertEqual(DEFAULT_MAIL_CHECKER, TestMailChecker)
    checker = DEFAULT_MAIL_CHECKER(self.mlist1)
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    self.assertEqual(IncomingMail.objects.all().count(), 0)
    in_mail = checker.fetch_mail()
    self.assertEqual(len(in_mail), 1)
    self.assertEqual(in_mail[0].origin_address, '*****@*****.**')
    self.assertEqual(IncomingMail.objects.all().count(), 1)
    
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 2', 'I like traffic lights A LOT.', sent_time=datetime.now() - timedelta(minutes=15))
    self.assertEqual(MailingList.objects.fetch_all_mail(), [])
    self.assertEqual(IncomingMail.objects.all().count(), 2)
Example #4
0
 def test_incoming_processing(self):
    checker = DEFAULT_MAIL_CHECKER(self.mlist1)
    # send an email from an unknown address
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 1', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    incoming = checker.fetch_mail()
    self.assertEqual(len(incoming), 1)
    self.assertEqual(incoming[0].state, 'raw')
    IncomingMail.objects.process_incoming()
    self.assertEqual(OutgoingMail.objects.all().count(), 1)
    incoming = IncomingMail.objects.get(pk=incoming[0].id)
    self.assertEqual(incoming.state, 'moderate')
    outgoing = OutgoingMail.objects.all()[0]
    self.assertEqual(outgoing.original_mail, incoming)
    self.assertTrue(outgoing.subject.startswith('Moderation Request'))
    
    # send an email from a known address, but not a subscriber
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 2', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    incoming = checker.fetch_mail()
    self.assertEqual(len(incoming), 1)
    self.assertEqual(incoming[0].state, 'raw')
    IncomingMail.objects.process_incoming()
    self.assertEqual(OutgoingMail.objects.all().count(), 2)
    incoming = IncomingMail.objects.get(pk=incoming[0].id)
    self.assertEqual(incoming.state, 'moderate')
    
    # send an email from a subscriber
    self.mlist1.subscribers.add(self.user2)
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 3', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    incoming = checker.fetch_mail()
    self.assertEqual(len(incoming), 1)
    self.assertEqual(incoming[0].state, 'raw')
    IncomingMail.objects.process_incoming()
    self.assertEqual(OutgoingMail.objects.all().count(), 3)
    incoming = IncomingMail.objects.get(pk=incoming[0].id)
    self.assertEqual(incoming.state, 'send')
    outgoing = OutgoingMail.objects.all()[0]
    self.assertTrue(outgoing.subject.startswith(self.mlist1.subject_prefix), outgoing.subject)
Example #5
0
 def test_outgoing_processing(self):
    self.assertEqual(OutgoingMail.objects.all().count(), 0)
    OutgoingMail.objects.send_outgoing()
    checker = DEFAULT_MAIL_CHECKER(self.mlist1)
    
    self.mlist1.subscribers.add(self.user2)
    add_test_incoming(self.mlist1, '*****@*****.**', 'ahoi 3', 'I like traffic lights.', sent_time=datetime.now() - timedelta(minutes=15))
    incoming = checker.fetch_mail()
    IncomingMail.objects.process_incoming()
    outgoing = OutgoingMail.objects.all()[0]
    self.assertEqual(outgoing.sent, None)
    OutgoingMail.objects.send_outgoing()
    incoming = IncomingMail.objects.get(pk=incoming[0].id)
    outgoing = OutgoingMail.objects.all()[0]
    self.assertNotEqual(outgoing.sent, None)
    self.assertEqual(incoming.state, 'sent')