예제 #1
0
    def test20_conf_store_logger(self):
        '''Make sure that CaptureLogger works and that default logger is created correctly by ConfigurationStore'''
        with ConfigurationStore() as c:
            logger = c.logger
        clog = testlib.CaptureLogger(logger)

        # Check name of the logger
        self.assertEqual(logger.name, ConfigurationStore.DEFAULT_LOGGER_NAME)
        self.assertEqual(logger.level, logging.INFO)

        # Level is INFO so debug should't log
        logger.debug("This is debug")
        expected = []
        self.assertListEqual(expected, clog.get())

        # Make sure logging works
        logger.info("This is info")
        logger.warn("A warning message")
        logger.error("A error occurred")
        expected = [
            {"level": "INFO", "message": "This is info"},
            {"level": "WARNING", "message": "A warning message"},
            {"level": "ERROR", "message": "A error occurred"}
        ]
        self.assertListEqual(expected, clog.get())

        logger.critical("Not a good thing...")
        expected = [{"level": "CRITICAL", "message": "Not a good thing..."}]
        self.assertListEqual(expected, clog.get())

        ConfigurationStore.unload()
예제 #2
0
    def test11_conf_store_conf(self):
        '''Testing passing a config file to ConfigurationStore with local override'''
        ConfigurationStore.unload()
        conf = ConfigurationStore(__file__)

        self.assertEqual(conf.config_dir, self._get_path('config'))
        self.assertEqual(conf.APP, "Config for app.json")
        self.assertEqual(conf.DATA, "override by local.json")
        self.assertEqual(conf.LOCAL_INFO, "local info")
예제 #3
0
    def test12_conf_store_conf_local(self):
        '''Testing passing a config file to ConfigurationStore with local name override'''
        ConfigurationStore.unload()
        conf = ConfigurationStore(__file__, in_local_name="app_local.json")

        self.assertEqual(conf.config_dir, self._get_path('config'))
        self.assertEqual(conf.APP, "Config for app.json")
        self.assertEqual(conf.DATA, "override by app_local.json")

        # Not using assertRaises as LOCAL_INFO is a property and not a function
        try:
            _ = conf.LOCAL_INFO
            exceptionRaised = False
        except AttributeError:
            exceptionRaised = True
        self.assertTrue(exceptionRaised, "Expected AttributeError for conf.LOCAL_INFO")
예제 #4
0
    def test07_conf_store_prod_config_file(self):
        '''Testing passing a config file'''
        forced_conf_file = self._get_path('conf_store_prod', 'conf.json')
        config_file, local_file = ConfigurationStore._search_config(in_config_file=forced_conf_file)

        self.assertEqual(config_file, forced_conf_file)
        self.assertIsNone(local_file)
예제 #5
0
    def test08_conf_store_prod_local_file(self):
        '''Setting a local name'''
        forced_conf_file = self._get_path('conf_store_prod', 'conf.json')
        config_file, local_file = ConfigurationStore._search_config(in_config_file=forced_conf_file, in_local_name="prod_local.json")

        self.assertEqual(config_file, forced_conf_file)
        self.assertEqual(local_file, self._get_path('conf_store_prod', 'prod_local.json'))
예제 #6
0
    def test06_conf_store_prod(self):
        '''Testing simple prod.json and local.json'''
        target_dir = self._get_path('conf_store_prod', 'config')
        config_file, local_file = ConfigurationStore._search_config(in_caller_file=target_dir)

        self.assertEqual(config_file, os.path.join(target_dir, 'prod.json'))
        self.assertEqual(local_file, os.path.join(target_dir, 'local.json'))
예제 #7
0
    def test05_conf_store_uat(self):
        '''Testing uat.json with local name'''
        target_dir = self._get_path('conf_store_uat', 'config')
        config_file, local_file = ConfigurationStore._search_config(in_caller_file=target_dir, in_local_name="conf_local.json")

        self.assertEqual(config_file, os.path.join(target_dir, 'uat.json'))
        self.assertEqual(local_file, os.path.join(target_dir, 'conf_local.json'))
예제 #8
0
    def test04_conf_store_uat(self):
        '''Testing simple uat.json'''
        target_dir = self._get_path('conf_store_uat', 'config')
        config_file, local_file = ConfigurationStore._search_config(in_caller_file=target_dir)

        self.assertEqual(config_file, os.path.join(target_dir, 'uat.json'))
        self.assertIsNone(local_file)
예제 #9
0
    def test10_conf_store(self):
        '''Testing passing a config file to ConfigurationStore with local override'''
        ConfigurationStore.unload()
        conf = ConfigurationStore()

        self.assertIsNone(conf.config_dir)
        self.assertIsNone(conf.APP)
        self.assertIsNone(conf.INST)
        self.assertEqual(conf.RUN_MODE, "dev")

        # Not using assertRaises as DATA is a property and not a function
        try:
            _ = conf.DATA
            exceptionRaised = False
        except AttributeError:
            exceptionRaised = True
        self.assertTrue(exceptionRaised, "Expected AttributeError for conf.DATA")
예제 #10
0
    def test21_conf_store_logger_config(self):
        '''Make sure that logger is create correctly from config file'''
        with ConfigurationStore(__file__, in_local_name="logger_local.json") as c:
            logger = c.logger

        self.assertEqual(logger.name, "TestLogger")
        self.assertEqual(logger.level, logging.CRITICAL)
        self.assertEqual(len(logger.handlers), 1)

        handler = logger.handlers[0]
        self.assertEqual(handler.formatter._fmt, "%(asctime)-15s:|%(levelname)s|%(message)s|%(filename)s|%(lineno)d")
예제 #11
0
    def test01_simple(self):
        '''Simple test without any param'''
        config_file, local_file = ConfigurationStore._search_config()

        self.assertIsNone(config_file)
        self.assertIsNone(local_file)
예제 #12
0
'''
# pylint: disable=W0212

from __future__ import print_function

import copy
import datetime

from google.appengine.ext import ndb

from google.net.proto.ProtocolBuffer import ProtocolBufferDecodeError
from google.appengine.api.datastore_errors import Error, BadValueError

from core import ConfigurationStore

with ConfigurationStore() as c:
    LOGGER = c.logger


# ==============================================================================
# Define Exceptions
#
class NdbModelError(Error):
    '''Generic and base error used by NdbModelMixIn object'''
    pass


class NdbModelMismatchError(NdbModelError):
    '''When updating model with a key but entity returned is of different model'''
    pass