Пример #1
0
class PyrseasTestCase(TestCase):
    """Base class for most test cases"""
    def setUp(self):
        self.db = _connect_clear(TEST_DBNAME)
        self.cfg = Config(sys_only=True)
        if 'database' not in self.cfg:
            self.cfg.update(database={})
        dbc = self.cfg['database']
        dbc['dbname'] = self.db.name
        dbc['username'] = self.db.user
        dbc['password'] = None
        dbc['host'] = self.db.host
        dbc['port'] = self.db.port

    def tearDown(self):
        self.db.close()

    def database(self):
        """The Pyrseas Database instance"""
        return Database(self.cfg)

    def config_options(self, **kwargs):
        class Opts():
            def __init__(self, **kwargs):
                [setattr(self, opt, val) for opt, val in list(kwargs.items())]

        self.cfg['options'] = Opts(**kwargs)
Пример #2
0
class PyrseasTestCase(TestCase):
    """Base class for most test cases"""

    def setUp(self):
        self.db = _connect_clear(TEST_DBNAME)
        self.cfg = Config(sys_only=True)
        if not 'database' in self.cfg:
            self.cfg.update(database={})
        dbc = self.cfg['database']
        dbc['dbname'] = self.db.name
        dbc['username'] = self.db.user
        dbc['password'] = None
        dbc['host'] = self.db.host
        dbc['port'] = self.db.port

    def tearDown(self):
        self.db.close()

    def database(self):
        """The Pyrseas Database instance"""
        return Database(self.cfg)

    def config_options(self, **kwargs):
        class Opts():
            def __init__(self, **kwargs):
                [setattr(self, opt, val) for opt, val in list(kwargs.items())]
        self.cfg['options'] = Opts(**kwargs)
Пример #3
0
 def setUp(self):
     self.db = _connect_clear(TEST_DBNAME)
     self.cfg = Config(sys_only=True)
     if 'database' not in self.cfg:
         self.cfg.update(database={})
     dbc = self.cfg['database']
     dbc['dbname'] = self.db.name
     dbc['username'] = self.db.user
     dbc['password'] = None
     dbc['host'] = self.db.host
     dbc['port'] = self.db.port
Пример #4
0
def test_user_config(tmpdir):
    "Test a user configuration file"
    f = tmpdir.join(CFG_FILE)
    f.write(yamldump(USER_CFG_DATA))
    os.environ["PYRSEAS_USER_CONFIG"] = f.strpath
    cfg = Config()
    assert cfg['database'] == {'port': 5433}
    assert cfg['output'] == {'version_comment': True}
Пример #5
0
def test_repo_config(tmpdir):
    "Test a repository configuration file"
    ucfg = tmpdir.join(CFG_FILE)
    ucfg.write(yamldump({'repository': {'path': tmpdir.strpath}}))
    f = tmpdir.join("config.yaml")
    f.write(yamldump(CFG_DATA))
    os.environ["PYRSEAS_USER_CONFIG"] = ucfg.strpath
    cfg = Config()
    assert cfg['datacopy'] == CFG_TABLE_DATA
Пример #6
0
def test_repo_user_config(tmpdir):
    "Test a repository path specified in the user config"
    usercfg = {'repository': {'path': tmpdir.strpath}}
    userf = tmpdir.join("usercfg.yaml")
    userf.write(yamldump(usercfg))
    os.environ["PYRSEAS_USER_CONFIG"] = userf.strpath
    repof = tmpdir.join("config.yaml")
    repof.write(yamldump(CFG_DATA))
    cfg = Config()
    assert cfg['datacopy'] == CFG_TABLE_DATA
Пример #7
0
def test_defaults():
    "Create a configuration with defaults"
    cfg = Config()
    for key in [
            'audit_columns', 'functions', 'function_templates', 'columns',
            'triggers'
    ]:
        assert key in cfg['augmenter']
    for key in ['metadata', 'data']:
        assert key in cfg['repository']
Пример #8
0
 def setUp(self):
     self.db = _connect_clear(TEST_DBNAME)
     self.cfg = Config(sys_only=True)
     if not 'database' in self.cfg:
         self.cfg.update(database={})
     dbc = self.cfg['database']
     dbc['dbname'] = self.db.name
     dbc['username'] = self.db.user
     dbc['password'] = None
     dbc['host'] = self.db.host
     dbc['port'] = self.db.port
Пример #9
0
 def setUp(self):
     self.db = _connect_clear(TEST_DBNAME)
     self.cfg = Config(sys_only=True)
     if not "database" in self.cfg:
         self.cfg.update(database={})
     dbc = self.cfg["database"]
     dbc["dbname"] = self.db.name
     dbc["username"] = self.db.user
     dbc["password"] = None
     dbc["host"] = self.db.host
     dbc["port"] = self.db.port
Пример #10
0
def cmd_parser(description, version):
    """Create command line argument parser with common PostgreSQL options

    :param description: text to display before the argument help
    :param version: version of the caller
    :return: the created parser
    """
    global _cfg

    parent = ArgumentParser(add_help=False)
    parent.add_argument('dbname', help='database name')
    group = parent.add_argument_group('Connection options')
    if _cfg is None:
        _cfg = Config()
    dbcfg = _cfg['database'] if 'database' in _cfg else {}
    group.add_argument('-H', '--host', **_help_dflt('host', dbcfg))
    group.add_argument('-p', '--port', type=int, **_help_dflt('port', dbcfg))
    group.add_argument('-U', '--username', **_help_dflt('username', dbcfg))
    group.add_argument('-W',
                       '--password',
                       action="store_true",
                       help="force password prompt")
    parent.add_argument('-c',
                        '--config',
                        type=FileType('r'),
                        help="configuration file path")
    parent.add_argument('-r',
                        '--repository',
                        default=_repo_path(_cfg),
                        help="root of repository (default %(default)s)")
    parent.add_argument('-o',
                        '--output',
                        type=FileType('w'),
                        help="output file name (default stdout)")
    parser = ArgumentParser(parents=[parent], description=description)
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + '%s' % version)
    return parser