def test_chopped_url():
    msg = MailRequest('fakeperr', sender, list_addr, open("tests/data/chopped-url.msg").read())
    Router.deliver(msg)
    mlist = MailingList.objects.filter(email = list_addr)[0]
    links = mlist.link_set.all()
    assert len(links) == 2
    assert 'http://www.artic.edu/aic/collections/artwork/34145' in [link.url for link in links]
def test_gzip_attachment():

    clear_queue()
    
    # set up list and message
    name, address = parseaddr(gzip_msg['from'])
    client = RouterConversation(address, 'Files Tests')
    client.begin()
    mlist = mailinglist.find_list(list_name)
    test_subscribe_user(sender=address, client=client, mlist=mlist)
    
    test_subscribe_user(sender=parseaddr(sender)[1], client=sender_client, mlist=mlist)
    gzip_msg['to'] = list_addr

    # deliver the message.
    clear_queue()
    Router.deliver(gzip_msg)

    assert len(mlist.message_set.all()) == 1
    msg = mlist.message_set.all()[0]
    
    assert len(msg.file_set.all()) == 1
    attached = msg.file_set.all()[0]
    path = os.path.join(attached.pathprefix, attached.sha)
    assert attached.name in os.listdir(path)
    assert queue().count() == 1, "Should be 1 message in queue, but there are %s" % queue().count()
def test_long_url_1():
    msg = MailRequest('fakeperr', sender, list_addr, open("tests/data/long-url-1.msg").read())
    Router.deliver(msg)
    mlist = MailingList.objects.filter(email = list_addr)[0]
    links = mlist.link_set.all()
    assert len(links) == 1
    assert 'http://www.google.com/reader/view/#stream/feed%2Fhttp%3A%2F%2Fsethgodin.typepad.com%2Fseths_blog%2Findex.rdf' in [link.url for link in links]
def test_two_urls():
    msg = MailRequest('fakeperr', sender, list_addr, open("tests/data/two-urls.msg").read())
    Router.deliver(msg)
    mlist = MailingList.objects.filter(email = list_addr)[0]
    links = mlist.link_set.all()
    assert len(links) == 2
    assert 'http://www.rolfnelson.com/2009/11/your-work-habits-and-happiness.html' in [link.url for link in links]
    assert 'http://www.rolfnelson.com/2009/11/how-to-follow-through-emerging-science.html' in [link.url for link in links]
def test_complicated_archive_message():
    msg = MailRequest("fakeperr", sender, list_addr, open("tests/data/archive.msg").read())
    Router.deliver(msg)
    mlist = MailingList.objects.filter(email=list_addr)[0]
    messageid = mlist.message_set.all()[0].id
    jsmsg = json.loads(arch[str(messageid)])
    assert jsmsg["body"] == None
    assert len(jsmsg["parts"]) == 2
    assert "opted" in jsmsg["parts"][0]["body"]
    assert len(mlist.message_set.all()) == 1
Beispiel #6
0
def test_talking():

    """
    This message should move the state into
    TALKING.
    """

    msg = MailRequest('fakepeer', sender, "*****@*****.**", open(home("tests/data/emails/question.msg")).read())
    msg['From'] = sender
    Router.deliver(msg)
    q = queue.Queue(email('run/work'))
    assert q.count() == 2, "Queue count is actually %s" % str(q.count())
    assert delivered('Hi There!')
Beispiel #7
0
def test_get_work():

    """
    This message should move the state into
    TALKING.
    """
    # add some work to the work queue
    test_talking()
    
    msg = MailRequest('fakepeer', '*****@*****.**', "*****@*****.**", open(home("tests/data/emails/question.msg")).read())
    msg['From'] = '*****@*****.**'
    
    Router.deliver(msg)
    q = queue.Queue(email('run/work'))
    assert q.count() == 3, "Queue count is actually %s" % str(q.count())
    assert len(Answer.objects.all()) == 4, "Oops. There are actually %s answers in the db, expected 4." % str(len(Answer.objects.all()))
