summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorErik Romijn <erik@erik.io>2016-07-03 15:55:14 +0200
committerFlorian Apolloner <apollo13@users.noreply.github.com>2016-07-03 15:55:14 +0200
commit8db889eaf7dce0cb715b075be32047c1b1b316da (patch)
tree13a52c3c21615067a22906a00b829bd70df951d1 /tests/contenttypes_tests
parentf7e00b40c558967d697529b7ed55c5fb82396e6d (diff)
Fixed #18682 -- Expanded explanation in stale content type deletion. (#6869)
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/tests.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index 123e169fbc..5c8c675a4a 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -20,7 +20,7 @@ from django.test.utils import captured_stdout, isolate_apps
from django.utils.encoding import force_str, force_text
from .models import (
- Article, Author, ModelWithNullFKToSite, SchemeIncludedURL,
+ Article, Author, ModelWithNullFKToSite, Post, SchemeIncludedURL,
Site as MockSite,
)
@@ -383,13 +383,27 @@ class GenericRelationshipTests(SimpleTestCase):
class UpdateContentTypesTests(TestCase):
def setUp(self):
self.before_count = ContentType.objects.count()
- ContentType.objects.create(app_label='contenttypes_tests', model='Fake')
+ self.content_type = ContentType.objects.create(app_label='contenttypes_tests', model='Fake')
self.app_config = apps.get_app_config('contenttypes_tests')
- def test_interactive_true(self):
+ def test_interactive_true_with_dependent_objects(self):
"""
interactive mode of update_contenttypes() (the default) should delete
- stale contenttypes.
+ stale contenttypes and warn of dependent objects
+ """
+ Post.objects.create(title='post', content_type=self.content_type)
+ contenttypes_management.input = lambda x: force_str("yes")
+ with captured_stdout() as stdout:
+ contenttypes_management.update_contenttypes(self.app_config)
+ self.assertEqual(Post.objects.count(), 0)
+ self.assertIn("1 object of type contenttypes_tests.post:", stdout.getvalue())
+ self.assertIn("Deleting stale content type", stdout.getvalue())
+ self.assertEqual(ContentType.objects.count(), self.before_count)
+
+ def test_interactive_true_without_dependent_objects(self):
+ """
+ interactive mode of update_contenttypes() (the default) should delete
+ stale contenttypes and inform there are no dependent objects
"""
contenttypes_management.input = lambda x: force_str("yes")
with captured_stdout() as stdout: