Beispiel #1
0
async def test_quit_command(fx_config):
    fx_config.OWNER_ID = 'U1'
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'kirito')
    bot.add_user('U2', 'PoH')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
    })

    with pytest.raises(SystemExit):
        await quit(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '안녕히 주무세요!'

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
    })

    await quit(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '<@PoH> 이 명령어는 아빠만 사용할 수 있어요!'
Beispiel #2
0
async def test_hassan_handler():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'hunj')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '똑바로 서라 유이',
    })

    assert not await hassan(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '저한테 왜 그러세요 @hunj님?'

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '아무말 대잔치',
    })

    assert await hassan(bot, event)

    assert not bot.call_queue
Beispiel #3
0
async def test_say_command(fx_config):
    fx_config.OWNER_ID = 'U1'
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    test = bot.add_channel('C2', 'test')
    bot.add_user('U1', 'kirito')
    poh = bot.add_user('U2', 'PoH')

    text = '안녕하세요! 하고 유이인 척 하기'

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
    })

    await say(bot, event, None, None, text)

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

    await say(bot, event, test, None, text)

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

    await say(bot, event, None, poh, text)

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

    await say(bot, event, test, poh, text)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('`--channel` 옵션과 `--user` 옵션은 동시에 사용할 수 없어요!')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
    })

    await say(bot, event, None, None, '죽어라!')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '<@PoH> 이 명령어는 아빠만 사용할 수 있어요!'
Beispiel #4
0
def test_create_event():
    event: Hello = create_event('hello', {})
    assert type(event) == Hello
    assert event.type == 'hello'

    event: TeamMigrationStarted = create_event('team_migration_started', {})
    assert type(event) == TeamMigrationStarted
    assert event.type == 'team_migration_started'

    event: BaseEvent = create_event('not exists it', {})
    assert type(event) == UnknownEvent
    assert event.type == 'not exists it'
Beispiel #5
0
def test_create_event():
    event: Hello = create_event("hello", {})
    assert type(event) == Hello
    assert event.type == "hello"

    event: TeamMigrationStarted = create_event("team_migration_started", {})
    assert type(event) == TeamMigrationStarted
    assert event.type == "team_migration_started"

    event: UnknownEvent = create_event("not exists it", {})
    assert type(event) == UnknownEvent
    assert event.type == "not exists it"
Beispiel #6
0
def test_create_event():
    event = create_event({'type': 'hello'})
    assert type(event) == Hello
    assert event.type == 'hello'

    event = create_event({'type': 'team_migration_started'})
    assert type(event) == TeamMigrationStarted
    assert event.type == 'team_migration_started'

    event = create_event({'type': 'not exists it'})
    assert type(event) == Event
    assert event.type == 'not exists it'
Beispiel #7
0
async def test_html_command(fx_sess):
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await html(bot, event, fx_sess, 'section')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('아직 레퍼런스 관련 명령어의 실행준비가 덜 되었어요. 잠시만 기다려주세요!')

    await fetch_html_ref(bot, fx_sess)

    await html(bot, event, fx_sess, 'section')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        ':html: `<section>` - '
        'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section')

    await html(bot, event, fx_sess, '쀍뗗')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '비슷한 HTML Element를 찾지 못하겠어요!'