Beispiel #8
0
def test_good_confirmation(msg=None):

    """
    This message should move the state into
    ALERTING.
    """
    alert = create_alert()
    
    addr = "*****@*****.**" % alert.id
    if not msg:
        msg = MailRequest('fakepeer', sender, addr, open(home("tests/data/emails/confirmation.msg")).read())
    msg['to'] = addr
    Router.deliver(msg)
    q = queue.Queue(email('run/alerts'))
    assert q.count() == 0
    assert_in_state('app.handlers.alerts', msg['to'], sender, 'ALERTING') 
def test_two_attachments():
    name, address = parseaddr(deneen_msg['from'])
    client = RouterConversation(address, 'Files Tests')
    test_subscribe_user(sender=address, client=client)
    Router.deliver(two_msg)
    mlist = mailinglist.find_list(list_name)
    assert len(mlist.message_set.all()) == 1

    msg = mlist.message_set.all()[0]
    assert len(msg.file_set.all()) == 2
    attached = msg.file_set.all()[0]
    path = os.path.join(attached.pathprefix, attached.sha)
    assert os.listdir(path)[0] == attached.name

    attached = msg.file_set.all()[1]
    path = os.path.join(attached.pathprefix, attached.sha)
    assert os.listdir(path)[0] == attached.name
Beispiel #10
0
def test_add_karma():
    test_get_work()
    
    ans_u = User.objects.filter(email='*****@*****.**')[0]
    
    u = User.objects.filter(email=sender).all()[0]
    conv = Conversation.objects.filter(user=u).all()[0]
    s = Snip.objects.filter(conversation=conv).all()[0]
    answer = Answer.objects.filter(snip=s).all()[0]
    
    ans = MailRequest('fakepeer', '*****@*****.**', "*****@*****.**" % answer.id, open(home("tests/data/emails/answer.msg")).read())
    ans['From'] = '*****@*****.**'
    ans['To'] = "*****@*****.**" % answer.id
    Router.deliver(ans)
    
    ans_u = User.objects.filter(email='*****@*****.**')[0]
    
    assert ans_u.karma == 0
Beispiel #11
0
def test_incoming_alert():
    """
    Verify an incoming alert generates
    the correct database records.
    """
    alert = create_alert()

    
    msg = MailRequest('fakepeer', sender, "*****@*****.**" % alert.id, open(home("tests/data/emails/alerts.msg")).read())
    msg['to'] = "*****@*****.**" % alert.id
    Router.deliver(msg)

    #Should error out in the alerts.py handlers module in CONFIRMING
    #because these messages are dumped in the alertsq to be handled asyncronously,
    #but the testing environment just sends it to both modules at the same time.
    q = queue.Queue(email('run/error'))
    assert q.count() == 1
    
    assert len(Blurb.objects.all()) == 26, "There are %s blurbs." % len(Blurb.objects.all())
