1

Currently I have big application with huge amount of initial data. Basicly, I have postgresql dump file and I should apply some migrations to get "good database". And application got almost no fixtures to recreate initial data on sync/migrate.

Yes, this is a big pain in the... head.

Anyway, Django copies database to perform testing and everything should work fine. But the problem is - it takes really long time.

I'm thinking about creating custom test-runner to reproduce these operations, but I want to ask you! What you can suggest?

dt0xff
  • 1,553
  • 1
  • 10
  • 18
  • Do you really need to test the application with all the initial data? – iferminm Jan 11 '13 at 13:21
  • Yea, you could just strip the initial data to a minimum. Or create new data? – Rickard Zachrisson Jan 11 '13 at 13:38
  • Sadly, I can't. Because code is so bloated, I need a lot of time to discover what I really need. It is not an option, because I got work to do. I can make some simple tests using unittest2 and it will be fine for most parts. But... I really want to get ability to test everything I made, not just an usual parts of inner logic. – dt0xff Jan 11 '13 at 15:01

2 Answers2

1

There are a lot of nice answers on unit-testing with a lot of data

I have these two on my favorites

This one by me Unit Testing with Django Models and a lot of relations involved

and this one by a friend What are the best practices for testing "different layers" in Django?

You could use a library like FactoryBoy to create as many instances of your models as you want, with different characteristics to test several cases. Here is the doc page for FactoryBoy

Edit after chat:

It seems that defining your own test runner is the way to go in this case.

https://docs.djangoproject.com/en/1.2/topics/testing/#defining-a-test-runner

Community
  • 1
  • 1
iferminm
  • 2,019
  • 19
  • 34
  • FactoryBoy is awesome. I like factory_girl, really. But it is a good answer for questiong "I gate Django fixtures. What should i do?" and I want to say you "thank you", because I'll use it now. Also, I should say you "tank you" for a link to a page, where I finally understood what "mocking" is for. And it solves another my testing problem - with external services. But for now, I want to deal with Django tests just to get it run. – dt0xff Jan 11 '13 at 15:24
  • Yes, if you have a lot of changes in your model frequently fixtures are unmaintainable. If there are a lot of test cases, and not that much time, you can try covering the border cases for the moment and expanding the test coverage later. It's always good to create data just for testing, that way you can control your test. – iferminm Jan 11 '13 at 16:03
  • Thank you. But the problem is, I want to use "./manage.py test". It tries to recreate copy of my databases, but databases are huge. Maybe you can suggest how to avoid this, but with ability to use all Django testing functions, classes? Can FacrotyBoy clear all things w/o "rollback" of all DB/recreating testing DB? – dt0xff Jan 11 '13 at 16:08
  • Sorry, I missunderstood your question, maybe what you need is to specify a testing database with all the data you need, that way Django doesn't copy your production database and just create a connection to the specified database. http://stackoverflow.com/questions/4809393/specify-django-test-database-names-in-settings-py maybe that could help – iferminm Jan 11 '13 at 16:17
  • Oh, mayb eit should solve my problem. But if I'll set "test_name", Django will not recreate DB at starting of tests? Because this is what I need, I think. – dt0xff Jan 11 '13 at 16:25
  • I think this is what you need http://django-test-utils.readthedocs.org/en/latest/keep_database_runner.html it is in this other question http://stackoverflow.com/questions/7197699/django-unit-test-without-creating-test-database-everytime-i-run – iferminm Jan 11 '13 at 16:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22597/discussion-between-israelord-and-dt0xff) – iferminm Jan 11 '13 at 16:35
0

Try to use Mixer:

from mixer.backend.django import mixer

mixer.blend(MyModel)
klen
  • 1,595
  • 12
  • 11