Ejemplo n.º 1
0
def ANSWERING(message, answer_id=None, snip_id=None, conv_id=None, host=None):
    
    user = talking.get_user(message)

    if answer_id:
        answer = talking.get_answer(answer_id)
        answer.text = talking.scrape_response(message.body())
        answer.save()
        snip = answer.snip
        
        user.add_karma()
        
        if snip.ready_to_moderate():
            modwork = talking.create_mod_email(snip)
            q = queue.Queue("run/work")
            q.push(modwork)

    # we got a moderated response
    elif snip_id:
        snip = talking.get_snip(snip_id)
        talking.create_mod(snip, message)

    #this is the continuation of a conversation
    elif conv_id:
        conv = talking.get_conversation(conv_id)

        # ignore all emails to continue conversations
        # that are currently in the process of being answered
        if conv.pendingprompt:
            # this conversation was just waiting to be started again
            # so create some work already.
            create_work(message, conv)
            send_work(user)
            conv.pendingprompt = False
            conv.save()
        

    # if they have an outstanding conversation, send them
    # the response they've been waiting for if they have enough karma
    if user.enough_karma():
        talking.continue_conversation(user)

    return ANSWERING
Ejemplo n.º 2
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