summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-05-13 11:59:27 -0400
committerSimon Charette <charette.s@gmail.com>2016-05-15 19:51:16 -0400
commit61a16e02702fff4665969388f3b61af8cb1a20ae (patch)
tree5dbc9b622e5e1e37fb1d02943b3ec56c76b08235 /tests/contenttypes_tests
parentf937c9ec975ebd719f0c22e5d1d5f5fb87ff1edd (diff)
Fixed #24075 -- Used post-migration models in contrib apps receivers.
Thanks Markus and Tim for the review.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/test_models.py26
-rw-r--r--tests/contenttypes_tests/tests.py10
2 files changed, 11 insertions, 25 deletions
diff --git a/tests/contenttypes_tests/test_models.py b/tests/contenttypes_tests/test_models.py
index d388990c06..18795f9633 100644
--- a/tests/contenttypes_tests/test_models.py
+++ b/tests/contenttypes_tests/test_models.py
@@ -3,9 +3,8 @@ from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType, ContentTypeManager
from django.contrib.contenttypes.views import shortcut
from django.contrib.sites.shortcuts import get_current_site
-from django.db.utils import IntegrityError, OperationalError, ProgrammingError
from django.http import Http404, HttpRequest
-from django.test import TestCase, mock, override_settings
+from django.test import TestCase, override_settings
from django.utils import six
from .models import (
@@ -243,26 +242,3 @@ class ContentTypesTests(TestCase):
# Instead, just return the ContentType object and let the app detect stale states.
ct_fetched = ContentType.objects.get_for_id(ct.pk)
self.assertIsNone(ct_fetched.model_class())
-
- @mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get_or_create')
- @mock.patch('django.contrib.contenttypes.models.ContentTypeManager.get')
- def test_message_if_get_for_model_fails(self, mocked_get, mocked_get_or_create):
- """
- Check that `RuntimeError` with nice error message is raised if
- `get_for_model` fails because of database errors.
- """
-
- def _test_message(mocked_method):
- for ExceptionClass in (IntegrityError, OperationalError, ProgrammingError):
- mocked_method.side_effect = ExceptionClass
- with self.assertRaisesMessage(
- RuntimeError,
- "Error creating new content types. Please make sure contenttypes "
- "is migrated before trying to migrate apps individually."
- ):
- ContentType.objects.get_for_model(ContentType)
-
- _test_message(mocked_get)
-
- mocked_get.side_effect = ContentType.DoesNotExist
- _test_message(mocked_get_or_create)
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index da4b3311c4..5db01773a4 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -404,6 +404,16 @@ class UpdateContentTypesTests(TestCase):
self.assertIn("Stale content types remain.", stdout.getvalue())
self.assertEqual(ContentType.objects.count(), self.before_count + 1)
+ def test_unavailable_content_type_model(self):
+ """
+ #24075 - A ContentType shouldn't be created or deleted if the model
+ isn't available.
+ """
+ apps = Apps()
+ with self.assertNumQueries(0):
+ management.update_contenttypes(self.app_config, interactive=False, verbosity=0, apps=apps)
+ self.assertEqual(ContentType.objects.count(), self.before_count + 1)
+
class TestRouter(object):
def db_for_read(self, model, **hints):