Beispiel #12
0
def test_soft_bounce_tells_them():
    setup()

    # get them into a posting state
    admin_tests.test_existing_user_posts_message()
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    clear_queue()
    assert mailinglist.find_subscriptions(sender, list_addr)

    # force them to soft bounce
    msg = create_bounce(list_addr, sender)
    msg.bounce.primary_status = (3, bounce.PRIMARY_STATUS_CODES[u'3'])
    assert msg.bounce.is_soft()

    Router.deliver(msg)
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')
    assert_in_state('app.handlers.bounce', list_addr, sender, 'BOUNCING')
    assert not delivered('unbounce'), "We shouldn't be sending on bounde."
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
    assert not mailinglist.find_subscriptions(sender, list_addr)

    # make sure that any attempts to post return a "you're bouncing dude" message
    client.say(list_addr, 'So anyway as I was saying.')
    assert not delivered('unbounce')
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')

    # now have them try to unbounce
    msg = client.say('*****@*****.**', "Please put me back on, I'll be good.",
                     'unbounce-confirm')

    # handle the bounce confirmation
    client.say(msg['from'], "Confirmed to unbounce.", 'noreply')

    # alright they should be in the unbounce state for the global bounce handler
    assert_in_state('app.handlers.bounce', list_addr, sender,
                    'UNBOUNCED')

    # and they need to be back to POSTING for regular operations 
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    assert mailinglist.find_subscriptions(sender, list_addr)

    # and make sure that only the original bounce is in the bounce archive
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
Beispiel #13
0
def test_soft_bounce_tells_them():
    setup()

    # get them into a posting state
    admin_tests.test_existing_user_posts_message()
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    clear_queue()
    assert mailinglist.find_subscriptions(sender, list_addr)

    # force them to soft bounce
    msg = create_bounce(list_addr, sender)
    msg.bounce.primary_status = (3, bounce.PRIMARY_STATUS_CODES[u'3'])
    assert msg.bounce.is_soft()

    Router.deliver(msg)
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')
    assert_in_state('app.handlers.bounce', list_addr, sender, 'BOUNCING')
    assert delivered('unbounce'), "Looks like unbounce didn't go out."
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
    assert not mailinglist.find_subscriptions(sender, list_addr)

    # make sure that any attempts to post return a "you're bouncing dude" message
    unbounce = client.say(list_addr, 'So anyway as I was saying.', 'unbounce')
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')

    # now have them try to unbounce
    msg = client.say(unbounce['from'], "Please put me back on, I'll be good.",
                     'unbounce-confirm')

    # handle the bounce confirmation
    client.say(msg['from'], "Confirmed to unbounce.", 'noreply')

    # alright they should be in the unbounce state for the global bounce handler
    assert_in_state('app.handlers.bounce', list_addr, sender,
                    'UNBOUNCED')

    # and they need to be back to POSTING for regular operations 
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    assert mailinglist.find_subscriptions(sender, list_addr)

    # and make sure that only the original bounce is in the bounce archive
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
def test_one_attachment():

    #subscribe the original sender
    name, address = parseaddr(deneen_msg['from'])
    client = RouterConversation(address, 'Files Tests')
    test_subscribe_user(sender=address, client=client)

    # add someone else to the list
    test_subscribe_user(sender=sender, client=sender_client)

    # update the message to send to the list we just created.
    deneen_msg['to'] = list_addr

    Router.deliver(deneen_msg)
    mlist = mailinglist.find_list(list_name)
    assert len(mlist.message_set.all()) == 1
    msg = mlist.message_set.all()[0]
    
    assert len(msg.file_set.all()) == 1
    attached = msg.file_set.all()[0]
    path = os.path.join(attached.pathprefix, attached.sha)
    assert attached.name in os.listdir(path)
    assert_in_state('app.handlers.admin', deneen_msg['to'], address, 'POSTING')
Beispiel #15
0
def test_continue_conversation():

    """
    Start a conversation, get a response, continue the conversation.
    """

    test_talking()
    assert len(Conversation.objects.all()) == 1
    assert len(User.objects.all()) == 1
    u = User.objects.all()[0]
    c = Conversation.objects.all()[0]
    talking.continue_conversation(u)
    assert delivered('Hmmm...')
    c = Conversation.objects.all()[0]
    assert c.pendingprompt == True
    to = "*****@*****.**" % str(c.id)
    msg = MailRequest('fakepeer', sender, to, open(home("tests/data/emails/question.msg")).read())
    msg['to'] = to
    msg['from'] = sender
    #TODO: this doesn't affect state for some reason.
    Router.deliver(msg)
    assert len(Conversation.objects.all()) == 1
    assert len(User.objects.all()) == 1
def test_hard_bounce_disables_user():
    # get them into a posting state
    admin_tests.test_existing_user_posts_message()
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    clear_queue()
    assert mailinglist.find_subscriptions(sender, list_addr)

    # force them to HARD bounce
    msg = create_bounce(list_addr, sender)

    Router.deliver(msg)
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')
    assert_in_state('app.handlers.bounce', list_addr, sender, 'BOUNCING')
    assert not delivered('unbounce'), "A HARD bounce should be silent."
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
    assert not mailinglist.find_subscriptions(sender, list_addr)

    # make sure that any attempts to post return a "you're bouncing dude" message
    unbounce = client.say(list_addr, 'So anyway as I was saying.', 'unbounce')
    assert_in_state('app.handlers.admin', list_addr, sender, 'BOUNCING')

    # now have them try to unbounce
    msg = client.say(unbounce['from'], "Please put me back on, I'll be good.",
                     'unbounce-confirm')

    # handle the bounce confirmation
    client.say(msg['from'], "Confirmed to unbounce.", 'noreply')

    # alright they should be in the unbounce state for the global bounce handler
    assert_in_state('app.handlers.bounce', list_addr, sender, 'UNBOUNCED')

    # and they need to be back to POSTING for regular operations
    assert_in_state('app.handlers.admin', list_addr, sender, 'POSTING')
    assert mailinglist.find_subscriptions(sender, list_addr)

    # and make sure that only the original bounce is in the bounce archive
    assert_equal(len(queue(queue_dir=settings.BOUNCE_ARCHIVE).keys()), 1)
