Author: Alex
Date: 2009-12-22 00:08:15 -0600 (Tue, 22 Dec 2009)
New Revision: 11939
Modified:
django/branches/soc2009/multidb/django/db/models/loading.py
django/branches/soc2009/multidb/tests/modeltests/defer/models.py
django/branches/soc2009/multidb/tests/regressiontests/defer_regress/models.py
django/branches/soc2009/multidb/tests/regressiontests/test_runner/tests.py
Log:
[soc2009/multidb] Merged up to trunk r11938.
Modified: django/branches/soc2009/multidb/django/db/models/loading.py
===================================================================
--- django/branches/soc2009/multidb/django/db/models/loading.py 2009-12-22
06:01:23 UTC (rev 11938)
+++ django/branches/soc2009/multidb/django/db/models/loading.py 2009-12-22
06:08:15 UTC (rev 11939)
@@ -132,7 +132,7 @@
self._populate()
return self.app_errors
- def get_models(self, app_mod=None, include_auto_created=False):
+ def get_models(self, app_mod=None, include_auto_created=False,
include_deferred=False):
"""
Given a module containing models, returns a list of the models.
Otherwise returns a list of all installed models.
@@ -140,21 +140,28 @@
By default, auto-created models (i.e., m2m models without an
explicit intermediate table) are not included. However, if you
specify include_auto_created=True, they will be.
+
+ By default, models created to satisfy deferred attribute
+ queries are *not* included in the list of models. However, if
+ you specify include_deferred, they will be.
"""
- cache_key = (app_mod, include_auto_created)
+ cache_key = (app_mod, include_auto_created, include_deferred)
try:
return self._get_models_cache[cache_key]
except KeyError:
pass
self._populate()
if app_mod:
- model_list = self.app_models.get(app_mod.__name__.split('.')[-2],
SortedDict()).values()
+ app_list = [self.app_models.get(app_mod.__name__.split('.')[-2],
SortedDict())]
else:
- model_list = []
- for app_entry in self.app_models.itervalues():
- model_list.extend(app_entry.values())
- if not include_auto_created:
- model_list = filter(lambda o: not o._meta.auto_created, model_list)
+ app_list = self.app_models.itervalues()
+ model_list = []
+ for app in app_list:
+ model_list.extend(
+ model for model in app.values()
+ if ((not model._deferred or include_deferred)
+ and (not model._meta.auto_created or include_auto_created))
+ )
self._get_models_cache[cache_key] = model_list
return model_list
Modified: django/branches/soc2009/multidb/tests/modeltests/defer/models.py
===================================================================
--- django/branches/soc2009/multidb/tests/modeltests/defer/models.py
2009-12-22 06:01:23 UTC (rev 11938)
+++ django/branches/soc2009/multidb/tests/modeltests/defer/models.py
2009-12-22 06:08:15 UTC (rev 11939)
@@ -183,10 +183,4 @@
>>> obj.name = "bb"
>>> obj.save()
-# Finally, we need to flush the app cache for the defer module.
-# Using only/defer creates some artifical entries in the app cache
-# that messes up later tests. Purge all entries, just to be sure.
->>> from django.db.models.loading import cache
->>> cache.app_models['defer'] = {}
-
"""}
Modified:
django/branches/soc2009/multidb/tests/regressiontests/defer_regress/models.py
===================================================================
---
django/branches/soc2009/multidb/tests/regressiontests/defer_regress/models.py
2009-12-22 06:01:23 UTC (rev 11938)
+++
django/branches/soc2009/multidb/tests/regressiontests/defer_regress/models.py
2009-12-22 06:08:15 UTC (rev 11939)
@@ -136,11 +136,14 @@
>>> i2._deferred # Item must still be non-deferred
False
-# Finally, we need to flush the app cache for the defer module.
-# Using only/defer creates some artifical entries in the app cache
-# that messes up later tests. Purge all entries, just to be sure.
->>> from django.db.models.loading import cache
->>> cache.app_models['defer_regress'] = {}
+# Regression for #11936 - loading.get_models should not return deferred models
by default.
+>>> from django.db.models.loading import get_models
+>>> sorted(get_models(models.get_app('defer_regress')), key=lambda obj:
obj.__class__.__name__)
+[<class 'regressiontests.defer_regress.models.Item'>, <class
'regressiontests.defer_regress.models.RelatedItem'>, <class
'regressiontests.defer_regress.models.Child'>, <class
'regressiontests.defer_regress.models.Leaf'>]
+>>> sorted(get_models(models.get_app('defer_regress'), include_deferred=True),
key=lambda obj: obj.__class__.__name__)
+[<class 'regressiontests.defer_regress.models.Item'>, <class
'regressiontests.defer_regress.models.RelatedItem'>, <class
'regressiontests.defer_regress.models.Child'>, <class
'regressiontests.defer_regress.models.Leaf'>, <class
'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class
'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>,
<class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>,
<class
'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>,
<class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class
'regressiontests.defer_regress.models.Item_Deferred_name'>, <class
'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>,
<class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>]
+
"""
}
+
Modified:
django/branches/soc2009/multidb/tests/regressiontests/test_runner/tests.py
===================================================================
--- django/branches/soc2009/multidb/tests/regressiontests/test_runner/tests.py
2009-12-22 06:01:23 UTC (rev 11938)
+++ django/branches/soc2009/multidb/tests/regressiontests/test_runner/tests.py
2009-12-22 06:08:15 UTC (rev 11939)
@@ -4,25 +4,25 @@
import StringIO
import unittest
import django
-from django.test import TestCase, TransactionTestCase, simple
+from django.test import simple
-class DjangoTestRunnerTests(TestCase):
-
+class DjangoTestRunnerTests(unittest.TestCase):
+
def test_failfast(self):
- class MockTestOne(TransactionTestCase):
+ class MockTestOne(unittest.TestCase):
def runTest(self):
assert False
- class MockTestTwo(TransactionTestCase):
+ class MockTestTwo(unittest.TestCase):
def runTest(self):
assert False
-
+
suite = unittest.TestSuite([MockTestOne(), MockTestTwo()])
mock_stream = StringIO.StringIO()
dtr = simple.DjangoTestRunner(verbosity=0, failfast=False,
stream=mock_stream)
result = dtr.run(suite)
self.assertEqual(2, result.testsRun)
self.assertEqual(2, len(result.failures))
-
+
dtr = simple.DjangoTestRunner(verbosity=0, failfast=True,
stream=mock_stream)
result = dtr.run(suite)
self.assertEqual(1, result.testsRun)
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.