mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[soc2010/query-refactor] Implement a few methods to the point of tests actually running under mongodb (all failing of course).
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13331 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0813aa4614
commit
4c45befaad
@ -1,5 +1,38 @@
|
|||||||
|
from pymongo import Connection
|
||||||
|
|
||||||
from django.db.backends import BaseDatabaseWrapper
|
from django.db.backends import BaseDatabaseWrapper
|
||||||
|
from django.db.backends.signals import connection_created
|
||||||
|
from django.contrib.mongodb.creation import DatabaseCreation
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseFeatures(object):
|
||||||
|
interprets_empty_strings_as_nulls = False
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseOperations(object):
|
||||||
|
def max_name_length(self):
|
||||||
|
return 254
|
||||||
|
|
||||||
|
def value_to_db_datetime(self, value):
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
pass
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
self.features = DatabaseFeatures()
|
||||||
|
self.ops = DatabaseOperations()
|
||||||
|
self.creation = DatabaseCreation(self)
|
||||||
|
self._connection = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def connection(self):
|
||||||
|
if self._connection is None:
|
||||||
|
self._connection = Connection(self.settings_dict["HOST"],
|
||||||
|
self.settings_dict["PORT"] or None)
|
||||||
|
connection_created.send(sender=self.__class__)
|
||||||
|
return self._connection
|
||||||
|
|
||||||
|
def _rollback(self):
|
||||||
|
# TODO: ???
|
||||||
|
pass
|
||||||
|
20
django/contrib/mongodb/creation.py
Normal file
20
django/contrib/mongodb/creation.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from django.db.backends.creation import TEST_DATABASE_PREFIX
|
||||||
|
|
||||||
|
|
||||||
|
class DatabaseCreation(object):
|
||||||
|
def __init__(self, connection):
|
||||||
|
self.connection = connection
|
||||||
|
|
||||||
|
def create_test_db(self, verbosity, autoclobber):
|
||||||
|
if self.connection.settings_dict['TEST_NAME']:
|
||||||
|
test_database_name = self.connection.settings_dict['TEST_NAME']
|
||||||
|
else:
|
||||||
|
test_database_name = TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
|
||||||
|
self.connection.settings_dict["NAME"] = test_database_name
|
||||||
|
return test_database_name
|
||||||
|
|
||||||
|
def destroy_test_db(self, old_database_name, verbosity=1):
|
||||||
|
if verbosity >= 1:
|
||||||
|
print "Destroying test database '%s'..." % self.connection.alias
|
||||||
|
self.connection.connection.drop_database(self.connection.settings_dict["NAME"])
|
||||||
|
self.connection.settings_dict["NAME"] = old_database_name
|
Loading…
x
Reference in New Issue
Block a user