Beispiel #17
0
def test_confirm_then_alert():
    """
    An alert sent after an account is confirmed should go right into
    ALERTING and alert objects should be created in the database.
    """
    alert = create_alert()

    addr = "*****@*****.**" % alert.id

    confirm = MailRequest('fakepeer', sender, addr, open(home("tests/data/emails/confirmation.msg")).read())
    confirm['to'] = addr
    test_good_confirmation(msg=confirm)


    alertsmsg = MailRequest('fakepeer', "different@sender", addr, open(home("tests/data/emails/alerts.msg")).read())
    alertsmsg['to'] = addr
    Router.deliver(alertsmsg)

    # there are 10 alerts in this alert email. since this is the test environment it will be dumped
    # into the alerts queue automatically, which will create the 10 alerts. Then it should be processed
    # by the alerts handler module, dumped into the queue again, thereby upping the alerts queue by one.
    assert len(Blurb.objects.all()) == 26, "There are %s blurbs." % len(Blurb.objects.all())
    q = queue.Queue(email('run/alerts'))
    assert q.count() == 1
Beispiel #18
0
def test_bounce_to_decorator():
    import bounce_filtered_mod
    msg = mail.MailRequest(None,None,None, open("tests/bounce.msg").read())

    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.START, msg)
    assert bounce_filtered_mod.HARD_RAN, "Hard bounce state didn't actually run: %r" % msg.route_to

    msg.bounce.primary_status = (4, u'Persistent Transient Failure')
    Router.clear_states()
    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.START, msg)
    assert bounce_filtered_mod.SOFT_RAN, "Soft bounce didn't actually run."

    msg = mail.MailRequest(None, None, None, open("tests/signed.msg").read())
    Router.clear_states()
    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.END, msg), "Regular messages aren't delivering."
Beispiel #19
0
def test_bounce_to_decorator():
    import bounce_filtered_mod
    msg = mail.MailRequest(None, None, None, open("tests/bounce.msg").read())

    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.START, msg)
    assert bounce_filtered_mod.HARD_RAN, "Hard bounce state didn't actually run: %r" % msg.route_to

    msg.bounce.primary_status = (4, u'Persistent Transient Failure')
    Router.clear_states()
    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.START, msg)
    assert bounce_filtered_mod.SOFT_RAN, "Soft bounce didn't actually run."

    msg = mail.MailRequest(None, None, None, open("tests/signed.msg").read())
    Router.clear_states()
    Router.deliver(msg)
    assert Router.in_state(bounce_filtered_mod.END,
                           msg), "Regular messages aren't delivering."
Beispiel #20
0
def test_spam_sent_by_confirmed_user():
    test_confirmed_user_comments()
    clear_queue("run/posts")

    Router.deliver(make_spam())
Beispiel #21
0
def test_spam_sent_by_unconfirmed_user():
    setup()

    client.begin()
    Router.deliver(make_spam())
Beispiel #22
0
def test_log_handler():
    Router.deliver(message_tests.test_mail_request())
Beispiel #23
0
def test_bad_confirmation():
    Router.deliver(badmsg)
    q = queue.Queue(email('run/error'))
    assert q.count() == 2 #one for the alertsq module and one for alerts
    assert_in_state('app.handlers.alerts', badmsg['to'], sender, 'CONFIRMING')
Beispiel #24
0
def test_queue_handler():
    Router.deliver(message_tests.test_mail_request())