# Path: tests/politicos_api/base.py
# class BaseTestCase(AsyncHTTPTestCase):
#     def get_app(self):
#         app = Application()
#         loop = asyncio.get_event_loop()
#         app.init_with_loop(loop)
#         # FIXME
#         # app.es = None
#         # app.cache = None
#         # app.redis = None
#         return app
# 
# def get_json_mock(filename):
#     filename = os.path.join('handlers', filename)
#     json_file = os.path.join(os.path.dirname(__file__), filename)
#     with open(json_file) as es_main_response:
#         return load(es_main_response)


import asyncio
from ujson import loads
from unittest.mock import patch
from tests.politicos_api.base import BaseTestCase, get_json_mock
# Copyright (c) 2018, Marcelo Jorge Vieira <metal@alucinados.com>
#
#  This program is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Affero General Public License as published by the
#  Free Software Foundation, either version 3 of the License, or (at your
#  option) any later version.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
#  for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with this program. If not, see <http://www.gnu.org/licenses/>.




class MainHandlerTestCase(BaseTestCase):

    @patch('elasticsearch_async.AsyncElasticsearch.search')
    def test_main_handler(self, search_mock):
        f = asyncio.Future()
        es_main_response = get_json_mock('es_main_response.json')
        f.set_result(es_main_response)
        search_mock.return_value = f

        response = self.fetch('/api/v1/candidacies')

        self.assertEqual(response.code, 200)

# Path: tests/politicos_api/base.py
# class BaseTestCase(AsyncHTTPTestCase):
#     def get_app(self):
#         app = Application()
#         loop = asyncio.get_event_loop()
#         app.init_with_loop(loop)
#         # FIXME
#         # app.es = None
#         # app.cache = None
#         # app.redis = None
#         return app
# 
# def get_json_mock(filename):
#     filename = os.path.join('handlers', filename)
#     json_file = os.path.join(os.path.dirname(__file__), filename)
#     with open(json_file) as es_main_response:
#         return load(es_main_response)


# Path: tests/politicos_api/handlers/test_main.py
import asyncio
from ujson import loads
from unittest.mock import patch
from tests.politicos_api.base import BaseTestCase, get_json_mock

# Copyright (c) 2018, Marcelo Jorge Vieira <metal@alucinados.com>
#
#  This program is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Affero General Public License as published by the
#  Free Software Foundation, either version 3 of the License, or (at your
#  option) any later version.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
#  for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with this program. If not, see <http://www.gnu.org/licenses/>.




class MainHandlerTestCase(BaseTestCase):

    @patch('elasticsearch_async.AsyncElasticsearch.search')
    def test_main_handler(self, search_mock):
        f = asyncio.Future()
        es_main_response = get_json_mock('es_main_response.json')
        f.set_result(es_main_response)
        search_mock.return_value = f

        response = self.fetch('/api/v1/candidacies')

        self.assertEqual(response.code, 200)

        api_main_response = get_json_mock('api_main_response.json')