Preparing an Oracle test setup

This document attempts to ease the task of running Django's (or your own app's) test suite against Oracle by providing a step by step setup guide to achieve that.

Using the Oracle Developer Day pre-installed VM

Oracle provides pre-built virtual machine images with Oracle Database 11g Release 2 Enterprise Edition for developers in form of an OVA archive which can be imported by VirtualBox. The archive can be downloaded here (or alternately a different one can be chosen from this list) after signing up for an Oracle Developer Network account.

The server will probably be somewhat slower than if you install it directly on the host machine, but using a VM has a slightly simpler setup, there's a somewhat smaller chance you'll pollute your host system completely and in case something goes wrong, you can always just remove the virtual machine, import a fresh copy and start again.

  1. Download the OVA file from and import it into VirtualBox. You'll have to accept an extensive license agreement.

  2. By default, the VM will be configured to have one NAT network interface. The database server itself starts automatically and listens on port 1521. You'll have to set up port forwarding in VirtualBox in order to access the server. Open the settings of the emulated network adapter and under Advanced open Port Forwarding. Insert a new rule with host IP set to, host port and destination port 1521 and an empty guest IP.

  3. The server comes with a number of user accounts created beforehand but I only found out how to access two of them. There's sys, which is a "sysdba" account (whatever that means), and system. The password for both of these is oracle and both have full privileges. Since the sys account is "sysdba", I'm not sure it can be used to run the tests (it spits out an error message on login attempt) but system seems to work just fine.

    As for other credentials on the virtual machine, if you want to login as a regular user, just use oracle/oracle, the root password is oracle as well. However, in order to run the test suite, you just need to boot the machine up, you don't need to start anything manually.

  4. Install instantclient on your host system (the one where you'll be running the test suite). On Gentoo there is an ebuild, which means it is just a matter of emerge -av oracle-instantclient-basic and fetching the appropriate zip archives from the Oracle download site as instructed.

On Debian or Ubuntu you can download the RPM package ("Instant Client Package - Basic"), convert it to a DEB package and install using alien:

$ sudo alien -i oracle-instantclient-basic*.rpm

After installing the client, you will need to install the "Instant Client Package - SDK". After downloading, unzip and copy it to the client install directory:

$ unzip instantclient-sdk-linux.x64-*.zip
$ sudo cp -R instantclient_11_2/* /usr/lib/oracle/11.2/client64/
  1. Start a new shell and install cx_Oracle in your testing virtualenv:

    $ pip install cx_Oracle

    The new shell is necessary because the instantclient package sets various environment variables required to build the adapter. On Debian/Ubuntu, you'll need to set the variables manually:

    $ export ORACLE_HOME=/usr/lib/oracle/11.2/client64/

    If you get an error installing cx_oracle (/usr/bin/ld: cannot find -lclntsh), you may also need to create this link:

    $ sudo ln -s /usr/lib/oracle/11.2/client64/lib/ /usr/lib/oracle/11.2/client64/lib/
  2. Create a settings file, the following example seems to work for me:

        'default': {
            'ENGINE': '',
            'HOST': '',
            'PORT': '1521',
            'NAME': 'orcl',
            'USER': 'system',
            'PASSWORD': 'oracle',
            'TEST': {
                'USER': 'django',
                'TBLSPACE': 'django_test',
                'TBLSPACE_TMP': 'django_test_tmp',
        'other': {
            'ENGINE': '',
            'HOST': '',
            'PORT': '1521',
            'NAME': 'orcl',
            'USER': 'system',
            'PASSWORD': 'oracle',
            'TEST': {
                'USER': 'other',
                'TBLSPACE': 'other_test',
                'TBLSPACE_TMP': 'other_test_tmp',
    SECRET_KEY = "django_tests_secret_key"

    As opposed to the XE server whose installation is outlined above, the server provided on the VM image uses orcl as its SID.

  3. Profit:

    $ # may be need on Debian/Ubuntu
    $ export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
    $ # for error " cannot open shared object file"
    $ sudo apt-get install libaio1
    $ ./ --settings=test_oracle
    Creating test database for alias 'default'...
    Creating test user...
    Creating test database for alias 'other'...
    Ran XXX tests in XXXs
    OK (skipped=X, expected failures=X)
    Destroying test database for alias 'default'...
    Destroying test user...
    Destroying test database tables...
    Destroying test database for alias 'other'...
Last modified 4 months ago Last modified on 05/07/2015 12:02:39 PM

Attachments (1)

Download all attachments as: .zip

Back to Top