Beispiel #1
0
 def setUp(self):
     """The environment must contain PG* environment variables to establish a PostgreSQL connection:
     http://www.postgresql.org/docs/current/static/libpq-envars.html
     """
     parser = pgtool.make_argparser()
     pgtool.args = parser.parse_args(["kill", "x"])  # hack :(
     self.db = pgtool.connect(None)
Beispiel #2
0
    def test_parser(self):
        parser = pgtool.make_argparser()

        with self.assertRaises(SystemExit, msg="0"):
            parser.parse_args(['--help'])
        # kill doesn't take --no-backup
        with self.assertRaises(SystemExit, msg="1"):
            parser.parse_args(['kill', 'foo', '--no-backup'])
        # mv does
        parser.parse_args(['mv', 'foo', 'bar', '--no-backup'])
        # but not before the command itself
        with self.assertRaises(SystemExit, msg="1"):
            parser.parse_args(['--no-backup', 'mv', 'foo', 'bar'])

        # --quiet is only accepted before command (because argparse hates users)
        parser.parse_args(['--quiet', 'kill', 'foo'])
        with self.assertRaises(SystemExit, msg="1"):
            parser.parse_args(['kill', '--quiet', 'foo'])
Beispiel #3
0
    def setUpClass(cls):
        """The environment must contain PG* environment variables to establish a PostgreSQL connection:
        http://www.postgresql.org/docs/current/static/libpq-envars.html
        """
        parser = pgtool.make_argparser()
        pgtool.args = parser.parse_args(["kill", "x"])  # hack to fill out args
        cls.db = pgtool.connect(None)

        c = cls.db.cursor()
        # XXX ideally this setup should be done once globally, not for each test class
        # language=SQL
        c.execute(
            """\
        -- Schema
        DROP SCHEMA IF EXISTS pgtool_test CASCADE;
        CREATE SCHEMA pgtool_test;
        SET search_path=pgtool_test;

        -- Reindex test
        CREATE TABLE reindex_tbl (txt text);
        INSERT INTO reindex_tbl VALUES ('a');
        """
        )