-
Notifications
You must be signed in to change notification settings - Fork 27
Replace DatabaseWrapper.__getattr__() with a simpler database attribute #287
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.db import connection | ||
from django.db.backends.signals import connection_created | ||
from django.test import SimpleTestCase, TestCase | ||
|
||
from django_mongodb_backend.base import DatabaseWrapper | ||
|
@@ -21,3 +22,23 @@ def test_set_autocommit(self): | |
self.assertIs(connection.get_autocommit(), False) | ||
connection.set_autocommit(True) | ||
self.assertIs(connection.get_autocommit(), True) | ||
|
||
def test_connection_created_database_attr(self): | ||
""" | ||
connection.database is available in the connection_created signal. | ||
""" | ||
data = {} | ||
|
||
def receiver(sender, connection, **kwargs): # noqa: ARG001 | ||
data["database"] = connection.database | ||
|
||
connection_created.connect(receiver) | ||
connection.close() | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also assert that data is empty after calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certainly could, but if |
||
# Accessing database implicitly connects. | ||
connection.database # noqa: B018 | ||
self.assertIs(data["database"], connection.database) | ||
connection.close() | ||
connection_created.disconnect(receiver) | ||
data.clear() | ||
connection.connect() | ||
self.assertEqual(data, {}) |
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.
So we now won't raise an error if something other than
database
isThere 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.
The default implementation of
__getattr__()
raisesAttributeError
.