Beispiel #8
0
async def test_aqi(fx_aqi_api_token, fx_google_api_key):
    config = AttrDict({
        'AQI_API_TOKEN': fx_aqi_api_token,
        'GOOGLE_API_KEY': fx_google_api_key,
    })
    bot = FakeBot(config)
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.5678',
    })

    await aqi(bot, event, '부천')

    said = bot.call_queue.pop(0)

    if said.data['text'] == '현재 AQI 서버의 상태가 좋지 않아요! 나중에 다시 시도해주세요!':
        pytest.skip('AQI Server problem')
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert result_pattern_re.match(said.data['text'])
    assert said.data['thread_ts'] == '1234.5678'

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

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '해당 주소는 찾을 수 없어요!'
Beispiel #9
0
async def test_welcome_9xd_handler(bot_config):
    bot_config.PREFIX = "."
    bot_config.CHANNELS = {
        "welcome": "C1",
    }
    bot = FakeBot(bot_config)
    bot.add_channel("C1", "general")
    bot.add_user("U1", "kirito")
    event = create_event("team_join", {"user": "******"})

    @bot.response("chat.postMessage")
    def team_join(data):
        return APIResponse(
            body={
                "ok": True,
                "ts": "1234.5678"
            },
            status=200,
            headers={},
        )

    await welcome_9xd(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["text"].startswith("<@U1>님 9XD Slack에 오신걸 환영합니다! :tada:")
    assert "`.도움`" in said.data["text"]

    thread = bot.call_queue.pop(0)
    assert thread.method == "chat.postMessage"
    assert thread.data["channel"] == "C1"
    assert thread.data["text"].startswith(
        "9XD Slack에는 다음과 같은 채널들이 있으니 참가해보셔도 좋을 것 같아요!")
    assert thread.data["thread_ts"] == "1234.5678"
Beispiel #10
0
async def test_book(fx_naver_client_id, fx_naver_client_secret):
    config = AttrDict({
        'NAVER_CLIENT_ID': fx_naver_client_id,
        'NAVER_CLIENT_SECRET': fx_naver_client_secret,
    })
    bot = FakeBot(config)
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '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(ujson.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'] == '검색 결과가 없어요!'
Beispiel #11
0
async def test_welcome_9xd_handler(fx_config):
    fx_config.PREFIX = '.'
    fx_config.CHANNELS = {
        'welcome': 'general',
    }
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'kirito')
    event = create_event('team_join', {'user': {'id': 'U1'}})

    @bot.response('chat.postMessage')
    def team_join(data):
        return APIResponse(
            body={
                'ok': True,
                'ts': '1234.5678'
            },
            status=200,
            headers={},
        )

    await welcome_9xd(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'].startswith('<@U1>님 9XD Slack에 오신걸 환영합니다! :tada:')
    assert '`.도움`' in said.data['text']

    thread = bot.call_queue.pop(0)
    assert thread.method == 'chat.postMessage'
    assert thread.data['channel'] == 'C1'
    assert thread.data['text'].startswith(
        '9XD Slack에는 다음과 같은 채널들이 있으니 참가해보셔도 좋을 것 같아요!')
    assert thread.data['thread_ts'] == '1234.5678'
Beispiel #12
0
async def test_welcome_item4_handler():
    config = AttrDict({
        'PREFIX': '.',
        'CHANNELS': {
            'welcome': 'general',
        },
    })
    bot = FakeBot(config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'kirito')
    event = create_event({
        'type': 'team_join',
        'user': {
            'id': 'U1',
        },
    })

    await welcome_item4(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'].startswith(
        '<@U1>님 item4 개인 Slack에 오신걸 환영합니다! :tada:')
    assert '`.도움`' in said.data['text']
Beispiel #13
0
async def test_select_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })
    seed = 1

    await select(bot, event, ' ', 'cat dog', seed)
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '선택결과: cat'

    await select(bot, event, '/', 'cat/dog', seed)
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '선택결과: cat'

    await select(bot, event, ',', 'cat, dog', seed)
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '선택결과: cat'
Beispiel #14
0
async def test_css_command(fx_sess):
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await css(bot, event, fx_sess, 'font-family')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('아직 레퍼런스 관련 명령어의 실행준비가 덜 되었어요. 잠시만 기다려주세요!')

    await fetch_css_ref(bot, fx_sess)

    await css(bot, event, fx_sess, 'font-family')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        ':css: `font-family` - '
        'https://developer.mozilla.org/en-US/docs/Web/CSS/font-family')

    await css(bot, event, fx_sess, '쀍뗗')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '비슷한 CSS 관련 요소를 찾지 못하겠어요!'
