# Path: grazyna/plugins/hs_wiki.py
# @register(cmd='next-meet')
# def next_meet(bot, position: range_int(1)=1):
#     yield from show_meets(bot, position, MEETS_ID)
# 
# @asyncio.coroutine
# def get_html(url):
#     session = ClientSession()
#     try:
#         resp = yield from session.get(url)
#         try:
#             raw_data = yield from resp.read()
#             data = raw_data.decode('utf-8', errors='xmlcharrefreplace')
#             return fromstring_to_html(data)
#         finally:
#             resp.close()
#     finally:
#         session.close()
# 
# @register(cmd='trash')
# def trash(bot):
#     html = yield from get_html(URL_CYCLIC)
#     nodes = html.xpath(LIST_XPATH, id=TRASH_ID)
#     list_data = get_list_of_text_sorted_by_time(nodes)
#     if not list_data:
#         return bot.reply('czysto i pięknie, uzupełnij wiki.')
#     bot.reply(list_data[0])
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)


from grazyna.plugins.hs_wiki import next_meet, get_html, trash
from grazyna.test_mocks.sender import SayMessage
from asynctest import CoroutineMock, patch as async_patch
from lxml.html import fromstring, tostring
from freezegun import freeze_time
from unittest.mock import patch
import pytest
import asyncio
                </span>
            </h2>
            <ul>
                <li>14 listopada 2015,9:00 - 15:00 Code retreat</li>
                <li>4 listopada 2015, 18:00 - MeetJS</li>
            </ul>
        ''') 
    with freeze_time('2016-10-01 12:00:00'),\
            patch('grazyna.plugins.hs_wiki.get_html', get_html):
        yield from next_meet(public_bot)

    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: ¬_¬ no meetings'),
    ]


@pytest.mark.asyncio
def test_next_meet_no_meets(public_bot):

    @asyncio.coroutine
    def get_html(url):
        return fromstring('''
            <h2>
                <span id="Najbli.C5.BCsze_spotkania_tematyczne">
                    lol title
                </span>
            </h2>
            <ul></ul>
        ''') 
    with freeze_time('2016-10-01 12:00:00'),\

# Path: grazyna/plugins/hs_wiki.py
# @register(cmd='next-meet')
# def next_meet(bot, position: range_int(1)=1):
#     yield from show_meets(bot, position, MEETS_ID)
# 
# @asyncio.coroutine
# def get_html(url):
#     session = ClientSession()
#     try:
#         resp = yield from session.get(url)
#         try:
#             raw_data = yield from resp.read()
#             data = raw_data.decode('utf-8', errors='xmlcharrefreplace')
#             return fromstring_to_html(data)
#         finally:
#             resp.close()
#     finally:
#         session.close()
# 
# @register(cmd='trash')
# def trash(bot):
#     html = yield from get_html(URL_CYCLIC)
#     nodes = html.xpath(LIST_XPATH, id=TRASH_ID)
#     list_data = get_list_of_text_sorted_by_time(nodes)
#     if not list_data:
#         return bot.reply('czysto i pięknie, uzupełnij wiki.')
#     bot.reply(list_data[0])
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)


# Path: grazyna/tests/plugins/test_hs_wiki.py
from grazyna.plugins.hs_wiki import next_meet, get_html, trash
from grazyna.test_mocks.sender import SayMessage
from asynctest import CoroutineMock, patch as async_patch
from lxml.html import fromstring, tostring
from freezegun import freeze_time
from unittest.mock import patch
import pytest
import asyncio

                </span>
            </h2>
            <ul>
                <li>14 listopada 2015,9:00 - 15:00 Code retreat</li>
                <li>4 listopada 2015, 18:00 - MeetJS</li>
            </ul>
        ''') 
    with freeze_time('2016-10-01 12:00:00'),\
            patch('grazyna.plugins.hs_wiki.get_html', get_html):
        yield from next_meet(public_bot)

    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: ¬_¬ no meetings'),
    ]


@pytest.mark.asyncio
def test_next_meet_no_meets(public_bot):

    @asyncio.coroutine
    def get_html(url):
        return fromstring('''
            <h2>
                <span id="Najbli.C5.BCsze_spotkania_tematyczne">
                    lol title
                </span>
            </h2>
            <ul></ul>
        ''') 
    with freeze_time('2016-10-01 12:00:00'),\

            patch('grazyna.plugins.hs_wiki.get_html', get_html):