In a project I have some Plone REST API endpoints that get some inputs and register some information in an annotation.
We have an extensive set of tests, both testing the utility that writes the annotation and also testing the REST API endpoints, its results with different inputs, and checks that everything is being written correctly in the annotation.
So far so good.
Now we are evaluating to save the information in a RDBMS because of some limitations and ConflictErrors that we are having in production.
As we have a utility to do the annotation writing things, I have replaced the implementation quite easily using SQLAlchemy and writing the data to PostgreSQL without much issues.
But when I run the tests, I find a lot of issues because the REST API doesn't find the data in the database.
To run those tests, instead of using PostgreSQL, I am using SQLite, but initially I was running them with PostgreSQL and I was having the same issues.
For the test layer setup, I am using a WSGI_SERVER_FIXTURE
much like it is done in plone.restapi to test the endpoints.
For instance, to test the endpoint that deletes some data from the database, I populate first the database, I issue the relevant API request, and when executing the request I find the database empty, even uninitialized.
It looks like I can't populate correctly the data from the same test session that I use to query it, because they live in another session.
For the database setup I am using z3c.saconfig which internally is using zope.sqlalchemy which has zope.transation integration.
I have been looking at GitHub - euphorie/Euphorie: Euphorie is a tool for risk assessment which has an extensive set of tests, and also is using sqlalchemy to do those tests, but in that case it is using Browser tests and not REST API tests, and I don't know whether it can be any difference there.
I will keep investigating, but any hint will be appreciated. I will try to modify how I populate the database in the tests.