Fix database connection leak in tests

Without this, each flask app created in tests will hold
one database connection until all tests are finished. This may result
in test failure if database limits number of concurrent connections.
Implement py.test fixtures for database and flask application

Allows to set up database schema only once per test run, yet providing
clean environment for each test. Also, easier to use and reduces
setup/teardown code duplication in tests.

Reduces test time by ~50%.
Merge pull request #220 from kedder/for-upstream

Improve testing framework