django-testing

Django's self.client.login(...) does not work in unit tests

I have created users for my unit tests in two ways: 1) Create a fixture for "auth.user" that looks roughly like this: { "pk": 1, "model": "auth.user", "fields": { "username": "homer", "is_active": 1, "password": "sha1$72cd3$4935449e2cd7efb8b3723fb9958fe3bb100a30f2...

Problems using User model in django unit tests

I have the following django test case that is giving me errors: class MyTesting(unittest.TestCase): def setUp(self): self.u1 = User.objects.create(username='user1') self.up1 = UserProfile.objects.create(user=self.u1) def testA(self): ... def testB(self): ... When I run my tests, testA will...

Django - testing using large tables of static data

I am using "manage.py test" along with a JSON fixture I created using using 'dumpdata' My problem is that several of the tables in the fixture are very large (for example one containing the names of all cities in the US) which makes running a test incredibly slow. Seeing as several of these tables are never modified by the program (eg...

How can I unit test django messages?

In my django application, I'm trying to write a unit test that performs an action and then checks the messages in the response. As far as I can tell, there is no nice way of doing this. I'm using the CookieStorage storage method, and I'd like to do something similar to the following: response = self.client.post('/do-something/',...

How can I get more detail on why a fixture is not loading?

I have a TestCase that doesn't seem to load the fixtures. I'm seeing this error as the test database is being built: No fixtures found. .............................................Problem installing fixture '/Users/Bryan/work/CNPROG/forum/fixtures/forum_fixtures.json': Traceback (most recent call last): File "/Library/Frameworks...

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 models, I could save oodles of time if Django would not bother trying to create and destroy the...

in a brand-new django project, django auth tests fail

I make a brand-new django project and do literally nothing with it except give values to DATABASE_USER, DATABASE_ENGINE, DATABASE_NAME, and DATABASE_PASSWORD, and django auth test fail. How is this even possible? I also tried adding TEMPLATE_CONTEXT_PROCESSORS as suggested at http://stackoverflow.com/questions/2507210/django-failing-tes...

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 about that. I can create a new database through the control panel but I don't think...

How can reverse('opensearch') work in the shell, but fails in a Test?

I'm trying to install django-lean into my application. Open search is used in my app App. I can reverse('opensearch') in the Python shell. However, in the test, reverse('opensearch') * NoReverseMatch: Reverse for 'opensearch' with arguments '()' and keyword arguments In [47]: reverse('opensearch') Out[47]: '/opensearch.xml' In [48]:...

URL template tags fail in Test mode, but work in Dev and Production ( Django 1.2.1 )

I've been trying to add the django-lean app to my project. I have not been able to get the tests to pass. It took me a few days with a debugger to determine what the problem was. It seems that all the URL template tags fail in Test mode, but not in Production nor Developement. Failure happens in django.template.defaulttags.URLNode.ren...

How does this happen? AssertionError: Response redirected to 'http://testserver/account/signin/', expected 'http://testserver/accounts/signin/'

This just doesn't make any sense to me, how can the assertion fail when the arguments are identical? ====================================================================== FAIL: test_register_page_redirects_to_signin_page (forum.tests.test_views.ForumTestCase) ---------------------------------------------------------------------- Traceb...

Why are the Django project URLs not all available to the Django test client?

I've been trying to add the django-lean app to my project. The django-lean app is not located in the project I'm working on, it is on the PYTHONPATH. I have not been able to get the django-lean tests to pass. It seems the issue is that the TestCase defines a value for urls: urls = 'django_lean.experiments.tests.urls' As best as I...

Django testing - InternalError: current transaction is aborted, commands ignored until end of transaction block

In my tests I do not only test for the perfect case, but especially for edge cases and error conditions. So I wanted to ensure some uniqueness constraints work. While my test and test fixtures are pretty complicated I was able to track the problem down to the following example, which does not use any custom models. To reproduce the beha...

Django Testing: determine which view was executed

In the Django testing documentation they promise that you can "Test that the correct view is executed for a given URL." However I didn't find any possibility how to test which view was executed. I would expect that in the Response class but there's nothing about the executed view. Thanks in advance. ...

Testing email sending - Django

Hi folks, any tips on testing email sending? Other than maybe creating a gmail account, especially for receiving those emails? I would like to maybe store the emails locally, within a folder as they are sent. Tips would be great! Thanks :) ...

Error in django unittest while loading a fixture

Hello all, I am making unittests for a django app. I need some data in the database for my tests so I am using a json fixture. I have two fixtures: for users and it works ok. for some webpages The fixture 2 cause the following error: Problem installing fixture 'C:\Users\luc\Dev\Hg\mnl-adminpub\website\fixtures\website-unittest.js...

How to launch tests for django reusable app?

Can I launch tests for my Django reusable app without incorporating this app to some project? My app uses some models, so it is necessary to provide (TEST_)DATABASE_* settings. Where to store them and how to launch tests? For django project I run tests by: manage.py test, when I use django-admin.py I get: Error: Settings cannot be...