-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spin up separate database for pytest execution #235
Conversation
In this current state the two databases are created successfully but it requires we add this script that comes from a separate repo. It is possible to use a image that includes this script but I don't see why we would do that tbh as it would be limiting.
|
One alternative that is mentioned in the stackoverflow post i linked is to just have two different containers each with a different database to be created. This to me seems almost like a better solution just for the sake of simplicity.
|
my workflow is usually to run Even though its maybe a bit more clunky, i think using the script is a little bit smoother and more scalable for now. There's also a fair argument to be made for what this even solves given our current setup. Hopefully people wouldn't be spinning up a database with those credentials and then running the tests in their production environment? |
I'm ok with either solution but I'm now wondering if there is an actual problem to solve here, but I'm probably overlooking something @NevilleS @seanpreston @ethyca/fides-control any thoughts here? |
It seems like the original concern was to avoid potential impact to production data. I think that's probably worth putting some safe guards around. The script seems like a better option than trying to a esoteric docker image, imho. I would suggest maybe adding a comment stating where it came from for posterity, though. |
we have a separate |
That script (that leverages postgres' init scripts) isn't the only way to create a DB though- in In other words, if the |
nice! beautiful solution |
Is it possible that the solution posted doesn't actually do what it is meant to? At least for our fidesctl setup it doesn't seem to work well because tests are running in a different process than the api service. When we run Maybe I am missing something but you shouldn't be able to modify the environment variables from a different python process. For now I posted a working solution where we temporarily set the context server side through the api. This is working as we'd want and achieves the same as the fidesops example. This solution still feels not great to me though, but I can't think of any other way that the tests could interact with the server's context other than through the api. |
I agree it feels super weird to have code logic dedicated to spinning up a test database, that feels super bad. If the assumption here is that this ticket exists specifically so that people don't overwrite their production data, what is the simplest way to do that? I think the simplest way is to do the following:
@earmenda does this implementation make sense? does it seem reasonably elegant? Open to other suggestions, after some thought this is the cleanest I could think of |
I think the new config is a good idea but that still means that the execution of pytest would have to indicate to the server that it needs to use that database. Don't we still have that problem with this solution? Were you thinking that the service has a flag which either starts it in default or test domain to determine which database to use? |
Here is what I currently see as some options
|
I think the second option is the best. Maybe the API can check for a |
What do you think about this?
With this tests don't really have to do too much differently. I know you mentioned adding a check for whether the test database is being used from the tests but I don't see that much value to that to be honest. If this looks good I just need to add the variable to our make commands. We could make sure that |
With the latest change it is possible to start the server using make by passing in test mode as a parameter
Verified that this starts the service in test mode
|
Verified that starting the server in test mode will use the expected database
Verified that only the test database is used even after successfully running
|
Added some tests to validate the setting of |
@earmenda sorry for hijacking this at the end! You nailed the requirements, I just had a few nits and didn't want to keep kicking it back to you for those small things Thank you! |
no worries, just added a comment to your change though |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #121
Code Changes
test_database_url
config to access the databasemake pytest
target to set FIDESCTL_TEST_MODE to truemake api
andmake cli
to allow passing in a FIDESCTL_TEST_MODE.make api FIDESCTL_TEST_MODE=True
test_config.py
Steps to Confirm
Pre-Merge Checklist
Description Of Changes
The original issue Have Pytest spin up its own test database #121 I think had the impression that this was natively supported but it requires a script to be executed which comes from a github repo. See here: https://stackoverflow.com/questions/46668233/multiple-databases-in-docker-and-docker-composeTest database creation is now done through a fixtureServer context for tests is set through an api but I am still thinking about whether this is a good way to go about thisFIDESCTL_TEST_MODE
test_database_url
will be used to access the database