Skip to content
Dmitry Romanov edited this page Nov 4, 2023 · 11 revisions

For CCDB development one has to setup a database to have units tests running. There is a script that fills tables for a test database, but one needs to first create a schema (ccdb_test by default), and set proper privileges to use it:

mysql -u root -p 
-- If ccdb_user is not created yet
CREATE USER 'ccdb_user'@'localhost';

CREATE SCHEMA IF NOT EXISTS `ccdb_test`;
GRANT ALL PRIVILEGES ON ccdb_test.* TO 'ccdb_user'@'localhost';

Now you can use a tiny python wrapper that helps to create/recreate test database contents. This command may be used in future to recreate the test DB contents if the DB structure is screwed up by tests

python3 $CCDB_HOME/python/tests/helper.py --rmysql

Running this command without flags will show the CCDB tests setup variables

You should be able now to run tests

# general python tests - no MySQL
python3 $CCDB_HOME/python/run_unit_tests.py

# MySQL specific integration tests
python3 $CCDB_HOME/python/tests/integ_test_provider_mysql.py

Test database is the same as the main database. The python script just takes $CCDB_HOME/sql/ccdb.myslq.sql and renames ccdb to whatever test database name is (ccdb_test is the default). But it is recommended to use a separate database from the main one where it is easy and safe to recreate the structure and default values if anything goes wrong

Tests organization

Unit tests look for two environment variables:

  1. CCDB_TEST_MYSQL_CONNECTION
    if not found mysql://ccdb_user@localhost/ccdb_test is used
  2. CCDB_TEST_SQLITE_CONNECTION
    if not found sqlite:///$CCDB_HOME/sql/ccdb.sqlite is used

It is assumed that for unit tests on MySQL database, the schema with name ccdb_test and a user with name ccdb_user are used.

To create a user

mysql -u root -p -e "CREATE USER ccdb_user@'localhost';"

To give a permission for the user

mysql -u root -p -e "GRANT ALL PRIVILEGES ON ccdb_test.* TO 'ccdb_user'@'localhost';"

There is a helpful script that allows to re/create the test database contents

> python $CCDB_HOME/python/tests/helper.py --rmysql