示例#1
0
 def team_join(data):
     return APIResponse(
         body={
             'ok': True,
             'ts': '1234.5678'
         },
         status=200,
         headers={},
     )
示例#2
0
文件: welcome_test.py 项目: item4/yui
 def team_join(data):
     return APIResponse(
         body={
             "ok": True,
             "ts": "1234.5678"
         },
         status=200,
         headers={},
     )
示例#3
0
文件: say_test.py 项目: item4/yui
 def callback(data):
     return APIResponse(
         body={
             "ok": True,
             "channel": {
                 "id": data["users"].split(",")[0].replace("U", "D"),
             },
         },
         status=200,
         headers={},
     )
示例#4
0
 def im_open(data):
     return APIResponse(
         body={
             'ok': True,
             'channel': {
                 'id': data['user'].replace('U', 'D'),
             },
         },
         status=200,
         headers={},
     )
示例#5
0
文件: say_test.py 项目: dev-jelly/yui
 def callback(data):
     return APIResponse(
         body={
             'ok': True,
             'channel': {
                 'id': data['users'].split(',')[0].replace('U', 'D'),
             },
         },
         status=200,
         headers={},
     )
示例#6
0
async def test_call(event_loop, bot_config, response_mock):
    token = 'asdf1234'

    response_mock.post(
        'https://slack.com/api/test11',
        body=json.dumps({'res': 'hello world!'}),
        headers={'content-type': 'application/json'},
        status=200,
    )
    response_mock.post(
        'https://slack.com/api/test12',
        body=json.dumps({
            'res': 'hello world!',
            'data': {
                'extra': 'wow'
            }
        }),
        headers={'content-type': 'application/json'},
        status=200,
    )

    response_mock.post(
        'https://slack.com/api/test21',
        body=json.dumps({'error': 'aaa'}),
        headers={'content-type': 'application/json'},
        status=404,
    )
    response_mock.post(
        'https://slack.com/api/test22',
        body=json.dumps({'error': 'aaa'}),
        headers={'content-type': 'application/json'},
        status=404,
    )
    response_mock.post(
        'https://slack.com/api/test3',
        body=json.dumps({'res': 'hello world!'}),
        headers={'content-type': 'application/json'},
        status=200,
    )

    box = Box()
    bot = Bot(bot_config, event_loop, using_box=box)
    bot.api.throttle_interval = defaultdict(lambda: timedelta(0))

    res = await bot.call('test11')
    assert res == APIResponse(
        body={'res': 'hello world!'},
        status=200,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test12', data={'extra': 'wow'})
    assert res == APIResponse(
        body={
            'res': 'hello world!',
            'data': {
                'extra': 'wow'
            }
        },
        status=200,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test21')
    assert res == APIResponse(
        body={'error': 'aaa'},
        status=404,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test22', data={'extra': 'wow'})
    assert res == APIResponse(
        body={'error': 'aaa'},
        status=404,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test3', token=token)
    assert res == APIResponse(
        body={'res': 'hello world!'},
        status=200,
        headers={'content-type': 'application/json'},
    )
示例#7
0
async def test_call(fx_config, response_mock):
    token = 'asdf1234'

    response_mock.post(
        'https://slack.com/api/test11',
        body=json.dumps({'res': 'hello world!'}),
        headers={'content-type': 'application/json'},
        status=200,
    )
    response_mock.post(
        'https://slack.com/api/test12',
        body=json.dumps({
            'res': 'hello world!',
            'data': {
                'extra': 'wow'
            }
        }),
        headers={'content-type': 'application/json'},
        status=200,
    )

    response_mock.post(
        'https://slack.com/api/test21',
        body=json.dumps({'error': 'aaa'}),
        headers={'content-type': 'application/json'},
        status=404,
    )
    response_mock.post(
        'https://slack.com/api/test22',
        body=json.dumps({'error': 'aaa'}),
        headers={'content-type': 'application/json'},
        status=404,
    )
    response_mock.post(
        'https://slack.com/api/test3',
        body=json.dumps({'res': 'hello world!'}),
        headers={'content-type': 'application/json'},
        status=200,
    )

    box = Box()
    bot = Bot(fx_config, using_box=box)

    res = await bot.call('test11')
    assert res == APIResponse(
        body={'res': 'hello world!'},
        status=200,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test12', data={'extra': 'wow'})
    assert res == APIResponse(
        body={
            'res': 'hello world!',
            'data': {
                'extra': 'wow'
            }
        },
        status=200,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test21')
    assert res == APIResponse(
        body={'error': 'aaa'},
        status=404,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test22', data={'extra': 'wow'})
    assert res == APIResponse(
        body={'error': 'aaa'},
        status=404,
        headers={'content-type': 'application/json'},
    )

    res = await bot.call('test3', token=token)
    assert res == APIResponse(
        body={'res': 'hello world!'},
        status=200,
        headers={'content-type': 'application/json'},
    )
示例#8
0
async def test_call(bot_config, response_mock):
    token = "asdf1234"

    response_mock.post(
        "https://slack.com/api/test11",
        body=json.dumps({"res": "hello world!"}),
        headers={"content-type": "application/json"},
        status=200,
    )
    response_mock.post(
        "https://slack.com/api/test12",
        body=json.dumps({
            "res": "hello world!",
            "data": {
                "extra": "wow"
            }
        }),
        headers={"content-type": "application/json"},
        status=200,
    )

    response_mock.post(
        "https://slack.com/api/test21",
        body=json.dumps({"error": "aaa"}),
        headers={"content-type": "application/json"},
        status=404,
    )
    response_mock.post(
        "https://slack.com/api/test22",
        body=json.dumps({"error": "aaa"}),
        headers={"content-type": "application/json"},
        status=404,
    )
    response_mock.post(
        "https://slack.com/api/test3",
        body=json.dumps({"res": "hello world!"}),
        headers={"content-type": "application/json"},
        status=200,
    )

    box = Box()
    bot = Bot(bot_config, using_box=box)
    bot.api.throttle_interval = defaultdict(lambda: timedelta(0))

    res = await bot.call("test11")
    assert res == APIResponse(
        body={"res": "hello world!"},
        status=200,
        headers={"content-type": "application/json"},
    )

    res = await bot.call("test12", data={"extra": "wow"})
    assert res == APIResponse(
        body={
            "res": "hello world!",
            "data": {
                "extra": "wow"
            }
        },
        status=200,
        headers={"content-type": "application/json"},
    )

    res = await bot.call("test21")
    assert res == APIResponse(
        body={"error": "aaa"},
        status=404,
        headers={"content-type": "application/json"},
    )

    res = await bot.call("test22", data={"extra": "wow"})
    assert res == APIResponse(
        body={"error": "aaa"},
        status=404,
        headers={"content-type": "application/json"},
    )

    res = await bot.call("test3", token=token)
    assert res == APIResponse(
        body={"res": "hello world!"},
        status=200,
        headers={"content-type": "application/json"},
    )