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 #62

Closed
wants to merge 3 commits into from
Closed

Conversation

bendemboski
Copy link

Unit tests and a fix for #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.
@mitar
Copy link
Member

mitar commented Aug 5, 2013

Please make another pull request for database issues.

connect(DB_NAME, **getattr(settings, 'MONGO_DATABASE_OPTIONS', {}))


# We need to call this at module load time, because unit test discover will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? I thought I fixed this with this code? Maybe some Tastypie version broke that? I know that they changed in few versions back how this behave (removed _reset_already_indexed as well). I thought that you don't cache the connection anymore?

We should maybe make a test for that?

@mitar
Copy link
Member

mitar commented Aug 5, 2013

Please sign-off your pull request.

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.

2 participants