Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a unit test against the production database?

How do I run a unit test against the production database instead of the test database?

I have a bug that's seems to occur on my production server but not on my development computer.

I don't care if the database gets trashed.

like image 442
BryanWheelock Avatar asked Apr 06 '10 23:04

BryanWheelock


2 Answers

Is it feasible to make a copy the database, or part of the database that causes the problem? If you keep a backup server, you might be able to copy the data from there instead (make sure you have another backup, in case you messed the backup database).

Basically, you don't want to mess with live data and you don't want to be left with no backup in case you mess something up (and you will!).

like image 179
Lie Ryan Avatar answered Sep 21 '22 17:09

Lie Ryan


Use manage.py dumpdata > mydata.json to get a copy of the data from your database.

Go to your local machine, copy mydata.json to a subdirectory of your app called fixtures e.g. myapp/fixtures/mydata.json and do:

manage.py syncdb # Set up an empty database
manage.py loaddata mydata.json

Your local database will be populated with data and you can test away.

like image 34
blokeley Avatar answered Sep 21 '22 17:09

blokeley