Search code examples
djangopostgresqldjango-unittest

How do I test a Django site that uses UDFs in the database?


I have a django project that uses a postgres db with a number of UDFs. The UDFs are written in plpythonu. Since plpyhtonu is an untrusted language, only database super users can use it to to create UDFs. This poses a serious problem in that I have no way of programmatically creating them within the test suite. Right now I see two options:

  1. Modify django.db.backends.creation._create_test_db to create the test db from a template, which has my UDFs already loaded. This seems hacky and laborious to maintain.
  2. Create a super user with MD5 authentication and load the UDFs in the test suite with psycopg2. This seems unsecure.

Are there less terrible ways I can do this?

Thanks.


Solution

  • I went with #1. It's not ideal but it works ok.