Exemplo n.º 1
0
async def test_search_aws_zone(fx_sess):
    dt = datetime(2018, 10, 24, 0)

    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

    event = bot.create_message('C1', 'U1', '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'
Exemplo n.º 2
0
from freezegun import freeze_time

import pytest

from yui.apps.date.weekend import auto_weekend_loading
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@freeze_time(datetime(2018, 10, 8, 0))
async def test_weekend_start(bot_config):
    bot_config.CHANNELS['general'] = 'general'
    bot_config.WEEKEND_LOADING_TIME = [0, 12]
    bot = FakeBot(bot_config)
    bot.add_channel('C1', 'general')

    await auto_weekend_loading(bot)

    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('주말로딩… [□□□□□□□□□□□□□□□□□□□□] 0.00%')


@pytest.mark.asyncio
@freeze_time(datetime(2018, 10, 10, 12))
async def test_weekend_half(bot_config):
    bot_config.CHANNELS['general'] = 'general'
    bot_config.WEEKEND_LOADING_TIME = [0, 12]
Exemplo n.º 3
0
from freezegun import freeze_time

import pytest

from yui.apps.info.packtpub import PACKTPUB_URL
from yui.apps.info.packtpub import auto_packtpub_dotd
from yui.apps.info.packtpub import packtpub_dotd
from yui.utils import json
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@freeze_time(datetime(2018, 10, 7))
async def test_no_packtpub_dotd(response_mock):
    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': []}),
        headers={'Content-Type': 'application/json'},
    )

    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

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

    await packtpub_dotd(bot, event)
Exemplo n.º 4
0
from freezegun import freeze_time

import pytest

from yui.apps.date.work import work_end, work_start
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@freeze_time(datetime(2018, 10, 8, 9))
async def test_work_start_monday(fx_config):
    fx_config.CHANNELS['general'] = 'general'
    bot = FakeBot(fx_config)
    bot.add_channel('C1', 'general')

    await work_start(bot)

    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['username'] == '현실부정중인 직장인'
    assert said.data['as_user'] == '0'
    assert said.data['attachments']


@pytest.mark.asyncio
@freeze_time(datetime(2018, 10, 10, 9))
async def test_work_start_normal(fx_config):
    fx_config.CHANNELS['general'] = 'general'
Exemplo n.º 5
0
async def test_aws(fx_sess):
    bot = FakeBot()
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')

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

    await aws(bot, event, fx_sess, '인천')

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

    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 = datetime(2018, 10, 24, 0)

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

    # rain
    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[2018년 10월 24일 00시 00분@인천/인천광역시 중구 전동]'
        ' 강수: 예(15min: 111.111/일일: 555.555)'
        ' / 12.34℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa')
    assert said.data['username'] == '인천 날씨'
    assert said.data['icon_emoji'] == ':umbrella_with_rain_drops:'

    # snow
    record.temperature = -10
    with fx_sess.begin():
        fx_sess.add(record)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[2018년 10월 24일 00시 00분@인천/인천광역시 중구 전동]'
        ' 강수: 예(15min: 111.111/일일: 555.555)'
        ' / -10.0℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa')
    assert said.data['username'] == '인천 날씨'
    assert said.data['icon_emoji'] == ':snowflake:'

    # moon
    record.is_raining = False
    with fx_sess.begin():
        fx_sess.add(record)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[2018년 10월 24일 00시 00분@인천/인천광역시 중구 전동]'
        ' 강수: 아니오'
        ' / -10.0℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa')
    assert said.data['username'] == '인천 날씨'
    assert said.data['icon_emoji'] == ':crescent_moon:'

    # sun
    record.observed_at = datetime(2018, 10, 24, 12)
    with fx_sess.begin():
        fx_sess.add(record)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[2018년 10월 24일 12시 00분@인천/인천광역시 중구 전동]'
        ' 강수: 아니오'
        ' / -10.0℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa')
    assert said.data['username'] == '인천 날씨'
    assert said.data['icon_emoji'] == ':sunny:'

    # we don't know
    record.is_raining = None
    with fx_sess.begin():
        fx_sess.add(record)

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == (
        '[2018년 10월 24일 12시 00분@인천/인천광역시 중구 전동]'
        ' 강수: 모름'
        ' / -10.0℃ / 바람: 남남서 11.11㎧ / 습도: 55% / 해면기압: 1234.56hPa')
    assert said.data['username'] == '인천 날씨'
    assert said.data['icon_emoji'] == ':thinking_face:'

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

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

    await aws(bot, event, fx_sess, '인천')

    said = bot.call_queue.pop(0)
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == ('검색 결과가 여러가지 있어요! 시스템 관리자에게 문의해주세요!')
Exemplo n.º 6
0
import pytest

