summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2019-04-26 08:51:58 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-04-27 21:08:46 +0200
commit4f8ebdd09835ad5c010c122ec669c1b224801302 (patch)
treeaf0a0e958b213babf77a7fc621e7886d340009b3 /tests
parente45763193fe496cefc6749c45e6a31e62f987d63 (diff)
[2.2.x] Fixed #30351 -- Handled pre-existing permissions in proxy model permissions data migration.
Regression in 181fb60159e54d442d3610f4afba6f066a6dac05. Backport of 98296f86b340c8c9c968375d59f1d3a3479e60c2 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/auth_tests/test_migrations.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auth_tests/test_migrations.py b/tests/auth_tests/test_migrations.py
index 5ff2f6b4b3..98c5b5964a 100644
--- a/tests/auth_tests/test_migrations.py
+++ b/tests/auth_tests/test_migrations.py
@@ -4,6 +4,7 @@ from django.apps import apps
from django.contrib.auth.models import Permission, User
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
+from django.test.utils import captured_stdout
from .models import Proxy, UserProxy
@@ -152,3 +153,27 @@ class ProxyModelWithSameAppLabelTests(TestCase):
user = User._default_manager.get(pk=user.pk)
for permission in [self.default_permission, self.custom_permission]:
self.assertTrue(user.has_perm('auth_tests.' + permission.codename))
+
+ def test_migrate_with_existing_target_permission(self):
+ """
+ Permissions may already exist:
+
+ - Old workaround was to manually create permissions for proxy models.
+ - Model may have been concrete and then converted to proxy.
+
+ Output a reminder to audit relevant permissions.
+ """
+ proxy_model_content_type = ContentType.objects.get_for_model(Proxy, for_concrete_model=False)
+ Permission.objects.create(
+ content_type=proxy_model_content_type,
+ codename='add_proxy',
+ name='Can add proxy',
+ )
+ Permission.objects.create(
+ content_type=proxy_model_content_type,
+ codename='display_proxys',
+ name='May display proxys information',
+ )
+ with captured_stdout() as stdout:
+ update_proxy_permissions.update_proxy_model_permissions(apps, None)
+ self.assertIn('A problem arose migrating proxy model permissions', stdout.getvalue())