Opened 14 years ago

Closed 14 years ago

#14339 closed (duplicate)

Enable testing when you can't create/destroy databases

Reported by: Martin Omander <martin.omander@…> Owned by: nobody
Component: Testing framework Version: 1.2
Severity: Keywords: test database
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When you are using Django in a hosted environment, you don't always have privileges to "CREATE DATABASE" or "DROP DATABASE". Some services allow you to create and destroy databases, but only through a web UI and not from Python code. In either case, you can't run Django unit tests. Developers using Webfaction, like myself, are in this situation. See this forum thread for developers struggling with this problem.

I hacked my local _create_test_db() and _destroy_test_db() so they assume the test database exists and create and drop tables, instead of the entire database. This allows me to run unit tests, but at the cost of forking the Django code. If there was a new test runner that did the same thing, others who are on hosting services like Webfaction would be able to do testing without having to invent dirty hacks like I did. This new test runner would need to call new code in django/db/backends/creation.py that drops all tables in a database.

Is a new test runner the right approach to solve this problem? Are there other approaches? Would this warrant a new method in creation.py to drop all tables in a database?

Change History (4)

comment:1 by Luke Plant, 14 years ago

Just to collect some related things which we might need to think about at the same time:

(BTW, With webfaction are you sure you can't create a DB using the XML-RPC api? )

comment:2 by Martin Omander <martin.omander@…>, 14 years ago

Thanks for the pointer to Webfaction's XML-RPC API! I tried the API and it works well, but I was not able to write a working test runner that calls it. I guess I don't understand the ins and outs of test runners and db connections well enough, so I'm back to hacking _create_test_db() and _destroy_test_db().

comment:3 by Ramiro Morales, 14 years ago

The Oracle backend has the 'TEST_CREATE' (and a 'TEST_USER_CREATE') boolean var that allows control of the DB (actually tablespace) creation process. Maybe we could extend/generalize this to the other backends somehow?

comment:4 by Russell Keith-Magee, 14 years ago

Resolution: duplicate
Status: newclosed

Closing as a duplicate of #14296, since the solution is essentially the same.

Note: See TracTickets for help on using tickets.
Back to Top