Questions tagged [django-testing]

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. This tag is about writing and running tests for your Django apps.

Django

Testing overview

Testing a Web application is a complex task, because a Web application is made of several layers of logic – from HTTP-level request handling, to form validation and processing, to template rendering. With Django’s test-execution framework and assorted utilities, you can simulate requests, insert test data, inspect your application’s output and generally verify your code is doing what it should be doing.

1220 questions
20
votes
11 answers

Choose test database?

I'm trying to run ./manage.py test But it tells me Got an error creating the test database: permission denied to create database Obviously it doesn't have permission to create the database, but I'm on a shared server, so there's not much I can do…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
20
votes
1 answer

How can I keep test data after Django tests complete?

I am using Django 1.8 and the docs say to use --keepdb to save the test database. I am doing that and the database is there but every time I see it, it is empty and has no data in it. Is there any way that I can preserve that so that I can see…
user3214546
  • 6,523
  • 13
  • 51
  • 98
20
votes
4 answers

How to specify an IP address with Django test client?

I am testing an API with Django test client. The API uses geo blocking so in my test I need to specify an IP address to make sure it works properly. How can I do that? I am making a request in my test like this: from django.test.client import Client…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
19
votes
4 answers

Django Testing - Hard code URLs or Not

This is a best-practices question. When writing tests in Django, is it better to hard code urls in your tests.py, or to use the dispatch's reverse() function to retrieve the correct url? Using hard-coded urls for testing only feels like the right…
T. Stone
  • 19,209
  • 15
  • 69
  • 97
19
votes
2 answers

Many-to-many relationship in factory_boy?

I'm trying to test a many-to-many relationship between two Django models using factory_boy. The factory_boy documentation doesn't appear to discuss this and I'm having trouble figuring out what I'm doing wrong. When I run the first test, I get the…
Jim
  • 13,430
  • 26
  • 104
  • 155
18
votes
2 answers

Django test client response context None

I have moved my Django app from my development machine (OS X, Python 2.6.5, Django 1.2.3) to a staging server (Ubuntu VM, Python 2.6.6, Django 1.2.3). If I now run my test suite on the staging server, two tests fail when using the Django TestClient…
epoch
  • 1,337
  • 2
  • 15
  • 23
18
votes
7 answers

Selenium: Element not clickable ... Other Element Would Receive Click

When running Selenium tests on my Django project, I've started to get the error: selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (61, 24.300003051757812). Other element would receive the click:
jejy2343
  • 449
  • 2
  • 6
  • 18
17
votes
2 answers

Django testing tips

In the spirit of this question, I would like to know if anyone has any tips on creating a useful and "complete" test suite (can a test suite ever be "complete"?) for a Django webapp. My situation: I've knocked out a prototype and am now working on…
Belmin Fernandez
  • 8,307
  • 9
  • 51
  • 75
17
votes
3 answers

How do I tell Django to save my test database?

Running Django unit tests is far too slow. Especially when I just want to run one test but the test runner wants to create the entire database and destroy the whole thing just for that one test. In the case where I have not changed any of my…
Conley Owens
  • 8,691
  • 5
  • 30
  • 43
17
votes
2 answers

How to test login process?

I am developing a web application using Django 1.6 where I require users to log in using my login form. I want to write a test case that tests the procedure of a user logging in. I did succeed to get a working login page, meaning I was able to log…
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
16
votes
3 answers

django - specify database for TestCase fixtures

I have two databases that my site uses and I have an app that uses both of them. I need to write a TestCase that loads fixtures for both databases. I use a DB router, which works fine in production, but in the testing framework, Django insists on…
matt snider
  • 4,013
  • 4
  • 24
  • 39
16
votes
4 answers

Disable a specific Django middleware during tests

How can I disable a specific middleware (a custom middleware I wrote) only during tests?
daveoncode
  • 18,900
  • 15
  • 104
  • 159
16
votes
2 answers

Display list of all tests in a Django project

Is there an easy way to get a list of all tests in a Django project without running the tests themselves? I was hoping for something like ./manage.py test --list.
Hakan B.
  • 2,319
  • 23
  • 29
16
votes
2 answers

Setting HTTP_REFERER header in Django test

I'm working on a Django web application which (amongst other things) needs to handle transaction status info sent using a POST request. In addition to the HTTP security supported by the payment gateway, my view checks request.META['HTTP_REFERER']…
supervacuo
  • 9,072
  • 2
  • 44
  • 61
15
votes
1 answer

Django 1.3: Outbox empty during tests

Maybe I don't understand how outbox works but from the documentation I understood that it just catches all outgoing mail during testing. I created a new project with a new application and added the following code. from django.test import…
Pickels
  • 33,902
  • 26
  • 118
  • 178