-
Notifications
You must be signed in to change notification settings - Fork 347
Test with two database where one is external and readonly #828
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
Comments
Multiple dbs are not really well supported currently - there are existing issues in that regard already, and maybe even stalled PRs. Please look around there. I'd be happy to help with getting this solved, of course - it's just a bit tricky and it would be great if you could help there. |
@blueyed I've been looking at related issues PRs but they are more focused to support actual testing over multiple DB's which isn't exactly my case. Also, they are based on manipulating the Because of the way Django handles initialization one cannot simply override Since my application doesn't create users but I have to be able to make authenticated requests with the test client I managed to fake the User model with the help of factory boy so I could inject a fake user to make authenticated requests work nicely. Not being able to use hierarchical settings for tests is the main drawback of my workaround because I have to keep in sync the settings for tests with the ones in However, I couldn't find a way to make |
I'm running into a similar issue with an external read-only transaction (not 'transactional') database. I have functions that query this database and load information into the primary db. It is setup in @blueyed I've seen your comment here and haven't quite been able to get that to work. |
I'll be opening a new issue on multi-db support, I'll close this one as a duplicate. |
after research, explore and read many documents about how to test a legacy read-only database , If you only want to execute tests using legacy database as a test database, the best and simple solution is to setup the same legacy database as a MIRROR in the TEST configuration of the database. I know, it's not a good practice but this solves my need. Example: {
'default': {
'ENGINE': get_secret("DEFAULT_ENGINE_DB_LOCAL"),
'NAME': get_secret("DEFAULT_NAME_DB_LOCAL"),
'HOST': get_secret("DEFAULT_HOST_DB_LOCAL"),
....
},
'legacy_db': {
'ENGINE': get_secret("SIESA_ENGINE_DB_LOCAL"),
'NAME': get_secret("SIESA_NAME_DB_LOCAL"),
'HOST': get_secret("SIESA_HOST_DB_LOCAL"),
....
'TEST': {
'MIRROR': 'legacy_db',
}
} also, you can use it with --keepdb command to avoid creating a new test database for your default I am working with Django 2.2 |
I have a Django application
A
that takes the user's data from another Django applicationB
with its own database. So basically I implemented a Django database router so the users are taken from a an external database with read-only permissions because the applicationA
not creating users.As a result, I have two databases in my settings.:
Being
auth_db
the external read-only database. I've been trying to tell pytest-django with the help of asettings.test
to simply create the users database on thelocal
database with the following:But for some reason I cannot explain I still get the same error:
I honestly don't event create any users for tests since I tell factory boy to use a build strategy for the User factory and I use the factory so I can force Django Restf to make authenticated calls.
So I don't know what else I could do. Any Ideas?
The text was updated successfully, but these errors were encountered: