Example #1
0
 def test_plugin_add_requires_permissions(self):
     """User wants to add a plugin to the example app placeholder but has no permissions"""
     self._create_example()
     normal_guy = self._testuser()
     admin = self.get_admin()
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code,
                      HttpResponseForbidden.status_code)
     # The user gets the permission only for the plugin
     self._give_permission(normal_guy, Text, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code,
                      HttpResponseForbidden.status_code)
     # the user gets the permission only for the app
     self._delete_permission(normal_guy, Text, 'add')
     self._give_permission(normal_guy, Example1, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code,
                      HttpResponseForbidden.status_code)
     # user gets permissions for the plugin and the app
     self._give_permission(normal_guy, Text, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code, HttpResponse.status_code)
 def test_type_limit(self):
     placeholder = self.get_placeholder()
     admin = self.get_admin()
     data = {"plugin_type": "TextPlugin", "placeholder": placeholder.pk, "language": "en"}
     superuser = self.get_superuser()
     with UserLoginContext(self, superuser):
         with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
             request = self.get_post_request(data)
             response = admin.add_plugin(request)  # first
             self.assertEqual(response.status_code, 200)
             response = admin.add_plugin(request)  # second
             self.assertEqual(response.status_code, 400)
             self.assertEqual(
                 response.content, "This placeholder already has the maximum number (1) of TextPlugin plugins."
             )
Example #3
0
    def test_edit_plugin_and_cancel(self):
        placeholder = self.get_placeholder()
        admin = self.get_admin()
        data = {
            'plugin_type': 'TextPlugin',
            'placeholder': placeholder.pk,
            'language': 'en',
        }
        superuser = self.get_superuser()
        with UserLoginContext(self, superuser):
            with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
                request = self.get_post_request(data)
                response = admin.add_plugin(request)
                self.assertEqual(response.status_code, 200)
                plugin_id = int(response.content)
                data = {
                    'body': 'Hello World',
                }
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals('Hello World', text_plugin.body)

                # edit again, but this time press cancel
                data = {
                    'body': 'Hello World!!',
                    '_cancel': True,
                }
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals('Hello World', text_plugin.body)
Example #4
0
    def test_edit_plugin_and_cancel(self):
        placeholder = self.get_placeholder()
        admin = self.get_admin()
        data = {
            'plugin_type': 'TextPlugin',
            'placeholder': placeholder.pk,
            'language': 'en',
        }
        superuser = self.get_superuser()
        with UserLoginContext(self, superuser):
            with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
                request = self.get_post_request(data)
                response = admin.add_plugin(request)
                self.assertEqual(response.status_code, 200)
                plugin_id = int(response.content)
                data = {
                    'body': 'Hello World',
                }
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals('Hello World', text_plugin.body)

                # edit again, but this time press cancel
                data = {
                    'body': 'Hello World!!',
                    '_cancel': True,
                }
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals('Hello World', text_plugin.body)
Example #5
0
    def test_edit_plugin_and_cancel(self):
        placeholder = self.get_placeholder()
        admin = self.get_admin()
        data = {"plugin_type": "TextPlugin", "placeholder": placeholder.pk, "language": "en"}
        superuser = self.get_superuser()
        with UserLoginContext(self, superuser):
            with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
                request = self.get_post_request(data)
                response = admin.add_plugin(request)
                self.assertEqual(response.status_code, 200)
                plugin_id = int(response.content)
                data = {"body": "Hello World"}
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals("Hello World", text_plugin.body)

                # edit again, but this time press cancel
                data = {"body": "Hello World!!", "_cancel": True}
                request = self.get_post_request(data)
                response = admin.edit_plugin(request, plugin_id)
                self.assertEqual(response.status_code, 200)
                text_plugin = Text.objects.get(pk=plugin_id)
                self.assertEquals("Hello World", text_plugin.body)
Example #6
0
 def test_type_limit(self):
     placeholder = self.get_placeholder()
     admin = self.get_admin()
     data = {
         'plugin_type': 'TextPlugin',
         'placeholder': placeholder.pk,
         'language': 'en',
     }
     superuser = self.get_superuser()
     with UserLoginContext(self, superuser):
         with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
             request = self.get_post_request(data)
             response = admin.add_plugin(request) # first
             self.assertEqual(response.status_code, 200)
             response = admin.add_plugin(request) # second
             self.assertEqual(response.status_code, 400)
             self.assertEqual(response.content, "This placeholder already has the maximum number (1) of TextPlugin plugins.")
