Commit Graph

11 Commits

Author SHA1 Message Date
Leo Hemsted
6181c60f75 remove usage of notify_db fixture in unit tests
* notify_db fixture creates the database connection and ensures the test
  db exists and has migrations applied etc. It will run once per session
  (test run).
* notify_db_session fixture runs after your test finishes and deletes
  all non static (eg type table) data.

In unit tests that hit the database (ie: most of them), 99% of the time
we will need to use notify_db_session to ensure everything is reset. The
only time we don't need to use it is when we're querying things such as
"ensure get X works when database is empty". This is such a low
percentage of tests that it's easier for us to just use
notify_db_session every time, and ensure that all our tests run much
more consistently, at the cost of a small bit of performance when
running tests.

We used to use notify_db to access the session object for manually
adding, committing, etc. To dissuade usage of that fixture I've moved
that to the `notify_db_session`. I've then removed all uses of notify_db
that I could find in the codebase.

As a note, if you're writing a test that uses a `sample_x` fixture, all
of those fixtures rely on notify_db_session so you'll get the teardown
functionality for free. If you're just calling eg `create_x` db.py
functions, then you'll need to make you add notify_db_session fixture to
your test, even if you aren't manually accessing the session.
2022-05-04 11:36:54 +01:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
Ken Tsang
de7ad6fb95 Refactored service_permissions data model 2017-05-22 17:25:58 +01:00
kentsanggds
f5d3eed7e0 Revert "Refactored service permissisons data model" 2017-05-22 16:05:31 +01:00
Ken Tsang
28ef9a1853 Refactored service permissisons data model 2017-05-22 10:58:41 +01:00
Ken Tsang
54446d5f4d Add default permissions when creating a service 2017-05-17 14:18:12 +01:00
Ken Tsang
2a48891025 Removed unused pytest from test 2017-05-16 12:54:32 +01:00
Ken Tsang
b233ae46f3 Tidy up test code for service permissions 2017-05-16 12:53:46 +01:00
Ken Tsang
733c16b2bb Update to strip down DAO and clarify tests 2017-05-16 12:33:27 +01:00
Ken Tsang
54d801979c Refactored to handle single service permission 2017-05-16 10:57:57 +01:00
Ken Tsang
114d4d84d4 Add service permissions DAO and refactor user service permission mock 2017-05-15 17:28:14 +01:00