Test Framework

Extensions for Django’s test framework to add support for Heroku Connect.

The custom database engine will create the Heroku Connect schema for you. The schema is created right via the pre_migrate signal, only when a test database is created. This will work for both Django’s build in test suite as well as pytest-django and maybe others.

Utilities

Test utilities for Django and Heroku Connect.

heroku_connect.test.utils.heroku_cli(stdout='', stderr='', exit_code=0)[source]

Context manager to mock the Heroku CLI command.

Example:

import subprocess
from heroku_connect.test.utils import heroku_cli

with heroku_cli(stdout='success', stderr='warning', exit=0):
    process = subprocess.run(
        ['heroku'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
assert process.returncode == 0
assert process.stdout == b'success\n'
assert process.stderr == b'warning\n'
Parameters:
  • stdout (str) – String the command writes to stdout.

  • stderr (str) – String the command writes to stderr.

  • exit_code (int) – Code that the command will exit with, default 1.

heroku_connect.test.utils.no_heroku_connect_write_restrictions()[source]

Allow writing to read-only Heroku Connect tables.

Can be used to create test data, e.g.:

def get_test_data():
    with no_heroku_connect_write_restrictions():
        return MyReadOnlyModel.objects.create()