django-testing

Sharing transaction scope between threads in python/django? (PostgreSQL)

Is there any way to share same transaction between two threads in a django-based code? The problem is that I have 1.1's TestCase (those that wrap individual tests into transactions) that are intended to test code that is running in a different thread [a sort of asynchronous testing]. So these test create some data that is intended to be...

Applying DATABASE_OPTIONS when testing Django project (or make it to use InnoDB for MySQL)

As the title says, I want to apply DATABASE_OPTIONS settings when I run my tests via ./manage.py test. In django/db/backends/creation.py, it does not consider this option at all in both create_test_db() and _create_test_db(). This breaks a test with a view that uses transaction.rollback function with InnoDB. It seems that test databases...

Django: is there a way to count SQL queries from an unit test?

I am trying to find out the number of queries executed by a utility function. I have written a unit test for this function and the function is working well. What I would like to do is track the number of SQL queries executed by the function so that I can see if there is any improvement after some refactoring. def do_something_in_the_dat...

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 way, but at the same time I can't think of a good enough argument for not using reverse()....

Configure Django to find all doctests in all modules?

If I run the following command: >python manage.py test Django looks at tests.py in my application, and runs any doctests or unit tests in that file. It also looks at the __ test __ dictionary for extra tests to run. So I can link doctests from other modules like so: #tests.py from myapp.module1 import _function1, _function2 __test__...

How to test custom template tags in Django?

I'm adding a set of template tags to a Django application and I'm not sure how to test them. I've used them in my templates and they seem to be working but I was looking for something more formal. The main logic is done in the models/model managers and has been tested. The tags simply retrieve data and store it in a context variable ...

Writing Django Unit Tests for Views

Does anyone have a good tute/example of writing good tests for views? Most of the stuff I've been finding was from mid 2008 which is only a little helpful. ...

How can I access response.context when testing a Jinja2 powered Django view

When I use the Django test.client and I do something like: class MyTestCase(TestCase): def test_this(self): c = self.client response = c.get('/') assert False, response.context['name'] I get an error: assert False, response.context['name'] TypeError: 'NoneType' object is unsubscriptable My only guess is ...

Loading SQL dump before running Django tests

I have a fairly complex Django project which makes it hard/impossible to use fixtures for loading data. What I would like to do is to load a database dump from the production database server after all tables has bene created by the testrunner and before the actual tests start running. I've tried various "magic" in MyTestCase.setUp(), b...

What tools can I use for Django Testing Automation?

I'm looking into automating a test runner which would do the following things daily (or hourly or whenever I want basically): Pull the latest code from a git repository. Run the Django test suite or something like Nose. Run Selenium tests. Give Pass/Fail and coverage statistics via a web interface. Email developers in the case of failu...

In a Django unit test driver how do you test if an email is sent?

In a Django unit test driver how do you test if an email is sent? ...

Writing good tests for Django applications

I've never written any tests in my life, but I'd like to start writing tests for my Django projects. I've read some articles about tests and decided to try to write some tests for an extremely simple Django app or a start. The app has two views (a list view, and a detail view) and a model with four fields: class News(models.Model): ...

How can I test a form's validation logic in a unit test driver in Django?

I want to test the is_valid portion of a form's validation logic. In my test driver I have: test_animal = Animal(name="cat", number_paws="4") test_animal_form = AnimalForm(instance=test_animal) assertEqual(test_animal_form.is_valid(), True) The assertion fails, but from what I see there shouldn't be any errors in the form. I...

Django test FileField using test fixtures

I'm trying to build tests for some models that have a FileField. The model looks like this: class SolutionFile(models.Model): ''' A file from a solution. ''' solution = models.ForeignKey(Solution) file = models.FileField(upload_to=make_solution_file_path) I have encountered two problems: When saving data to a fix...

How do you use Relative Paths for Twill tests?

I've been working with an open source project that it not working correctly in Production but does work in Development. I believe I will need to refactor part of the project. The project has no tests, so I'm trying to learn how to use Twill to verify that my refactoring doesn't break the project during Development. I also want to be ab...

How can I interactively explore why a test is failing?

I have a test that is failing with: ====================================================================== FAIL: test_register_should_create_UserProfile (APP.forum.tests.test_views.UserTestCAse) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Us...

How do you add OpenId session data to a Django test client POST?

I'm trying to test that a UserProfile model is created as a new User is registered in django_authopenid. I don't understand how to add the Openid session data to the POST. class UserTestCAse(TestCase): def test_register_should_create_UserProfile(self): from django.test.client import Client c = Client() response = c.p...

is there a way to get django tests + buildout run well integrated with Eclipse/Aptana?

Hi, it's fairly easy to set up Eclipse to run a django project's tests created with django-admin startprojects, we whould just point a Run command to ./manage.py, and supply the necessary arguments. but what can I do if a project is built using buildout? of course, bin/biuldout creates the handy bin/test-1.1 and bin/test-trunk files, ...

Django - Testing with parts of original database

Hello everyone, My database has two types of entries: The very dynamic (users, comments, etc) and the more static (email templates, flat-pages). During testing I want a clean DB but with the real 'semi-static' data. Is there a way to make Django's testing system to load parts of the original DB ? Thanks ...

Why isn't django-nose running the doctests in my models?

I'm trying to use doctests with django-nose. All my doctests are running, except not any doctests within a model (unless it is abstract). class TestModel1(models.Model): """ >>> print 'pass' pass """ pass class TestModel2(models.Model): """ >>> print 'pass' pass """ class Meta: abstract ...