# Path: modules/utils/text.py
# def clean_text(text):
# 
# Path: modules/user_date.py
# async def main(bot, *args, **kwargs):
# 
# Path: modules/user_g.py
# def main(bot, *args, **kwargs):


import unittest
from unittest.mock import patch, MagicMock
from freezegun import freeze_time
from modules.utils import text
from modules import user_cowsay, user_date, user_g
class UserCowsayTestCase(BaseModuleTestCase):

    @patch('os.popen')
    def test_run_module_with_args_should_call_bot_send(self, popen):
        user_cowsay.main(self.bot, 'test', 'message')
        self.assertEqual(self.bot.send.call_count, 1)

    def test_run_module_without_args_should_return_none(self):
        user_cowsay.main(self.bot)
        self.assertEqual(self.bot.send.call_count, 0)


class UserDateTestCase(BaseModuleTestCase):

    @freeze_time('2015-12-14 12:13:14')
    def test_run_module_without_args_should_return_current_datetime(self):
        self.assertEqual(user_date.main(self.bot), '2015-12-14 12:13:14')

    def test_run_module_with_args_should_return_dating_text(self):
        self.assertEqual(user_date.main(self.bot, 'username'), 'обдумав свои чувства, пригласил на свидание username')


class UserGoogleTestCase(BaseModuleTestCase):

    def setUp(self):
        super(UserGoogleTestCase, self).setUp()
        self.bot.settings.google_api_key = 'api-key'

    @patch('modules.user_g.requests.get', lambda *args, **kwargs: MagicMock(content=b'{"responseData": {"results": [{"titleNoFormatting": "hello", "content": "content <b>of the</b> result", "url": "http://example.com"}]}}'))
    def test_run_module_with_args_should_return_search_result(self):

# Path: modules/utils/text.py
# def clean_text(text):
# 
# Path: modules/user_date.py
# async def main(bot, *args, **kwargs):
# 
# Path: modules/user_g.py
# def main(bot, *args, **kwargs):


# Path: tests/test_modules.py
import unittest
from unittest.mock import patch, MagicMock
from freezegun import freeze_time
from modules.utils import text
from modules import user_cowsay, user_date, user_g

class UserCowsayTestCase(BaseModuleTestCase):

    @patch('os.popen')
    def test_run_module_with_args_should_call_bot_send(self, popen):
        user_cowsay.main(self.bot, 'test', 'message')
        self.assertEqual(self.bot.send.call_count, 1)

    def test_run_module_without_args_should_return_none(self):
        user_cowsay.main(self.bot)
        self.assertEqual(self.bot.send.call_count, 0)


class UserDateTestCase(BaseModuleTestCase):

    @freeze_time('2015-12-14 12:13:14')
    def test_run_module_without_args_should_return_current_datetime(self):
        self.assertEqual(user_date.main(self.bot), '2015-12-14 12:13:14')

    def test_run_module_with_args_should_return_dating_text(self):
        self.assertEqual(user_date.main(self.bot, 'username'), 'обдумав свои чувства, пригласил на свидание username')


class UserGoogleTestCase(BaseModuleTestCase):

    def setUp(self):
        super(UserGoogleTestCase, self).setUp()
        self.bot.settings.google_api_key = 'api-key'

    @patch('modules.user_g.requests.get', lambda *args, **kwargs: MagicMock(content=b'{"responseData": {"results": [{"titleNoFormatting": "hello", "content": "content <b>of the</b> result", "url": "http://example.com"}]}}'))
    def test_run_module_with_args_should_return_search_result(self):

        self.assertEqual(user_g.main(self.bot, 'green', 'apples'), 'hello\ncontent of the result\nhttp://example.com')