def test_SlackRequest():
    s = SlackRequest('xoxoxoxox', "blah.get", {"meh": "blah"})
    print s

    e = EventRouter()
    e.receive(s)
    e.handle_next()
def test_SlackRequest():
    s = SlackRequest('xoxoxoxox', "blah.get", {"meh": "blah"})
    print s

    e = EventRouter()
    e.receive(s)
    e.handle_next()
Example #3
0
def realish_eventrouter(mock_websocket, mock_weechat):
    e = EventRouter()
    context = e.store_context(SlackRequest('xoxs-token', 'rtm.start', {}))
    with open('_pytest/data/http/rtm.start.json') as rtmstartfile:
        if sys.version_info.major == 2:
            rtmstartdata = rtmstartfile.read().decode('utf-8')
        else:
            rtmstartdata = rtmstartfile.read()
        e.receive_httprequest_callback(context, '', 0, rtmstartdata, '')
    while len(e.queue):
        e.handle_next()
    for team in e.teams.values():
        team.ws = mock_websocket
    return e
Example #4
0
def realish_eventrouter(mock_websocket, mock_weechat):
    e = EventRouter()
    wee_slack.EVENTROUTER = e
    context = e.store_context(SlackRequest('xoxs-token', 'rtm.start', {}))
    with open('_pytest/data/http/rtm.start.json') as rtmstartfile:
        if sys.version_info.major == 2:
            rtmstartdata = rtmstartfile.read().decode('utf-8')
        else:
            rtmstartdata = rtmstartfile.read()
        e.receive_httprequest_callback(context, '', 0, rtmstartdata, '')
    while len(e.queue):
        e.handle_next()
    for team in e.teams.values():
        team.ws = mock_websocket
    return e
Example #5
0
def realish_eventrouter():
    e = EventRouter()
    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"}))
    rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read()
    e.receive_httprequest_callback(context, 1, 0, rtmstartdata, 4)
    e.handle_next()
    #e.sc is just shortcuts to these items
    e.sc = {}
    e.sc["team_id"] = e.teams.keys()[0]
    e.sc["team"] = e.teams[e.sc["team_id"]]
    e.sc["user"] = e.teams[e.sc["team_id"]].users[e.teams[e.sc["team_id"]].users.keys()[0]]
    socket = mock_websocket
    e.teams[e.sc["team_id"]].ws = socket

    return e
Example #6
0
def realish_eventrouter(mock_websocket, mock_weechat):
    e = EventRouter()
    wee_slack.EVENTROUTER = e
    context = e.store_context(initiate_connection("xoxs-token"))
    with open("_pytest/data/http/rtm.start.json") as rtmstartfile:
        if sys.version_info.major == 2:
            rtmstartdata = rtmstartfile.read().decode("utf-8")
        else:
            rtmstartdata = rtmstartfile.read()
        e.receive_httprequest_callback(context, "", 0, rtmstartdata, "")
    while len(e.queue):
        e.handle_next()
    for team in e.teams.values():
        team.ws = mock_websocket
    return e
Example #7
0
def realish_eventrouter():
    e = EventRouter()
    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"}))
    rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read()
    e.receive_httprequest_callback(context, 1, 0, rtmstartdata, 4)
    e.handle_next()
    #e.sc is just shortcuts to these items
    e.sc = {}
    e.sc["team_id"] = e.teams.keys()[0]
    e.sc["team"] = e.teams[e.sc["team_id"]]
    e.sc["user"] = e.teams[e.sc["team_id"]].users[e.teams[e.sc["team_id"]].users.keys()[0]]
    socket = mock_websocket
    e.teams[e.sc["team_id"]].ws = socket

    return e
Example #8
0
def test_EventRouter(mock_weechat):
    # Sending valid json adds to the queue.
    e = EventRouter()
    e.receive_json('{}')
    assert len(e.queue) == 1

    # Handling an event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['testfunc'] = lambda x, y: x
    e.receive_json('{"type": "testfunc"}')
    e.handle_next()
    assert len(e.queue) == 0

    # Handling a local event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['local_testfunc'] = lambda x, y: x
    e.receive_json('{"type": "local_testfunc"}')
    e.handle_next()
    assert len(e.queue) == 0

    # Handling an event without an associated processor
    # raises an exception.
    e = EventRouter()
    # Create a function to test we are called
    e.receive_json('{"type": "testfunc"}')
    with pytest.raises(ProcessNotImplemented):
        e.handle_next()
