123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- # -*- coding: utf-8 -*-
- # Copyright (c) 2017 Tomek Wójcik <tomek@bthlabs.pl>
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- #
- """
- q3stats.testing
- ===============
- This module contains testing utilites.
- """
- import json
- import os
- from flask import Response
- from q3stats.lib.config import get_config
- import q3stats.database
- import q3stats.models
- from q3stats.web_app.application import create_app
- class ResponseWrapper(Response):
- @property
- def json(self):
- if not hasattr(self, '_json_data'):
- self._json_data = json.loads(self.get_data().decode('utf-8'))
- return self._json_data
- class BaseQ3StatsTestCase(object):
- """Base class for Q3Stats test cases."""
- CONFIG_PATH = os.path.join(os.getcwd(), 'testing.cfg')
- @classmethod
- def setUpClass(cls):
- cls._config = get_config(cls.CONFIG_PATH)
- q3stats.database.db_engine = q3stats.database.create_engine(
- cls._config
- )
- q3stats.database.db_session = q3stats.database.create_session(
- q3stats.database.db_engine, cls._config
- )
- q3stats.database.Base.metadata.drop_all(
- bind=q3stats.database.db_engine
- )
- q3stats.database.Base.metadata.create_all(
- bind=q3stats.database.db_engine
- )
- @classmethod
- def tearDownClass(cls):
- pass
- class BaseQ3StatsWebAppTestCase(BaseQ3StatsTestCase):
- """Base class for Q3Stats Web App test cases."""
- @classmethod
- def setUpClass(cls):
- super(BaseQ3StatsWebAppTestCase, cls).setUpClass()
- cls.app = create_app(cls.CONFIG_PATH)
- cls.app.response_class = ResponseWrapper
- cls.client = cls.app.test_client()
|