def test_psql_with_ignored_dry_run_flag(self):
        """
        Calls the psql command if the `dryrun` flag is set in the configuration
        but the 'ignore_dryrun' parameter is set to `True`.
        """

        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.number_of_calls += 1

        fake_runner.number_of_calls = 0

        config = {
            "dryrun": True,
            "path": "/tmp",
            "host": "localhost",
            "db": "openquake",
            "user": "******"
        }
        psql(
            config,
            cmd="SELECT * from admin.revision_info",
            ignore_dryrun=True,
            runner=fake_runner)
        self.assertEqual(1, fake_runner.number_of_calls)
Пример #2
0
 def test_psql_with_neither_script_nor_command(self):
     """
     Raises an `Exception` if neither a command nor a script are passed.
     """
     config = {"dryrun": True, "path": "/tmp", "host": "localhost",
               "db": "openquake", "user": "******"}
     try:
         psql(config)
     except Exception, e:
         self.assertEqual(
             "Neither SQL script nor command specified.", e.args[0])
Пример #3
0
 def test_psql_with_both_script_and_command(self):
     """
     Raises an `Exception` if both a command and a script are passed.
     """
     config = {"dryrun": True, "path": "/tmp", "host": "localhost",
               "db": "openquake", "user": "******"}
     try:
         psql(config, cmd="SELECT * from admin.revision_info", script="xxx")
     except Exception, e:
         self.assertEqual(
             "Please specify either an SQL script or a command.", e.args[0])
Пример #4
0
    def test_psql_cmd_with_script(self):
        """Tests the psql command params with an SQL script file."""
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds
        fake_runner.args = []

        config = {"dryrun": False, "path": "/tmp", "host": "localhost",
                  "db": "0penquark", "user": "******"}
        psql(config, script="xxx", runner=fake_runner)
        self.assertEqual(
            ["psql", "-d", "0penquark", "-U", "postgres", "-f", "/tmp/xxx"],
            fake_runner.args)
Пример #5
0
    def test_psql_cmd_with_command(self):
        """Tests the psql command params with an SQL command."""
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds
        fake_runner.args = []

        config = {"dryrun": False, "path": "/tmp", "host": "localhost",
                  "db": "openquake", "user": "******"}
        psql(config, cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertEqual(
            ["psql", "-d", "openquake", "-U", "chuckn", "-c",
             "SELECT * from admin.revision_info"], fake_runner.args)
Пример #6
0
    def test_psql_with_dry_run_flag(self):
        """
        Does not call the psql command if the `dryrun` flag is set in
        the configuration.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.number_of_calls += 1
        fake_runner.number_of_calls = 0

        config = {"dryrun": True, "path": "/tmp", "host": "localhost",
                  "db": "openquake", "user": "******"}
        psql(config, cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertEqual(0, fake_runner.number_of_calls)
Пример #7
0
    def test_psql_with_local_host_ip(self):
        """
        Does not specify the `-h` flag in the `psql` command when the host in
        the configuration is `127.0.0.1`.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds
        fake_runner.args = []

        config = {"dryrun": False, "path": "/tmp", "host": "127.0.0.1",
                  "db": "openquake", "user": "******"}
        psql(config, cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertTrue("-h" not in fake_runner.args)
Пример #8
0
    def test_psql_with_non_local_host(self):
        """
        The `-h` flag *is* specified in the `psql` command when the host in
        the configuration is not `localhost`.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds
        fake_runner.args = []

        config = {"dryrun": False, "path": "/tmp", "host": "gozilla",
                  "db": "openquake", "user": "******"}
        psql(config, cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertTrue("-h" in fake_runner.args)
Пример #9
0
 def test_psql_with_neither_script_nor_command(self):
     """
     Raises an `Exception` if neither a command nor a script are passed.
     """
     config = {
         "dryrun": True,
         "path": "/tmp",
         "host": "localhost",
         "db": "openquake",
         "user": "******"
     }
     try:
         psql(config)
     except Exception, e:
         self.assertEqual("Neither SQL script nor command specified.",
                          e.args[0])
Пример #10
0
 def test_psql_with_both_script_and_command(self):
     """
     Raises an `Exception` if both a command and a script are passed.
     """
     config = {
         "dryrun": True,
         "path": "/tmp",
         "host": "localhost",
         "db": "openquake",
         "user": "******"
     }
     try:
         psql(config, cmd="SELECT * from admin.revision_info", script="xxx")
     except Exception, e:
         self.assertEqual(
             "Please specify either an SQL script or a command.", e.args[0])
Пример #11
0
    def test_psql_cmd_with_script(self):
        """Tests the psql command params with an SQL script file."""
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds

        fake_runner.args = []

        config = {
            "dryrun": False,
            "path": "/tmp",
            "host": "localhost",
            "db": "0penquark",
            "user": "******"
        }
        psql(config, script="xxx", runner=fake_runner)
        self.assertEqual(
            ["psql", "-d", "0penquark", "-U", "postgres", "-f", "/tmp/xxx"],
            fake_runner.args)
Пример #12
0
    def test_psql_cmd_with_command(self):
        """Tests the psql command params with an SQL command."""
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds

        fake_runner.args = []

        config = {
            "dryrun": False,
            "path": "/tmp",
            "host": "localhost",
            "db": "openquake",
            "user": "******"
        }
        psql(config,
             cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertEqual([
            "psql", "-d", "openquake", "-U", "chuckn", "-c",
            "SELECT * from admin.revision_info"
        ], fake_runner.args)
Пример #13
0
    def test_psql_with_dry_run_flag(self):
        """
        Does not call the psql command if the `dryrun` flag is set in
        the configuration.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.number_of_calls += 1

        fake_runner.number_of_calls = 0

        config = {
            "dryrun": True,
            "path": "/tmp",
            "host": "localhost",
            "db": "openquake",
            "user": "******"
        }
        psql(config,
             cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertEqual(0, fake_runner.number_of_calls)
Пример #14
0
    def test_psql_with_local_host_ip(self):
        """
        Does not specify the `-h` flag in the `psql` command when the host in
        the configuration is `127.0.0.1`.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds

        fake_runner.args = []

        config = {
            "dryrun": False,
            "path": "/tmp",
            "host": "127.0.0.1",
            "db": "openquake",
            "user": "******"
        }
        psql(config,
             cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertTrue("-h" not in fake_runner.args)
Пример #15
0
    def test_psql_with_non_local_host(self):
        """
        The `-h` flag *is* specified in the `psql` command when the host in
        the configuration is not `localhost`.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.args = cmds

        fake_runner.args = []

        config = {
            "dryrun": False,
            "path": "/tmp",
            "host": "gozilla",
            "db": "openquake",
            "user": "******"
        }
        psql(config,
             cmd="SELECT * from admin.revision_info",
             runner=fake_runner)
        self.assertTrue("-h" in fake_runner.args)
Пример #16
0
    def test_psql_with_ignored_dry_run_flag(self):
        """
        Calls the psql command if the `dryrun` flag is set in the configuration
        but the 'ignore_dryrun' parameter is set to `True`.
        """
        def fake_runner(cmds):
            """Fake command runner function to be used in this test."""
            fake_runner.number_of_calls += 1

        fake_runner.number_of_calls = 0

        config = {
            "dryrun": True,
            "path": "/tmp",
            "host": "localhost",
            "db": "openquake",
            "user": "******"
        }
        psql(config,
             cmd="SELECT * from admin.revision_info",
             ignore_dryrun=True,
             runner=fake_runner)
        self.assertEqual(1, fake_runner.number_of_calls)