Example #9
0
def test_EventRouter(mock_weechat):
    # Sending valid object adds to the queue.
    e = EventRouter()
    e.receive({})
    assert len(e.queue) == 1

    # Handling an event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['testfunc'] = lambda x, y: x
    e.receive({"type": "testfunc"})
    e.handle_next()
    assert len(e.queue) == 0

    # Handling a local event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['local_testfunc'] = lambda x, y: x
    e.receive({"type": "local_testfunc"})
    e.handle_next()
    assert len(e.queue) == 0

    # Handling an event without an associated processor
    # shouldn't raise an exception.
    e = EventRouter()
    # Create a function to test we are called
    e.receive({"type": "testfunc"})
    e.handle_next()
def test_EventRouter(mock_weechat):
    # Sending valid json adds to the queue.
    e = EventRouter()
    e.receive_json('{}')
    assert len(e.queue) == 1

    # Handling an event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['testfunc'] = lambda x, y: x
    e.receive_json('{"type": "testfunc"}')
    e.handle_next()
    assert len(e.queue) == 0

    # Handling a local event removes from the queue.
    e = EventRouter()
    # Create a function to test we are called
    e.proc['local_testfunc'] = lambda x, y: x
    e.receive_json('{"type": "local_testfunc"}')
    e.handle_next()
    assert len(e.queue) == 0

    # Handling an event without an associated processor
    # raises an exception.
    e = EventRouter()
    # Create a function to test we are called
    e.receive_json('{"type": "testfunc"}')
    with pytest.raises(ProcessNotImplemented):
        e.handle_next()
def test_EventRouterReceivedata(mock_weechat):

    e = EventRouter()
    context = e.store_context(
        SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, -1, ' {"JSON": "MEH", ', 4)
    #print len(e.reply_buffer)
    context = e.store_context(
        SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, -1, ' "JSON2": "MEH", ', 4)
    #print len(e.reply_buffer)
    context = e.store_context(
        SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, 0, ' "JSON3": "MEH"}', 4)
    #print len(e.reply_buffer)
    try:
        e.handle_next()
        e.handle_next()
        e.handle_next()
        e.handle_next()
    except:
        pass

    print e.context
    #assert False

    context = e.store_context(
        SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"}))
    rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read()
    e.receive_httprequest_callback(context, 1, -1, rtmstartdata[:5000], 4)
    e.receive_httprequest_callback(context, 1, 0, rtmstartdata[5000:], 4)
    e.handle_next()

    #print len(e.reply_buffer)

    #print e.teams

    for t in e.teams:
        #print vars(e.teams[t])
        for c in e.teams[t].channels:
            pass
            #print c
        for u in e.teams[t].users:
            pass
Example #12
0
def test_EventRouterReceivedata(mock_weechat):

    e = EventRouter()
    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, -1, ' {"JSON": "MEH", ', 4)
    #print len(e.reply_buffer)
    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, -1, ' "JSON2": "MEH", ', 4)
    #print len(e.reply_buffer)
    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
    print context
    e.receive_httprequest_callback(context, 1, 0, ' "JSON3": "MEH"}', 4)
    #print len(e.reply_buffer)
    try:
        e.handle_next()
        e.handle_next()
        e.handle_next()
        e.handle_next()
    except:
        pass

    print e.context
    #assert False

    context = e.store_context(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"}))
    rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read()
    e.receive_httprequest_callback(context, 1, -1, rtmstartdata[:5000], 4)
    e.receive_httprequest_callback(context, 1, 0, rtmstartdata[5000:], 4)
    e.handle_next()

    #print len(e.reply_buffer)

    #print e.teams

    for t in e.teams:
        #print vars(e.teams[t])
        for c in e.teams[t].channels:
            pass
            #print c
        for u in e.teams[t].users:
            pass