Development¶
Testing¶
dbschema
uses py.test for testing. Since
dbschema
works with various database backends a little setup is
required to run the full test suite. Without any additional setup
as explained below only tests for SQLite3 databases will be
executed.
For testing the sqlparse
Python module is required.
Copy tests/databases.conf.example
to
tests/database.conf
and edit as needed. This configuration
file needs to be adapt to the database systems you’ve running on your
system and you need to set the parameters to access those databases
accordingly. Note that the database user needs permissions to create
and delete databases. Here’s an example with PostgreSQL and MySQL
configured, and where all created databases created during the tests
are prefixed with dbschema_
to avoid conflicts.
[DEFAULT]
db_prefix = dbschema_
[postgresql]
user = john
password = foo
[mysql]
user = john
password = foo
host = localhost
If the file tests/database.conf
doesn’t exist or is empty,
only the tests for SQLite databases will be run.
When ready, run py.test tests/ to run the tests using the default Python interpreter.
Setting Up Databases for Testing¶
As noted above each DBMS you want to test requires an entry in
test/databases.conf
. This section contains some notes on how
to set up various DBMS for testing on an Debian/Ubuntu system.
Warning
Security
The following setups assume that you run distinct database instances for testing this module. Therefore all databases users created in this examples are superusers. Please don’t use a production database for testing!
MySQL¶
First install the MySQL server and Python module with sudo apt-get install mysql-server libmysqlclient-dev python-mysqldb. During the installation you’ll be prompted for a password, note it down (or to be more secure, just remember it).
Next create a test user account. The test user needs privileges to create and drop a database. If you don’t care much about security for this database installation just create a superuser with the following commands:
$ mysql -u root -p
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'secret';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost';
Then in your tests/databases.conf
add
[mysql]
user = test
password = secret
host = localhost