We can refactor the database session handling to always begin with the lambda handler and then pass the session into all of the querying functions. This speeds up the database access by keeping the same connection alive for all queries rather than requesting a new one each time. This also makes the tests easier to mock and inject our test sessions by patching the module-level session factory.
Testing
Rather than using a fixture to populate the databases, I switched it over to explicitly call the function from within the test so that we are only populating what needs to be populated and isolating the tests. I think this makes it more explicit what is happening, but I could be convinced to leave the setup/populate functions as a fixture if people prefer that style.
Change Summary
Overview
We can refactor the database session handling to always begin with the lambda handler and then pass the session into all of the querying functions. This speeds up the database access by keeping the same connection alive for all queries rather than requesting a new one each time. This also makes the tests easier to mock and inject our test sessions by patching the module-level session factory.
Testing
Rather than using a fixture to populate the databases, I switched it over to explicitly call the function from within the test so that we are only populating what needs to be populated and isolating the tests. I think this makes it more explicit what is happening, but I could be convinced to leave the setup/populate functions as a fixture if people prefer that style.