Example #1
0
    def test_update_config_file(self):
        "Test config file update utility."

        input_dir = dbutil.input_directory(self.MODULE, self.SUITE)
        output_dir = dbutil.output_directory(self.MODULE, self.SUITE)
        expected_dir = dbutil.expected_directory(self.MODULE, self.SUITE)

        dbname = 'TEST_TEST_TEST'
        config_file_name = 'test_datacube.conf'

        output_path = dbutil.update_config_file(dbname, input_dir, output_dir,
                                                config_file_name)

        expected_path = os.path.join(expected_dir, config_file_name)
        if not os.path.isfile(expected_path):
            self.skipTest("Expected config file not found.")
        else:
            try:
                subprocess.check_output(['diff', output_path, expected_path])
            except subprocess.CalledProcessError as err:
                self.fail("Config file does not match expected result:\n" +
                          err.output)
Example #2
0
    def test_update_config_file(self):
        "Test config file update utility."

        input_dir = dbutil.input_directory(self.MODULE, self.SUITE)
        output_dir = dbutil.output_directory(self.MODULE, self.SUITE)
        expected_dir = dbutil.expected_directory(self.MODULE, self.SUITE)

        dbname = 'TEST_TEST_TEST'
        config_file_name = 'test_datacube.conf'

        output_path = dbutil.update_config_file(dbname, input_dir,
                                                output_dir, config_file_name)

        expected_path = os.path.join(expected_dir, config_file_name)
        if not os.path.isfile(expected_path):
            self.skipTest("Expected config file not found.")
        else:
            try:
                subprocess.check_output(['diff', output_path, expected_path])
            except subprocess.CalledProcessError as err:
                self.fail("Config file does not match expected result:\n" +
                          err.output)
Example #3
0
    def test_onescene(self):
        """Test database update for a single scene."""

        # This test is intended as an example, and so is extensively
        # commented.

        # Open a log file
        logfile_path = os.path.join(self.OUTPUT_DIR, "test_onescene.log")
        self.logfile = open(logfile_path, "w")

        #
        # Create the initial database
        #

        # Randomise the name to avoid collisons with other users.
        self.test_dbname = dbutil.random_name("test_onescene")

        # Create the database.
        dbutil.TESTSERVER.create(self.test_dbname,
                                 self.INPUT_DIR, "hypercube_empty.sql")

        #
        # Run dbupdater on the test database and save the result
        #

        # Create an updated datacube_conf file with the new dbname
        config_file_path = dbutil.update_config_file(self.test_dbname,
                                                     self.INPUT_DIR,
                                                     self.OUTPUT_DIR,
                                                     "test_datacube.conf")

        # Run dbupdater

        ingest_dir = os.path.join(self.INPUT_DIR, 'onescene')
        dbupdater_cmd = ["python",
                         "dbupdater.py",
                         "--debug",
                         "--config=%s" % config_file_path,
                         "--source=%s" % ingest_dir,
                         "--removedblist",
                         "--followsymlinks"]
        subprocess.check_call(dbupdater_cmd, stdout=self.logfile,
                              stderr=subprocess.STDOUT)

        # Save the updated database
        dbutil.TESTSERVER.save(self.test_dbname, self.OUTPUT_DIR,
                               "onescene.sql")

        #
        # If an expected result exists then load it and compare
        #

        # Check for expected result
        if os.path.isfile(os.path.join(self.EXPECTED_DIR, "onescene.sql")):
            # Create a randomised name...
            self.expected_dbname = dbutil.random_name("expected_onescene")

            # load the database...
            dbutil.TESTSERVER.create(self.expected_dbname,
                                     self.EXPECTED_DIR, "onescene.sql")

            # create database connections...
            self.test_conn = dbutil.TESTSERVER.connect(self.test_dbname)
            self.expected_conn = dbutil.TESTSERVER.connect(
                self.expected_dbname)

            # and compare.

            self.assertTrue(dbcompare.compare_databases(self.test_conn,
                                                        self.expected_conn,
                                                        output=self.logfile,
                                                        verbosity=3),
                            "Databases do not match.")
        else:
            self.skipTest("Expected database save file not found.")