from time_machine import travel

from yui.apps.info.packtpub import PACKTPUB_URL
from yui.apps.info.packtpub import auto_packtpub_dotd
from yui.apps.info.packtpub import packtpub_dotd
from yui.utils import json
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@travel(datetime(2018, 10, 7), tick=False)
async def test_no_packtpub_dotd(bot, response_mock):
    response_mock.get(
        "https://services.packtpub.com/free-learning-v1/offers"
        "?dateFrom=2018-10-07T00:00:00.000Z&dateTo=2018-10-08T00:00:00.000Z",
        body=json.dumps({"data": []}),
        headers={"Content-Type": "application/json"},
    )

    bot.add_channel("C1", "general")
    bot.add_user("U1", "item4")

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

    await packtpub_dotd(bot, event)

    said = bot.call_queue.pop(0)
Exemplo n.º 7
0
import pytest

from time_machine import travel

from yui.apps.date.weekend import auto_weekend_loading
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@travel(datetime(2018, 10, 8, 0), tick=False)
async def test_weekend_start(bot_config):
    bot_config.CHANNELS["general"] = "C1"
    bot_config.WEEKEND_LOADING_TIME = [0, 12]
    bot = FakeBot(bot_config)
    bot.add_channel("C1", "general")

    await auto_weekend_loading(bot)

    said = bot.call_queue.pop()
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["text"] == "주말로딩… [□□□□□□□□□□□□□□□□□□□□] 0.00%"


@pytest.mark.asyncio
@travel(datetime(2018, 10, 10, 12), tick=False)
async def test_weekend_half(bot_config):
    bot_config.CHANNELS["general"] = "C1"
    bot_config.WEEKEND_LOADING_TIME = [0, 12]
Exemplo n.º 8
0
from freezegun import freeze_time

import pytest

from yui.apps.date.day import holiday
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@freeze_time(datetime(2019, 2, 4))
async def test_holiday_command(bot_config):
    bot = FakeBot(bot_config)
    bot.add_channel('C1', 'general')
    bot.add_user('U1', 'item4')
    event = bot.create_message('C1', 'U1')

    # empty body
    await holiday(bot, event, '')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '2019년 02월 04일: 설날연휴'

    # buggy input
    await holiday(bot, event, '버그발생')
    said = bot.call_queue.pop()
    assert said.method == 'chat.postMessage'
    assert said.data['channel'] == 'C1'
    assert said.data['text'] == '인식할 수 없는 날짜 표현식이에요!'
Exemplo n.º 9
0
import pytest

from time_machine import travel

from yui.apps.date.work import work_end
from yui.apps.date.work import work_start
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@travel(datetime(2018, 10, 8, 9), tick=False)
async def test_work_start_monday(bot_config):
    bot_config.CHANNELS["general"] = "C1"
    bot = FakeBot(bot_config)
    bot.add_channel("C1", "general")

    await work_start(bot)

    said = bot.call_queue.pop()
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["username"] == "현실부정중인 직장인"
    assert not said.data["as_user"]
    assert said.data["attachments"]


@pytest.mark.asyncio
@travel(datetime(2018, 10, 10, 9), tick=False)
async def test_work_start_normal(bot_config):
Exemplo n.º 10
0
import pytest

from time_machine import travel

from yui.apps.date.day import holiday
from yui.utils.datetime import datetime

from ...util import FakeBot


@pytest.mark.asyncio
@travel(datetime(2019, 2, 4), tick=False)
async def test_holiday_command(bot_config):
    bot = FakeBot(bot_config)
    bot.add_channel("C1", "general")
    bot.add_user("U1", "item4")
    event = bot.create_message("C1", "U1")

    # empty body
    await holiday(bot, event, "")
    said = bot.call_queue.pop()
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["text"] == "2019년 02월 04일: 설날연휴"

    # buggy input
    await holiday(bot, event, "버그발생")
    said = bot.call_queue.pop()
    assert said.method == "chat.postMessage"
    assert said.data["channel"] == "C1"
    assert said.data["text"] == "인식할 수 없는 날짜 표현식이에요!"