Beispiel #15
0
async def test_dice_handler():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'user')
    event: Message = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '주사위',
    })

    assert not await dice(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'
    assert said.data['username'] == '딜러'
    assert said.data['text'] == (
        '유이가 기도하며 주사위를 굴려줬습니다. 19입니다.'
    )

    assert not await dice(bot, event, '', seed=206)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['as_user'] == '0'
    assert said.data['username'] == '딜러'
    assert said.data['text'] == '콩'

    assert not await dice(bot, event, '', seed=503)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['as_user'] == '0'
    assert said.data['username'] == '딜러'
    assert said.data['text'] == '콩콩'

    assert not await dice(bot, event, 'bug')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['as_user'] == '0'
    assert said.data['username'] == '딜러'
    assert said.data['text'] == '*Error*: Can not parse this chunk (`bug`)'

    assert not await dice(bot, event, '1d6+0', seed=100)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['as_user'] == '0'
    assert said.data['username'] == '딜러'
    assert said.data['text'] == 'd6 == 2'
Beispiel #16
0
async def test_search_aws_zone(fx_sess):
    dt = now()

    bot = FakeBot()
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.5678'
    })

    await search_aws_zone(bot, event, fx_sess, 'name', '인')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과가 없어요!'
    assert said.data['thread_ts'] == '1234.5678'

    record = AWS()
    record.name = '인천'
    record.height = 1234
    record.is_raining = True
    record.rain15 = 111.111
    record.rain60 = 222.222
    record.rain6h = 333.333
    record.rain12h = 444.444
    record.rainday = 555.555
    record.temperature = 12.34
    record.wind_direction1 = 'SSW'
    record.wind_speed1 = 11.11
    record.wind_direction10 = 'NNE'
    record.wind_speed10 = 22.22
    record.humidity = 55
    record.pressure = 1234.56
    record.location = '인천광역시 중구 전동'
    record.observed_at = dt

    with fx_sess.begin():
        fx_sess.add(record)

    await search_aws_zone(bot, event, fx_sess, 'name', '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과는 다음과 같습니다.\n\n인천(인천광역시 중구 전동)'
    assert said.data['thread_ts'] == '1234.5678'

    await search_aws_zone(bot, event, fx_sess, 'location', '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '검색 결과는 다음과 같습니다.\n\n인천(인천광역시 중구 전동)'
    assert said.data['thread_ts'] == '1234.5678'
Beispiel #17
0
async def test_magic_conch():
    config = AttrDict({
        'PREFIX': '.',
    })
    bot = FakeBot(config)
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'text': '마법의 유이님'
    })

    assert await magic_conch(bot, event)

    assert not bot.call_queue

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'text': '마법의 소라고둥님'
    })

    assert not await magic_conch(bot, event)

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

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'text': '마법 소라고동'
    })

    assert not await magic_conch(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] in RESPONSES
Beispiel #18
0
async def test_hi_handler():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'kirito')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '안녕 유이',
    })

    await hi(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '안녕하세요! @kirito'

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '유이 안녕',
    })

    await hi(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '안녕하세요! @kirito'

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
        'text': '아무말 대잔치',
    })

    await hi(bot, event)

    assert not bot.call_queue
Beispiel #19
0
async def test_translate_command(bot):
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await translate(bot, event, None, 'ja', '안녕하세요. 제 이름은 유이에요.'*100)
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '500자 이상의 긴 문장의 번역은 다른 번역기를 사용해주세요!'

    await translate(bot, event, 'php', 'ja', '안녕하세요. 제 이름은 유이에요.')
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '원문 언어가 올바르지 않아요!'

    await translate(bot, event, None, 'ja', '?'*100)
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '원문 언어를 추론하는데에 실패했어요!'

    await translate(bot, event, 'ko', 'php', '안녕하세요. 제 이름은 유이에요.')
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '결과값 언어가 올바르지 않아요!'

    await translate(bot, event, 'ko', 'ko', '안녕하세요. 제 이름은 유이에요.')
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '원문 언어와 결과값 언어가 같아요!'

    await translate(bot, event, 'id', 'th', 'orange')
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '인도네시아어에서 태국어로의 번역은 현재 지원되지 않아요!'

    await translate(bot, event, None, 'ja', '안녕하세요. 제 이름은 유이에요.')
    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '한국어 원문: 안녕하세요. 제 이름은 유이에요.\n'
        '일본어 번역: こんにちは。私の名前はユです。'
    )
