Ejemplo n.º 1
0
    def test_editing_reconnect(self):
        """
        Test if the product can successfully be set to connect to another db.

        This requires a SUPERUSER.
        """

        pr_client = env.setup_product_client(self.test_workspace,
                                             product=self.product_name)
        product_id = pr_client.getCurrentProduct().id
        config = self._pr_client.getProductConfiguration(product_id)

        old_db_name = config.connection.database

        # Create a new database.
        tenv = self.test_cfg['codechecker_cfg']['check_env']

        if config.connection.engine == 'sqlite':
            new_db_name = os.path.join(self.test_workspace, 'new.sqlite')
        elif config.connection.engine == 'postgresql':
            new_db_name = 'editeddb'
            env.add_database(new_db_name, tenv)
        else:
            raise ValueError("I was not prepared to handle database mode " +
                             config.connection.engine)

        config.connection.database = new_db_name
        self.assertTrue(self._root_client.editProduct(product_id, config),
                        "Product edit didn't conclude.")

        # Check if the configuration now uses the new values.
        config = self._pr_client.getProductConfiguration(product_id)

        self.assertEqual(config.connection.database, new_db_name,
                         "Server didn't save new database name.")
        self.assertEqual(
            config.endpoint, self.product_name,
            "The endpoint was changed -- perhaps the "
            "temporary connection leaked into the database?")

        # There is no schema initialization if the product database
        # was changed. The inital schema needs to be created manually
        # for the new database.
        runs = self._cc_client.getRunData(None, None, 0, None)
        self.assertIsNone(runs)

        # Connect back to the old database.
        config.connection.database = old_db_name
        self.assertTrue(self._root_client.editProduct(product_id, config),
                        "Product configuration restore didn't conclude.")

        config = self._pr_client.getProductConfiguration(product_id)
        self.assertEqual(config.connection.database, old_db_name,
                         "Server didn't save back to old database name.")

        # The old database should have its data available again.
        runs = self._cc_client.getRunData(None, None, 0, None)
        self.assertEqual(
            len(runs), 1,
            "We connected to old database but the run was missing.")

        # Drop the temporary database. SQLite file will be removed with
        # the test workspace.
        if config.connection.engine == 'postgresql':
            env.del_database(new_db_name, tenv)
Ejemplo n.º 2
0
    def test_editing_reconnect(self):
        """
        Test if the product can successfully be set to connect to another db.

        This requires a SUPERUSER.
        """

        pr_client = env.setup_product_client(
            self.test_workspace, product=self.product_name)
        product_id = pr_client.getCurrentProduct().id
        config = self._pr_client.getProductConfiguration(product_id)

        old_db_name = config.connection.database

        # Create a new database.
        tenv = self.test_cfg['codechecker_cfg']['check_env']

        if config.connection.engine == 'sqlite':
            new_db_name = os.path.join(self.test_workspace, 'new.sqlite')
        elif config.connection.engine == 'postgresql':
            new_db_name = 'editeddb'
            env.add_database(new_db_name, tenv)
        else:
            raise ValueError("I was not prepared to handle database mode " +
                             config.connection.engine)

        config.connection.database = new_db_name
        self.assertTrue(self._root_client.editProduct(product_id, config),
                        "Product edit didn't conclude.")

        # Check if the configuration now uses the new values.
        config = self._pr_client.getProductConfiguration(product_id)

        self.assertEqual(config.connection.database, new_db_name,
                         "Server didn't save new database name.")
        self.assertEqual(config.endpoint, self.product_name,
                         "The endpoint was changed -- perhaps the "
                         "temporary connection leaked into the database?")

        # There is no schema initialization if the product database
        # was changed. The inital schema needs to be created manually
        # for the new database.
        runs = self._cc_client.getRunData(None)
        self.assertIsNone(runs)

        # Connect back to the old database.
        config.connection.database = old_db_name
        self.assertTrue(self._root_client.editProduct(product_id, config),
                        "Product configuration restore didn't conclude.")

        config = self._pr_client.getProductConfiguration(product_id)
        self.assertEqual(config.connection.database, old_db_name,
                         "Server didn't save back to old database name.")

        # The old database should have its data available again.
        runs = self._cc_client.getRunData(None)
        self.assertEqual(
            len(runs), 1,
            "We connected to old database but the run was missing.")

        # Drop the temporary database. SQLite file will be removed with
        # the test workspace.
        if config.connection.engine == 'postgresql':
            env.del_database(new_db_name, tenv)