I want to know the best/different ways to test a REST API which uses a database backend. I've developed my API with Flask in Python and want to use unittest or nose.
But my problem, is that some resources require another resource to create them in the first place. Is there a way to say that to test the creation of a blog post requires that another test involving the creation of the author was successful?
There are 2 standard ways of approaching a test that depends on something else (object, function call, etc).
Some people like "classical" unit tests where only the "unit" of code is tested. In these cases you typically use mocks and stubs to replace the dependencies.
Other like more integrative tests where most or all of the call stack is tested. In these cases you use a fixture, or possibly even do calls/creations in a setup function.
Generally you would not make one test depend on another. All tests should:
If you make one test dependent on another they cannot be run in isolation and you are also forcing an order to the tests run. Enforcing order in tests isn't good, in fact many people feel you should randomize the order in which your tests are run.
The unit test should work in isolated mode so you have to isolate your dependent resources and this done using isolation an framework (mocking framework). Common frameworks for legacy, Windows systems are DevMagicFake, MOQ, Rhino Mocks, TypeMock.
DevMagicFake will make you able to fake the DB so you will not need to create DB or even any code to save your data because it save your data in memory and you can retrieve it anytime.