当前位置: 首页>>代码示例>>Python>>正文


Python routing.Router类代码示例

本文整理汇总了Python中lamson.routing.Router的典型用法代码示例。如果您正苦于以下问题:Python Router类的具体用法?Python Router怎么用?Python Router使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_long_url_1

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]
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:7,代码来源:links_tests.py

示例2: test_gzip_attachment

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()
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:26,代码来源:files_tests.py

示例3: test_chopped_url

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]
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:7,代码来源:links_tests.py

示例4: test_two_urls

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]
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:8,代码来源:links_tests.py

示例5: test_complicated_archive_message

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
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:10,代码来源:archive_tests.py

示例6: test_talking

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!')
开发者ID:sfioritto,项目名称:quibbles,代码行数:13,代码来源:talking_tests.py

示例7: test_get_work

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()))
开发者ID:sfioritto,项目名称:quibbles,代码行数:16,代码来源:talking_tests.py

示例8: test_good_confirmation

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') 
开发者ID:sfioritto,项目名称:lookout,代码行数:16,代码来源:alert_tests.py

示例9: test_two_attachments

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
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:17,代码来源:files_tests.py

示例10: test_add_karma

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
开发者ID:sfioritto,项目名称:quibbles,代码行数:18,代码来源:talking_tests.py

示例11: test_incoming_alert

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())
开发者ID:sfioritto,项目名称:lookout,代码行数:19,代码来源:alert_tests.py

示例12: test_soft_bounce_tells_them

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)
开发者ID:3kwa,项目名称:lamson,代码行数:42,代码来源:bounce_tests.py

示例13: _settings_loader

def _settings_loader():
    from lamson.routing import Router
    from lamson.server import Relay, SMTPReceiver
    from lamson import view, queue
    import logging
    import logging.config
    import jinja2

    settings = Settings()
    for attr_name in dir(django_settings):
    	if attr_name.startswith("LAMSON_"):
    		setattr(settings, attr_name.split("LAMSON_")[1].lower(),
             getattr(django_settings, attr_name))

    #logging.config.fileConfig("logging.conf")

    # the relay host to actually send the final message to
    #TODO make debug a parameter to the command
    if hasattr(settings, 'relay_config'):
        settings.relay = Relay(host=settings.relay_config['host'],
                               port=settings.relay_config['port'], debug=1)

    # where to listen for incoming messages
    settings.receiver = SMTPReceiver(settings.receiver_config['host'],
                                     settings.receiver_config['port'])

    Router.defaults(**settings.router_defaults)
    Router.load(settings.handlers)
    #TODO make this a parameter to the command
    Router.RELOAD=True
    #TODO make run a parameter to the command
    Router.UNDELIVERABLE_QUEUE=queue.Queue("run/undeliverable")

    if hasattr(settings, 'template_config'):
        view.LOADER = jinja2.Environment(
            loader=jinja2.PackageLoader(settings.template_config['dir'],
                                        settings.template_config['module']))

    return settings
开发者ID:fitoria,项目名称:django-lamson,代码行数:39,代码来源:lamson_start.py

示例14: test_one_attachment

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')
开发者ID:sfioritto,项目名称:postosaurus-old,代码行数:23,代码来源:files_tests.py

示例15: test_continue_conversation

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
开发者ID:sfioritto,项目名称:quibbles,代码行数:23,代码来源:talking_tests.py


注:本文中的lamson.routing.Router类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。