Example #7
0
 def test_global_limit(self):
     placeholder = self.get_placeholder()
     admin = self.get_admin()
     data = {
         'plugin_type': 'LinkPlugin',
         'placeholder': placeholder.pk,
         'language': 'en',
     }
     superuser = self.get_superuser()
     with UserLoginContext(self, superuser):
         with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
             request = self.get_post_request(data)
             response = admin.add_plugin(request) # first
             self.assertEqual(response.status_code, 200)
             response = admin.add_plugin(request) # second
             self.assertEqual(response.status_code, 200)
             response = admin.add_plugin(request) # third
             self.assertEqual(response.status_code, 400)
             self.assertEqual(response.content, "This placeholder already has the maximum number of plugins (2).")
Example #8
0
    def test_position_set_on_addition(self):
        placeholder = self.get_placeholder()
        placeholderconf = {'test': {}}
        admin = self.get_admin()
        data = {
            'plugin_type': 'TextPlugin',
            'placeholder': placeholder.pk,
            'language': 'en',
        }
        superuser = self.get_superuser()
        with UserLoginContext(self, superuser):
            with SettingsOverride(CMS_PLACEHOLDER_CONF=placeholderconf):
                request = self.get_post_request(data)
                response = admin.add_plugin(request) # first
                response = admin.add_plugin(request) # second
                response = admin.add_plugin(request) # third

        plugins = CMSPlugin.objects.filter(placeholder=placeholder)
        positions = [plugin.position for plugin in plugins]
        self.assertEqual(positions, [0, 1, 2])
Example #9
0
    def test_position_set_on_addition(self):
        placeholder = self.get_placeholder()
        placeholderconf = {'test': {}}
        admin = self.get_admin()
        data = {
            'plugin_type': 'TextPlugin',
            'placeholder': placeholder.pk,
            'language': 'en',
        }
        superuser = self.get_superuser()
        with UserLoginContext(self, superuser):
            with SettingsOverride(CMS_PLACEHOLDER_CONF=placeholderconf):
                request = self.get_post_request(data)
                response = admin.add_plugin(request)  # first
                response = admin.add_plugin(request)  # second
                response = admin.add_plugin(request)  # third

        plugins = CMSPlugin.objects.filter(placeholder=placeholder)
        positions = [plugin.position for plugin in plugins]
        self.assertEqual(positions, [0, 1, 2])
Example #10
0
 def test_plugin_add_requires_permissions(self):
     """User wants to add a plugin to the example app placeholder but has no permissions"""
     self._create_example()
     normal_guy = self._testuser()
     admin = self.get_admin()
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code, HttpResponseForbidden.status_code)
     # The user gets the permission only for the plugin
     self._give_permission(normal_guy, Text, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code, HttpResponseForbidden.status_code)
     # the user gets the permission only for the app
     self._delete_permission(normal_guy, Text, 'add')
     self._give_permission(normal_guy, Example1, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code, HttpResponseForbidden.status_code)
     # user gets permissions for the plugin and the app
     self._give_permission(normal_guy, Text, 'add')
     request = self._post_request(normal_guy)
     response = admin.add_plugin(request)
     self.assertEqual(response.status_code, HttpResponse.status_code)
Example #11
0
 def _test_plugin_action_requires_permissions(self, key):
     self._create_example()
     if key=='change':
         self._create_plugin()
     normal_guy = self._testuser()
     admin = self.get_admin()
     # check all combinations of plugin, app and object permission
     for perms in itertools.product(*[[False, True]]*3):
         self._set_perms(normal_guy, [Text, Example1, self.example_object], perms, key)
         request = self._post_request(normal_guy)
         if key=='add':
             response = admin.add_plugin(request)
         elif key=='change':
             response = admin.edit_plugin(request, self._plugin.id)
         should_pass = perms[0] and (perms[1] or perms[2])
         expected_status_code = HttpResponse.status_code if should_pass else HttpResponseForbidden.status_code
         self.assertEqual(response.status_code, expected_status_code)
     # cleanup
     self._set_perms(normal_guy, [Text, Example1, self.example_object], (False,)*3, key)
 def _test_plugin_action_requires_permissions(self, key):
     self._create_example()
     if key == 'change':
         self._create_plugin()
     normal_guy = self._testuser()
     admin = self.get_admin()
     # check all combinations of plugin, app and object permission
     for perms in itertools.product(*[[False, True]] * 3):
         self._set_perms(normal_guy, [Text, Example1, self.example_object],
                         perms, key)
         request = self._post_request(normal_guy)
         if key == 'add':
             response = admin.add_plugin(request)
         elif key == 'change':
             response = admin.edit_plugin(request, self._plugin.id)
         should_pass = perms[0] and (perms[1] or perms[2])
         expected_status_code = HttpResponse.status_code if should_pass else HttpResponseForbidden.status_code
         self.assertEqual(response.status_code, expected_status_code)
     # cleanup
     self._set_perms(normal_guy, [Text, Example1, self.example_object],
                     (False, ) * 3, key)