Пример #1
0
async def test_book(fx_config, fx_naver_client_id, fx_naver_client_secret):
    fx_config.NAVER_CLIENT_ID = fx_naver_client_id
    fx_config.NAVER_CLIENT_SECRET = fx_naver_client_secret
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

    event = bot.create_message('C1', 'U1', '1234.5678')

    await book(bot, event, '소드 아트 온라인')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    match = book_result_pattern_re.match(said.data['text'])
    assert match
    assert match.group(1) == '소드 아트 온라인'
    assert len(json.loads(said.data['attachments'])) == int(match.group(2))
    assert said.data['thread_ts'] == '1234.5678'

    await book(
        bot,
        event,
        '🙄  🐰😴😰🏄😋😍🍦😮🐖😫🍭🚬🚪🐳😞😎🚠😖🍲🙉😢🚔🐩👪🐮🚍🐎👱🎿😸👩🚇🍟👧🎺😒',
    )

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과가 없어요!'
Пример #2
0
async def test_auto_packtpub_dotd(response_mock, fx_config):
    assert auto_packtpub_dotd.cron.spec == '5 9 * * *'
    product_id = '11223344'
    title = 'test book'
    image_url = 'test url'
    response_mock.get(
        'https://services.packtpub.com/free-learning-v1/offers'
        f'?dateFrom=2018-10-07T00:00:00.000Z&dateTo=2018-10-08T00:00:00.000Z',
        body=json.dumps({
            'data': [{'productId': product_id}],
        }),
        headers={'Content-Type': 'application/json'},
    )
    response_mock.get(
        f'https://static.packt-cdn.com/products/{product_id}/summary',
        body=json.dumps({
            'title': title,
            'coverImage': image_url,
        }),
        headers={'Content-Type': 'application/json'},
    )

    fx_config.CHANNELS = {
        'general': 'general',
    }
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')

    await auto_packtpub_dotd(bot)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '오늘자 PACKT Book의 무료책이에요!'
    attachments = json.loads(said.data['attachments'])
    assert len(attachments) == 1
    assert attachments[0]['fallback'] == f'{title} - {PACKTPUB_URL}'
    assert attachments[0]['title'] == title
    assert attachments[0]['title_link'] == PACKTPUB_URL
    assert attachments[0]['text'] == (
        f'오늘의 Packt Book Deal of The Day: {title} - {PACKTPUB_URL}'
    )
    assert attachments[0]['image_url'] == image_url
Пример #3
0
async def test_write_code_review():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

    event = bot.create_message('C1', 'U1', text='램지 코드 리뷰')
    await write_code_review(bot, event, seed=100)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'

    assert said.data['as_user'] == '0'

    attachments = json.loads(said.data['attachments'])

    assert len(attachments) == 1
    assert attachments[0]['fallback'] == attachments[0]['image_url'] == \
        'https://i.imgur.com/btkBRvc.png'
Пример #4
0
async def test_code_review():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

    event = bot.create_message('C1', 'U1', text='코드 리뷰')

    assert await code_review(bot, event)

    assert not bot.call_queue

    event = bot.create_message('C1', 'U1', text='램지 코드 리뷰')

    assert not await code_review(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert len(json.loads(said.data['attachments'])) == 1
    assert said.data['as_user'] == '0'

    event = bot.create_message('C1', 'U1', text='램지 코드 리뷰')

    assert await code_review(bot, event)
Пример #5
0
def to_test_type(o):
    return json.loads(to_json(o))
Пример #6
0
async def test_update_command(fx_config):
    fx_config.USERS['owner'] = 'U1'
    fx_config.CHANNELS['notice'] = 'general'
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'kirito')
    bot.add_user('U2', 'PoH')

    event = bot.create_message('C1', 'U1')

    await update(bot, event, """
TITLE=패치
FLAG=PATCH
LINK=<https://item4.github.io>
본문1
본문2
본문3
---
TITLE=테스트
FLAG=test
- 테스트 코드가 작성되었습니다.
---
TITLE=새 기능
FLAG=NEW
1. 리스트1
2. 리스트2
3. 리스트3
---
TITLE=위험
FLAG=DANGER
- 위험
- 위험!
- 위험!!
---
TITLE=커스텀
COLOR=123456
임의의 색상 지정
PRETEXT=유이 업데이트 명령 테스트
---
---
본문만 있음
---
TITLE=타이틀만 있음
""")
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '유이 업데이트 명령 테스트'
    attachments = json.loads(said.data['attachments'])
    assert attachments == [
        dict(
            fallback='[patch] 패치: 본문1 본문2 본문3',
            title='[patch] 패치',
            title_link='https://item4.github.io',
            color=FLAG_MAP['patch'],
            text='본문1\n본문2\n본문3',
            fields=[],
        ),
        dict(
            fallback='[test] 테스트: - 테스트 코드가 작성되었습니다.',
            title='[test] 테스트',
            color=FLAG_MAP['test'],
            text='- 테스트 코드가 작성되었습니다.',
            fields=[],
        ),
        dict(
            fallback='[new] 새 기능: 1. 리스트1 2. 리스트2 3. 리스트3',
            title='[new] 새 기능',
            color=FLAG_MAP['new'],
            text='1. 리스트1\n2. 리스트2\n3. 리스트3',
            fields=[],
        ),
        dict(
            fallback='[danger] 위험: - 위험 - 위험! - 위험!!',
            title='[danger] 위험',
            color=FLAG_MAP['danger'],
            text='- 위험\n- 위험!\n- 위험!!',
            fields=[],
        ),
        dict(
            fallback='커스텀: 임의의 색상 지정',
            title='커스텀',
            color='123456',
            text='임의의 색상 지정',
            fields=[],
        ),
        dict(
            fallback='본문만 있음',
            text='본문만 있음',
            fields=[],
        ),
        dict(
            fallback='타이틀만 있음:',
            title='타이틀만 있음',
            fields=[],
        ),
    ]

    event = bot.create_message('C1', 'U2')

    await update(bot, event, '')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '<@PoH> 이 명령어는 아빠만 사용할 수 있어요!'