TestClient with no Django Database

14 views
Skip to first unread message

Denali Lumma

unread,
Sep 11, 2008, 7:35:07 PM9/11/08
to Django users
Hi There,

I am trying to use the TestClient class to validate some of our
pages. It seems to work OK for pages which don't require
authentication.

I am aware of the test database which is created and used in the
TestClient run, however, we have a special set up here. We are not
using any of Django's database support code. We have our own lower
level code which interacts with the database.

So there is really no way for Django to create a test database for
the run, since we have no Models defined, no settings variables
related to database defined, etc.

Any pointers on the best direction to take, given this limitation?

This, of course, makes testing pages which require login impossible
at the present time.

Thank you very much for any help.

Russell Keith-Magee

unread,
Sep 11, 2008, 8:30:23 PM9/11/08
to django...@googlegroups.com
On Fri, Sep 12, 2008 at 7:35 AM, Denali Lumma <denalin...@gmail.com> wrote:
>
> Hi There,
>
> I am trying to use the TestClient class to validate some of our
> pages. It seems to work OK for pages which don't require
> authentication.

It should work fine for pages _with_ authentication, too; you just
need to authenticate the client first.

> I am aware of the test database which is created and used in the
> TestClient run, however, we have a special set up here. We are not
> using any of Django's database support code. We have our own lower
> level code which interacts with the database.

You appear to be getting some terminology confused here. Are you talking about:
* the TestClient - the dummy web browser
* the Django Test Case - a wrapper around unittest.TestCase that
provides a TestClient instance
* the Django Test Runner - which creates the test database.

The TestClient itself doesn't do anything with the database
connection. It just hits the URLconf to activate the requested views
and get the response. You should be able to run the TestClient without
ever touching the database backend code.

However, if you're talking about the test runner, the solution is easy
- write a custom test runner. If you want to use an existing database
rather than the Django Test database, take a copy of the runtests
method in django.test.simple, remove the parts that create and destroy
the test database, and refer to your modified version in the
TEST_RUNNNER value of your settings file. See here for more details on
the general process:

http://docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages