# # -*- coding: utf-8 -*-
#
# # Copyright (C) 2014-2016 Avencall
# #
# # This program is free software: you can redistribute it and/or modify
# # it under the terms of the GNU 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 General Public License for more details.
# #
# # You should have received a copy of the GNU General Public License
# # along with this program.  If not, see <http://www.gnu.org/licenses/>
#
# import time
#
# from .base_dird_integration_test import BaseDirdIntegrationTest
# from .base_dird_integration_test import VALID_UUID, VALID_TOKEN
#
# from hamcrest import assert_that
# from hamcrest import contains
# from hamcrest import contains_inanyorder
# from hamcrest import equal_to
# from hamcrest import has_entry, has_entries
#
# from xivo_dird import database
# import unittest
#
#
# from sqlalchemy import create_engine
# from sqlalchemy.orm import sessionmaker, scoped_session
#
# from xivo_dao.alchemy.meetingroom import MeetingRoom
# from xivo_dao.alchemy.userfeatures import UserFeatures
#
# import os
# import logging
#
# logger = logging.getLogger(__name__)
#
# Session = sessionmaker()
#
# class DBStarter(BaseDirdIntegrationTest):
#
#     asset = 'database'
#
#
# def setup():
#     DBStarter.setUpClass()
#     db_uri = os.getenv('DB_URI', 'postgresql://asterisk:proformatique@localhost:15432')
#     engine = create_engine(db_uri)
#     database.Base.metadata.bind = engine
#     database.Base.metadata.reflect()
#     database.Base.metadata.drop_all()
#     database.Base.metadata.create_all()
#
#
# def teardown():
#     DBStarter.tearDownClass()
#
#
# class _BaseTest(unittest.TestCase):
#
#     def setUp(self):
#         self._meeting = []
#
#     def _insert_meeting_room(self, meetingrooms):
#         session = Session()
#         for room in meetingrooms:
#             if room.get('user_id'):
#                 session.add(UserFeatures(id=room['user_id']), uuid='')
#             session.add(MeetingRoom(**room))
#             session.flush()
#         session.commit()
#
#     def _clean_table(self):
#         # session = Session()
#         # session.query(MeetingRoom).delete()
#         # session.commit()
#         pass
#
# class TestMeetingRoom(BaseDirdIntegrationTest, _BaseTest):
#
#     asset = 'xivo_meetingroom'
#     uuid = "6fa459ea-ee8a-3ca4-894e-db77e160355e"
#
#     def setUp(self):
#         super(TestMeetingRoom, self).setUp()
#         self._clean_table()
#         self._crud = database.MeetingroomSearchEngine(Session, searched_columns=['name'])
#         self._insert_meeting_room([{'name': 'room', 'display_name': 'display', 'uuid': '111-222', 'room_type': 'static'}])
#
#
#     def test_that_the_lookup_returns_the_expected_result_meetingroom_direct(self):
#         result = self._crud.find(term=u'room')
#
#         assert_that(result[0], has_entries({'display_name': u'display', 'room_type': u'static', 'name': u'room'}))
#
#     # def test_that_lookup_returns_expected_result(self):
#     #     result = self.get_lookup_result('oom', 'default', token=VALID_TOKEN)
#     #
#     #     raise Exception(result.content)