Beispiel #20
0
async def test_aqi_none(response_mock):
    response_mock.get(
        'https://maps.googleapis.com/maps/api/geocode/json?' +
        urlencode({
            'address': '부천',
            'key': 'qwer',
        }),
        body=ujson.dumps({
            'results': [
                {
                    'address_components': [
                        {
                            'long_name': '부천',
                        },
                    ],
                    'geometry': {
                        'location': {
                            'lat': 37.5034138,
                            'lng': 126.7660309,
                        },
                    },
                },
            ],
        }),
        headers={'Content-Type': 'application/json'},
    )
    response_mock.get(
        'https://api.waqi.info/feed/geo:37.5034138;126.7660309/?token=asdf',
        body='null',
        headers={'Content-Type': 'application/json'},
    )

    config = AttrDict({
        'AQI_API_TOKEN': 'asdf',
        'GOOGLE_API_KEY': 'qwer',
    })
    bot = FakeBot(config)
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.5678',
    })

    await aqi(bot, event, '부천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('현재 AQI 서버의 상태가 좋지 않아요! 나중에 다시 시도해주세요!')
Beispiel #21
0
async def test_ping_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'user': '******',
    })

    await ping(bot, event)
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '@item4, pong!'
Beispiel #22
0
async def test_about_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.56',
    })

    await about(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == MESSAGE.format(prefix=bot.config.PREFIX)
    assert said.data['thread_ts'] == '1234.56'
Beispiel #23
0
async def test_gdpr_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await gdpr(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert len(ujson.loads(said.data['attachments'])) == 2
    assert said.data['as_user'] == '0'
    assert said.data['username'] == 'G-man'
Beispiel #24
0
async def test_packtpub_dotd():
    bot = FakeBot()
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await packtpub_dotd(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '오늘자 PACKT Book의 무료책이에요!'
    assert said.data['attachments']
Beispiel #25
0
async def test_fallback(fx_config):
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    g = Gacha()

    event: Message = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await g.fallback(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == f'Usage: `{bot.config.PREFIX}help 가챠`'
Beispiel #26
0
async def test_black_market_charge_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
        'ts': '1234.5678',
    })

    await black_market_charge(bot, event, [])
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '거래 건수는 1개 이상 20개 이하로 해주세요!'

    prices = [Decimal(0), Decimal(500_000)
              ] + [Decimal(10_000_000) for _ in range(18)]
Beispiel #27
0
async def test_no_packtpub_dotd(response_mock):
    response_mock.get(PACKTPUB_URL, body='<!doctype html>\n<html></html>')

    bot = FakeBot()
    bot.add_channel('C1', 'general')

    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await packtpub_dotd(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '오늘은 PACKT Book의 무료책이 없는 것 같아요'
Beispiel #28
0
async def test_relax_command():
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    event = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await relax(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '유이에게 나쁜 것을 주입하려는 사악한 재벌은 이 너굴맨이 처리했으니 안심하라구!')
    assert said.data['as_user'] == '0'
    assert said.data['username'] == '너굴맨'
Beispiel #29
0
async def test_welcome_item4_handler(bot_config):
    bot_config.PREFIX = "."
    bot_config.CHANNELS = {
        "welcome": "C1",
    }
    bot = FakeBot(bot_config)
    bot.add_channel("C1", "general")
    bot.add_user("U1", "kirito")
    event = create_event("team_join", {"user": "******"})

    await welcome_item4(bot, event)

    said = bot.call_queue.pop(0)
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["text"].startswith(
        "<@U1>님 item4 개인 Slack에 오신걸 환영합니다! :tada:")
    assert "`.도움`" in said.data["text"]
Beispiel #30
0
async def test_collect(fx_config):
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')
    g = Gacha()

    event: Message = create_event({
        'type': 'message',
        'channel': 'C1',
    })

    await g.collect(bot, event, 30)

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '상품 1개 구입시 30종류의 특전 중 하나를 무작위로 100% 확률로 준다고 가정할 때 '
        '30종류의 특전을 모두 모으려면, 평균적으로 120(`119.85`)개의 상품을 구입해야 '
        '전체 수집에 성공할 수 있어요!')