diff options
| author | Nick Sandford <nick@sandford.id.au> | 2014-07-23 04:01:55 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-07-23 08:49:55 -0400 |
| commit | 9638daec5cb584dc3b62b7373e0f7cd2fc808b7e (patch) | |
| tree | 87743dbe334a4853048aee3b0d7796bc025e6c7c /tests/contenttypes_tests | |
| parent | ddb5674945725ec8f6e6336f73d3d56e331f34ae (diff) | |
[1.7.x] Fixed #23078 -- Regression in update_contenttypes() interactivity.
Thanks raymond at adaptiv.nl for the report.
Backport of fa3cf006b2 from master
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/tests.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index 085ad2ec89..ee4821ae4b 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -1,16 +1,20 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals +import sys + from django.apps.registry import Apps, apps from django.contrib.contenttypes.fields import ( GenericForeignKey, GenericRelation ) +from django.contrib.contenttypes import management from django.contrib.contenttypes.models import ContentType from django.core import checks from django.db import models from django.test import TestCase from django.test.utils import override_settings from django.utils.encoding import force_str +from django.utils.six import StringIO from .models import Author, Article, SchemeIncludedURL @@ -335,3 +339,37 @@ class GenericRelationshipTests(IsolatedModelsTestCase): ) ] self.assertEqual(errors, expected) + + +class UpdateContentTypesTests(TestCase): + def setUp(self): + self.before_count = ContentType.objects.count() + ContentType.objects.create(name='fake', app_label='contenttypes_tests', model='Fake') + self.app_config = apps.get_app_config('contenttypes_tests') + + def test_interactive_true(self): + """ + interactive mode of update_contenttypes() (the default) should delete + stale contenttypes. + """ + self.old_stdout = sys.stdout + sys.stdout = StringIO() + management.input = lambda x: force_str("yes") + management.update_contenttypes(self.app_config) + output = sys.stdout.getvalue() + sys.stdout = self.old_stdout + self.assertIn("Deleting stale content type", output) + self.assertEqual(ContentType.objects.count(), self.before_count) + + def test_interactive_false(self): + """ + non-interactive mode of update_contenttypes() shouldn't delete stale + content types. + """ + self.old_stdout = sys.stdout + sys.stdout = StringIO() + management.update_contenttypes(self.app_config, interactive=False) + output = sys.stdout.getvalue() + sys.stdout = self.old_stdout + self.assertIn("Stale content types remain.", output) + self.assertEqual(ContentType.objects.count(), self.before_count + 1) |
