本文整理汇总了Python中lamson.routing.Router.deliver方法的典型用法代码示例。如果您正苦于以下问题:Python Router.deliver方法的具体用法?Python Router.deliver怎么用?Python Router.deliver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lamson.routing.Router
的用法示例。
在下文中一共展示了Router.deliver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_long_url_1
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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]
示例2: test_chopped_url
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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]
示例3: test_gzip_attachment
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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()
示例4: test_two_urls
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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]
示例5: test_complicated_archive_message
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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
示例6: test_talking
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
def test_talking():
"""
This message should move the state into
TALKING.
"""
msg = MailRequest('fakepeer', sender, "[email protected]", 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!')
示例7: test_good_confirmation
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
def test_good_confirmation(msg=None):
"""
This message should move the state into
ALERTING.
"""
alert = create_alert()
addr = "alerts-%[email protected]" % 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')
示例8: test_get_work
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
def test_get_work():
"""
This message should move the state into
TALKING.
"""
# add some work to the work queue
test_talking()
msg = MailRequest('fakepeer', '[email protected]', "[email protected]", open(home("tests/data/emails/question.msg")).read())
msg['From'] = '[email protected]'
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()))
示例9: test_two_attachments
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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
示例10: test_add_karma
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
def test_add_karma():
test_get_work()
ans_u = User.objects.filter(email='[email protected]')[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', '[email protected]', "answer-%[email protected]" % answer.id, open(home("tests/data/emails/answer.msg")).read())
ans['From'] = '[email protected]'
ans['To'] = "answer-%[email protected]" % answer.id
Router.deliver(ans)
ans_u = User.objects.filter(email='[email protected]')[0]
assert ans_u.karma == 0
示例11: test_incoming_alert
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
def test_incoming_alert():
"""
Verify an incoming alert generates
the correct database records.
"""
alert = create_alert()
msg = MailRequest('fakepeer', sender, "alerts-%[email protected]" % alert.id, open(home("tests/data/emails/alerts.msg")).read())
msg['to'] = "alerts-%[email protected]" % 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())
示例12: test_soft_bounce_tells_them
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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)
示例13: test_one_attachment
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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')
示例14: test_continue_conversation
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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 = "conv-%[email protected]" % 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
示例15: test_confirm_then_alert
# 需要导入模块: from lamson.routing import Router [as 别名]
# 或者: from lamson.routing.Router import deliver [as 别名]
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 = "alerts-%[email protected]" % 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', "[email protected]", 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