开发者

Have different initial_data fixtures for different stages (testing v. production)

I have an initial_data fixture that I want to load everytime except for production. I already have different settings file for production and non-production deployments.

Any suggestions on how to accomplish this?

Clarification: I do not want test fixtures. Basically, I开发者_StackOverflow just need the fixture to be loaded based on a setting change of some sort. I'll be digging into the Django code to see if I could figure out an elegant way to accomplish this.


You can actually setup different test fixtures for each test if you want: http://docs.djangoproject.com/en/dev/topics/testing/#topics-testing-fixtures

If you only want to load the fixtures in one time, you can also write a custom TestRunner that will allow you to do that setup at the beginning:

docs.djangoproject.com/en/dev/topics/testing/#using-different-testing-frameworks

Both of those will still load the data from the production fixtures as that is done with syncdb, but you can override the data, or even delete it all. This may not be optimal if you are loading large amounts of data into your production product. If this is the case, I would recommend you adding a custom command like load_production_data that allows you to do it quickly and easily from the command line.


The easiest way is to use manage.py testserver [fixture ...]

If this is a staging (rather than dev) deployment, though, you may not want to use django's builtin server. In that case, a quick (if hacky) way of doing what you're after is to have the fixtures in an app (called, for example, "undeployed") that is only installed in your non-production settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