Skip to content
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

Issue57 fix #2

Closed
wants to merge 3 commits into from
Closed

Issue57 fix #2

wants to merge 3 commits into from

Conversation

bendemboski
Copy link
Owner

Unit tests and a fix for wlanslovenija#57.

I also fixed an issue I ran into with the database connections in the unit tests.

Ben Demboski added 3 commits August 4, 2013 23:09
…e classes get loaded before the test runner's setup_databases() is called. When the resource classes are loaded, they create their default querysets, which save off database connections (wrapped in collection objects). Since this happens before setup_databases(), all of these connections will point to settings.MONGO_DATABASE_NAME because of the connect() call in settings.py. Then, before the tests actually start, setup_databases() is called, which opens a new connection to ('test_%s' % settings.MONGO_DATABASE_NAME) under the same alias. At this point all the resource classes have their connections to the original (wrong) database, so unit tests that just access the database through the API work fine. But if unit tests want to access the database directly through the ORM, then a new connection will be created and will point to the new (correct) database. Obviously this will lead to problems because different methods of access "the database" are using different connections to different databases!

The test runner module is loaded after settings.py, but before the test discovery loads all the resources, so adding a connect() call at module load time fixes the issue.
@bendemboski bendemboski closed this Aug 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant