def test_render_child_plugin_permissions(self): """ Users can't render a child plugin without change permissions on the placeholder attached object and the text plugin. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_standard_user()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 403) self.assertEqual(force_text(response.content), '<h1>403 Forbidden</h1>')
def test_render_child_plugin_endpoint_calls_context_processors(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin( text_plugin, plugin_type='SekizaiPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) context = RequestContext(request) context['request'] = request rendered_content = _render_cms_plugin(child_plugin, context) rendered_child_plugin = plugin_to_tag( child_plugin, content=rendered_content, admin=True, ) self.assertEqual(force_str(response.content), rendered_child_plugin)
def test_plugin_edit(self): page = create_page(title='pagina', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='Lorem ipsum') page.publish('en') response = self.client.get(page.get_absolute_url('en')) self.assertContains(response, 'Lorem ipsum')
def test_plugin_edit(self): page = create_page(title='pagina', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='Lorem ipsum') page.publish('en') response = self.client.get(page.get_absolute_url('en')) self.assertContains(response, 'Lorem ipsum')
def test_action_token_per_session(self): # Assert that a cancel token for the same plugin # is different per user session. simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() with self.login_user_context(self.get_superuser()): request = self.get_request() action_token_1 = text_plugin_class.get_action_token( request, text_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token_2 = text_plugin_class.get_action_token( request, text_plugin) self.assertNotEqual(action_token_1, action_token_2)
def test_render_child_plugin_endpoint_calls_context_processors(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin( text_plugin, plugin_type='SekizaiPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) context = RequestContext(request) context['request'] = request rendered_content = _render_cms_plugin(child_plugin, context) rendered_child_plugin = plugin_to_tag( child_plugin, content=rendered_content, admin=True, ) self.assertEqual(force_text(response.content), rendered_child_plugin)
def test_render_child_plugin_permissions(self): """ Users can't render a child plugin without change permissions on the placeholder attached object and the text plugin. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_standard_user()): request = self.get_request() action_token = text_plugin_class.get_action_token( request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertContains(response, '<h1>403 Forbidden</h1>', status_code=403, html=True)
def test_render_child_plugin_token_validation(self): """ Users can only render a child plugin if the token was created in the current session and it's text plugin matches the child plugin parent. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) # Tokens are unique per session. # Users can't render a child plugin with a token # from another session. with self.login_user_context(self.get_superuser()): request = self.get_request() with self.login_user_context(self.get_superuser()): action_token = text_plugin_class.get_action_token( request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 400) self.assertEqual(force_text(response.content), 'Unable to process your request. Invalid token.') text_plugin_2 = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the second", ) # Tokens are unique per text plugin. # User can't render a child plugin for a token whose text plugin # does not match the plugin's parent. with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token( request, text_plugin_2) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 400) self.assertEqual(force_text(response.content), 'Unable to process your request.')
def test_custom_ckeditor_body_css_classes(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') parent_plugin = add_plugin( simple_placeholder, DummyParentPlugin, 'en', label=DummyParentPlugin._ckeditor_body_class_label_trigger, ) child_plugin = add_plugin( simple_placeholder, DummyChildPlugin, 'en', target=parent_plugin, ) text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="Content", target=child_plugin, ) with self.login_user_context(self.get_superuser()): change_endpoint = self.get_change_plugin_uri(text_plugin) response = self.client.get(change_endpoint) self.assertContains(response, DummyParentPlugin._ckeditor_body_class) self.assertContains(response, DummyChildPlugin.child_ckeditor_body_css_class)
def test_copy_plugin_integrity(self): """ Test that copying of textplugins replaces references to copied plugins """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = self._add_text_plugin(simple_placeholder) child_plugin_1 = self._add_child_plugin( text_plugin, plugin_type='LinkPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_1) child_plugin_2 = self._add_child_plugin( text_plugin, plugin_type='LinkPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_2) # create a page translation to copy plugins to translation = create_title('fr', 'test-page-fr', simple_page, slug='test-page-fr') self.assertEqual(CMSPlugin.objects.filter(language='en').count(), 3) self.assertEqual( CMSPlugin.objects.filter(language=translation.language).count(), 0) data = { 'source_placeholder_id': simple_placeholder.pk, 'target_placeholder_id': simple_placeholder.pk, 'target_language': translation.language, 'source_language': 'en', } endpoint = self.get_admin_url(Page, 'copy_plugins') endpoint += '?' + urlencode({'cms_path': '/en/'}) with self.login_user_context(self.user): response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 200) self.assertEqual( CMSPlugin.objects.filter(language='en').count(), 3) self.assertEqual( CMSPlugin.objects.filter( language=translation.language).count(), 3) plugins = list(CMSPlugin.objects.all()) new_plugin = plugins[3].get_plugin_instance()[0] idlist = sorted(plugin_tags_to_id_list(new_plugin.body)) expected = sorted([plugins[4].pk, plugins[5].pk]) self.assertEqual(idlist, expected)
def test_contain_text(self): page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='some text') language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, 'some text')
def test_contain_text(self): page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='some text') language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, 'some text')
def test_copy_plugin_integrity(self): """ Test that copying of textplugins replaces references to copied plugins """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = self._add_text_plugin(simple_placeholder) child_plugin_1 = self._add_child_plugin( text_plugin, plugin_type='LinkPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_1) child_plugin_2 = self._add_child_plugin( text_plugin, plugin_type='LinkPlugin', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_2) # create a page translation to copy plugins to translation = create_title( 'fr', 'test-page-fr', simple_page, slug='test-page-fr' ) self.assertEqual(CMSPlugin.objects.filter(language='en').count(), 3) self.assertEqual(CMSPlugin.objects.filter(language=translation.language).count(), 0) data = { 'source_placeholder_id': simple_placeholder.pk, 'target_placeholder_id': simple_placeholder.pk, 'target_language': translation.language, 'source_language': 'en', } endpoint = self.get_admin_url(Page, 'copy_plugins') endpoint += '?' + urlencode({'cms_path': '/en/'}) with self.login_user_context(self.user): response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 200) self.assertEqual(CMSPlugin.objects.filter(language='en').count(), 3) self.assertEqual(CMSPlugin.objects.filter(language=translation.language).count(), 3) plugins = list(CMSPlugin.objects.all()) new_plugin = plugins[3].get_plugin_instance()[0] idlist = sorted(plugin_tags_to_id_list(new_plugin.body)) expected = sorted([plugins[4].pk, plugins[5].pk]) self.assertEqual(idlist, expected)
def test_add_and_cancel_plugin(self): """ Test that you can add a text plugin """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(self.get_superuser()): response = self.client.get(endpoint) self.assertEqual(response.status_code, 302) # Point to the newly created text plugin text_plugin_pk = self.get_plugin_id_from_response(response) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() # Assert "ghost" plugin has been created self.assertObjectExist(CMSPlugin.objects.all(), pk=text_plugin_pk) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token( request, cms_plugin) data = {'token': action_token} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 204) # Assert "ghost" plugin has been removed self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=text_plugin_pk) # Assert "real" plugin was never created self.assertObjectDoesNotExist(Text.objects.all(), pk=text_plugin_pk) # Assert user can't delete a non "ghost" plugin text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token( request, text_plugin) data = {'token': action_token} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400)
def test_render_child_plugin_endpoint(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) context = RequestContext(request) context['request'] = request rendered_content = _render_cms_plugin(child_plugin, context) rendered_child_plugin = plugin_to_tag( child_plugin, content=rendered_content, admin=True, ) self.assertEqual(force_str(response.content), rendered_child_plugin) child_plugin = self._add_child_plugin(text_plugin, plugin_type='PreviewDisabledPlugin') text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) # it is important that we do not add any extra whitespace inside of # <cms-plugin></cms-plugin> rendered_child_plugin = ('<cms-plugin render-plugin=false ' 'alt="Preview Disabled Plugin - 3 ' '"title="Preview Disabled Plugin - 3" ' 'id="3"><span>Preview is disabled for this plugin</span>' '</cms-plugin>') self.assertEqual(force_str(response.content), rendered_child_plugin)
def test_add_and_edit_plugin(self): """ Test that you can add a text plugin """ admin = self.get_superuser() simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(admin): response = self.client.get(endpoint) text_plugin_pk = self.get_plugin_id_from_response(response) self.assertIn('?delete-on-cancel', response.url) self.assertEqual(response.status_code, 302) # Assert "ghost" plugin has been created self.assertObjectExist(CMSPlugin.objects.all(), pk=text_plugin_pk) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() # Assert "real" plugin has not been created yet self.assertObjectDoesNotExist(Text.objects.all(), pk=text_plugin_pk) add_url = response.url with self.login_user_context(admin): request = self.get_request() action_token = text_plugin_class.get_action_token( request, cms_plugin) response = self.client.get(add_url) self.assertEqual(response.status_code, 200) # Assert cancel token is present self.assertContains(response, action_token) with self.login_user_context(admin): data = {'body': 'Hello world'} response = self.client.post(add_url, data) self.assertEqual(response.status_code, 200) # Assert "real" plugin has been created yet self.assertObjectExist(Text.objects.all(), pk=text_plugin_pk) text_plugin = Text.objects.get(pk=text_plugin_pk) # Assert the text was correctly saved self.assertEqual(text_plugin.body, 'Hello world')
def test_render_child_plugin_endpoint(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) context = RequestContext(request) context['request'] = request rendered_content = _render_cms_plugin(child_plugin, context) rendered_child_plugin = plugin_to_tag( child_plugin, content=rendered_content, admin=True, ) self.assertEqual(force_text(response.content), rendered_child_plugin) child_plugin = self._add_child_plugin(text_plugin, plugin_type='PreviewDisabledPlugin') text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) # it is important that we do not add any extra whitespace inside of # <cms-plugin></cms-plugin> rendered_child_plugin = ('<cms-plugin render-plugin=false ' 'alt="Preview Disabled Plugin - 3 ' '"title="Preview Disabled Plugin - 3" ' 'id="3"><span>Preview is disabled for this plugin</span>' '</cms-plugin>') self.assertEqual(force_text(response.content), rendered_child_plugin)
def test_render_child_plugin_token_validation(self): """ Users can only render a child plugin if the token was created in the current session and it's text plugin matches the child plugin parent. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin = self._add_child_plugin(text_plugin) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin) # Tokens are unique per session. # Users can't render a child plugin with a token # from another session. with self.login_user_context(self.get_superuser()): request = self.get_request() with self.login_user_context(self.get_superuser()): action_token = text_plugin_class.get_action_token(request, text_plugin) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 400) self.assertEqual(force_text(response.content), 'Unable to process your request. Invalid token.') text_plugin_2 = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the second", ) # Tokens are unique per text plugin. # User can't render a child plugin for a token whose text plugin # does not match the plugin's parent. with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin_2) endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin') endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk) response = self.client.get(endpoint) self.assertEqual(response.status_code, 400) self.assertEqual(force_text(response.content), 'Unable to process your request.')
def test_add_and_edit_plugin(self): """ Test that you can add a text plugin """ admin = self.get_superuser() simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(admin): response = self.client.get(endpoint) text_plugin_pk = self.get_plugin_id_from_response(response) self.assertIn('?delete-on-cancel', response.url) self.assertEqual(response.status_code, 302) # Assert "ghost" plugin has been created self.assertObjectExist(CMSPlugin.objects.all(), pk=text_plugin_pk) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() # Assert "real" plugin has not been created yet self.assertObjectDoesNotExist(Text.objects.all(), pk=text_plugin_pk) add_url = response.url with self.login_user_context(admin): request = self.get_request() action_token = text_plugin_class.get_action_token(request, cms_plugin) response = self.client.get(add_url) self.assertEqual(response.status_code, 200) # Assert cancel token is present self.assertContains(response, action_token) with self.login_user_context(admin): data = {'body': 'Hello world'} response = self.client.post(add_url, data) self.assertEqual(response.status_code, 200) # Assert "real" plugin has been created yet self.assertObjectExist(Text.objects.all(), pk=text_plugin_pk) text_plugin = Text.objects.get(pk=text_plugin_pk) # Assert the text was correctly saved self.assertEqual(text_plugin.body, 'Hello world')
def test_text_sanitizer(self): page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='<span data-one="1" data-two="2">some text</span>') language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, 'data-one="1"') self.assertContains(response, 'data-two="2"')
def test_text_sanitizer(self): page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin( placeholder, 'TextPlugin', 'en', body='<span data-one="1" data-two="2">some text</span>' ) language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, 'data-one="1"') self.assertContains(response, 'data-two="2"')
def test_sub_plugin_config(self): page = create_page(title='home', template='page.html', language='en') plugin = add_plugin( get_page_placeholders(page, 'en').get(slot='content'), 'TextPlugin', 'en', body='some text' ) endpoint = self.get_change_plugin_uri(plugin) with self.login_user_context(self.user): response = self.client.get(endpoint) self.assertContains(response, "group: 'Extra'") self.assertContains(response, "'title': 'Add a link'") self.assertContains(response, "group: 'Generic'") self.assertContains(response, "'title': 'Image'")
def test_add_and_cancel_plugin(self): """ Test that you can add a text plugin """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(self.get_superuser()): response = self.client.get(endpoint) self.assertEqual(response.status_code, 302) # Point to the newly created text plugin text_plugin_pk = self.get_plugin_id_from_response(response) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() # Assert "ghost" plugin has been created self.assertObjectExist(CMSPlugin.objects.all(), pk=text_plugin_pk) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, cms_plugin) data = {'token': action_token} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 204) # Assert "ghost" plugin has been removed self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=text_plugin_pk) # Assert "real" plugin was never created self.assertObjectDoesNotExist(Text.objects.all(), pk=text_plugin_pk) # Assert user can't delete a non "ghost" plugin text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) data = {'token': action_token} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400)
def test_child_plugin(self): page = create_page(title='pagina', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') plugin = add_plugin(placeholder, 'TextPlugin', 'en', body='Lorem ipsum') test_image = self.create_filer_image_object() pic_plugin = add_plugin( placeholder, 'PicturePlugin', 'en', target=plugin, picture=test_image ) plugin.body = '%s %s' % (plugin.body, plugin_to_tag(pic_plugin)) plugin.save() page.publish('en') response = self.client.get(page.get_absolute_url('en')) self.assertContains(response, 'Lorem ipsum') self.assertContains(response, '<img src="/media/')
def test_text_sanitizer_no_settings(self): settings.ALLOW_TOKEN_PARSERS = [] html.DEFAULT_PARSER = html._get_default_parser() page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin(placeholder, 'TextPlugin', 'en', body='<span data-one="1" data-two="2">some text</span>') language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, '<span>some text</span>')
def test_text_sanitizer_no_settings(self): settings.ALLOW_TOKEN_PARSERS = [] html.DEFAULT_PARSER = html._get_default_parser() page = create_page(title='home', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') add_plugin( placeholder, 'TextPlugin', 'en', body='<span data-one="1" data-two="2">some text</span>' ) language = 'en' page.publish(language) url = page.get_absolute_url(language) response = self.client.get(url) self.assertContains(response, '<span>some text</span>')
def test_text_plugin_xss(self): page = create_page('test page', 'page.html', u'en') placeholder = get_page_placeholders(page, 'en').get(slot='content') plugin = add_plugin(placeholder, 'TextPlugin', 'en', body='body') endpoint = self.get_change_plugin_uri(plugin) with self.login_user_context(self.user): data = { 'body': ( '<div onload="do_evil_stuff();">divcontent</div><a href="javascript:do_evil_stuff();">acontent</a>' ) } response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 200) self.assertEqual(self.reload(plugin).body, '<div>divcontent</div><a>acontent</a>')
def test_text_plugin_xss(self): page = create_page('test page', 'page.html', u'en') placeholder = get_page_placeholders(page, 'en').get(slot='content') plugin = add_plugin(placeholder, 'TextPlugin', 'en', body='body') endpoint = self.get_change_plugin_uri(plugin) with self.login_user_context(self.user): data = { 'body': ( '<div onload="do_evil_stuff();">divcontent</div><a href="javascript:do_evil_stuff();">acontent</a>' ) } response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 200) self.assertEqual(self.reload(plugin).body, '<div>divcontent</div><a>acontent</a>')
def test_sub_plugin_config(self): page = create_page(title='home', template='page.html', language='en') plugin = add_plugin(get_page_placeholders(page, 'en').get(slot='content'), 'TextPlugin', 'en', body='some text') endpoint = self.get_change_plugin_uri(plugin) with self.login_user_context(self.user): response = self.client.get(endpoint) self.assertContains(response, "group: 'Extra'") self.assertContains(response, "'title': 'Add a link'") self.assertContains(response, "group: 'Generic'") self.assertContains(response, "'title': 'Image'")
def test_change_form_has_rendered_plugin_content(self): """ When the text form is rendered in the admin, the child plugins are rendered as their contents passed as initial data to the text field. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) child_plugins = [ self._add_child_plugin(text_plugin), self._add_child_plugin(text_plugin), ] for plugin in child_plugins: text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() context = RequestContext(request) context['request'] = request text_with_rendered_plugins = plugin_tags_to_admin_html( text=text_plugin.body, context=context, ) endpoint = self.get_change_plugin_uri(text_plugin) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) self.assertEqual( response.context['adminform'].form['body'].value(), text_with_rendered_plugins, ) self.assertContains( response, escape(text_with_rendered_plugins), html=False, )
def test_copy_plugin_callback(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin_1 = self._add_text_plugin(simple_placeholder) child_plugin_1_a = self._add_child_plugin( text_plugin_1, plugin_type='LinkPlugin', ) text_plugin_1 = self.add_plugin_to_text(text_plugin_1, child_plugin_1_a) child_plugin_1_b = self._add_child_plugin( text_plugin_1, plugin_type='LinkPlugin', ) text_plugin_1 = self.add_plugin_to_text(text_plugin_1, child_plugin_1_b) text_plugin_2 = copy.copy(text_plugin_1) text_plugin_2.pk = None text_plugin_2.save() child_plugin_2_a = self._add_child_plugin( text_plugin_2, plugin_type='LinkPlugin', ) child_plugin_2_b = self._add_child_plugin( text_plugin_2, plugin_type='LinkPlugin', ) source_map = { child_plugin_1_a.pk: child_plugin_2_a, child_plugin_1_b.pk: child_plugin_2_b, } TextPlugin.do_post_copy(text_plugin_2, source_map) text_plugin_2.refresh_from_db() idlist = sorted(plugin_tags_to_id_list(text_plugin_2.body)) expected = sorted([child_plugin_2_a.pk, child_plugin_2_b.pk]) self.assertEqual(idlist, expected)
def test_change_form_has_rendered_plugin_content(self): """ When the text form is rendered in the admin, the child plugins are rendered as their contents passed as initial data to the text field. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) child_plugins = [ self._add_child_plugin(text_plugin), self._add_child_plugin(text_plugin), ] for plugin in child_plugins: text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() context = RequestContext(request) context['request'] = request text_with_rendered_plugins = plugin_tags_to_admin_html( text=text_plugin.body, context=context, ) endpoint = self.get_change_plugin_uri(text_plugin) response = self.client.get(endpoint) self.assertEqual(response.status_code, 200) self.assertEqual( response.context['adminform'].form['body'].value(), text_with_rendered_plugins, ) self.assertContains( response, escape(text_with_rendered_plugins), html=False, )
def test_child_plugin(self): page = create_page(title='pagina', template='page.html', language='en') placeholder = get_page_placeholders(page, 'en').get(slot='content') plugin = add_plugin(placeholder, 'TextPlugin', 'en', body='Lorem ipsum') test_image = self.create_filer_image_object() pic_plugin = add_plugin(placeholder, 'PicturePlugin', 'en', target=plugin, picture=test_image) plugin.body = '%s %s' % (plugin.body, plugin_to_tag(pic_plugin)) plugin.save() page.publish('en') response = self.client.get(page.get_absolute_url('en')) self.assertContains(response, 'Lorem ipsum') self.assertContains(response, '<img src="/media/')
def test_copy_plugin_callback(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin_1 = self._add_text_plugin(simple_placeholder) child_plugin_1_a = self._add_child_plugin( text_plugin_1, plugin_type='LinkPlugin', ) text_plugin_1 = self.add_plugin_to_text(text_plugin_1, child_plugin_1_a) child_plugin_1_b = self._add_child_plugin( text_plugin_1, plugin_type='LinkPlugin', ) text_plugin_1 = self.add_plugin_to_text(text_plugin_1, child_plugin_1_b) text_plugin_2 = copy.copy(text_plugin_1) text_plugin_2.pk = None text_plugin_2.save() child_plugin_2_a = self._add_child_plugin( text_plugin_2, plugin_type='LinkPlugin', ) child_plugin_2_b = self._add_child_plugin( text_plugin_2, plugin_type='LinkPlugin', ) source_map = { child_plugin_1_a.pk: child_plugin_2_a, child_plugin_1_b.pk: child_plugin_2_b, } TextPlugin.do_post_copy(text_plugin_2, source_map) text_plugin_2.refresh_from_db() idlist = sorted(plugin_tags_to_id_list(text_plugin_2.body)) expected = sorted([child_plugin_2_a.pk, child_plugin_2_b.pk]) self.assertEqual(idlist, expected)
def test_add_and_cancel_plugin_permissions(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(self.user): response = self.client.post(endpoint, {}) self.assertEqual(response.status_code, 302) # Point to the newly created text plugin text_plugin_pk = self.get_plugin_id_from_response(response) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() endpoint = self.get_custom_admin_url(TextPlugin, 'delete_on_cancel') # Assert a standard user (no staff) can't delete ghost plugin with self.login_user_context(self.get_standard_user()): request = self.get_request() action_token = text_plugin_class.get_action_token( request, cms_plugin) data = {'token': action_token} response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 403) staff_user = self._create_user('addonly-staff', is_staff=True, is_superuser=False) self._give_cms_permissions(staff_user) self._give_permission(staff_user, text_plugin_class.model, 'add') with self.login_user_context(staff_user): request = self.get_request() action_token = text_plugin_class.get_action_token( request, cms_plugin) data = {'token': action_token} response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 204)
def test_render_plugin(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = self._add_text_plugin(simple_placeholder) for i in range(0, 10): plugin = self._add_child_plugin(text_plugin, plugin_type='LinkPlugin', data_suffix=i) text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.assertNumQueries(2): request = self.get_request() context = RequestContext(request) context['request'] = request rendered = _render_cms_plugin(text_plugin, context) for i in range(0, 10): self.assertTrue('LinkPlugin record %d' % i in rendered)
def test_user_cant_edit_child_plugins_directly(self): """ No user regardless of permissions can modify the contents of a child plugin directly in the text plugin text. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) child_plugins = [ self._add_child_plugin(text_plugin), self._add_child_plugin(text_plugin), ] for plugin in child_plugins: text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.login_user_context(self.get_superuser()): expected_text = text_plugin.body # This returns the child plugins with their content # overridden to <img src=""> overridden_text = self._replace_plugin_contents( text_plugin.body, new_plugin_content='<img src="">', ) endpoint = self.get_change_plugin_uri(text_plugin) response = self.client.post(endpoint, {'body': overridden_text}) text_plugin.refresh_from_db() self.assertEqual(response.status_code, 200) self.assertXMLEqual(text_plugin.body, expected_text)
def test_user_cant_edit_child_plugins_directly(self): """ No user regardless of permissions can modify the contents of a child plugin directly in the text plugin text. """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) child_plugins = [ self._add_child_plugin(text_plugin), self._add_child_plugin(text_plugin), ] for plugin in child_plugins: text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.login_user_context(self.get_superuser()): expected_text = text_plugin.body # This returns the child plugins with their content # overridden to <img src=""> overridden_text = self._replace_plugin_contents( text_plugin.body, new_plugin_content='<img src="">', ) endpoint = self.get_change_plugin_uri(text_plugin) response = self.client.post(endpoint, {'body': overridden_text}) text_plugin.refresh_from_db() self.assertEqual(response.status_code, 200) self.assertXMLEqual(text_plugin.body, expected_text)
def test_render_extended_plugin(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = self._add_text_plugin(simple_placeholder, 'ExtendedTextPlugin') for i in range(0, 10): plugin = self._add_child_plugin( text_plugin, plugin_type='LinkPlugin', data_suffix=i ) text_plugin = self.add_plugin_to_text(text_plugin, plugin) with self.assertNumQueries(2): request = self.get_request() context = RequestContext(request) context['request'] = request rendered = _render_cms_plugin(text_plugin, context) for i in range(0, 10): self.assertTrue('LinkPlugin record %d' % i in rendered)
def test_action_token_per_session(self): # Assert that a cancel token for the same plugin # is different per user session. simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() with self.login_user_context(self.get_superuser()): request = self.get_request() action_token_1 = text_plugin_class.get_action_token(request, text_plugin) with self.login_user_context(self.get_superuser()): request = self.get_request() action_token_2 = text_plugin_class.get_action_token(request, text_plugin) self.assertNotEqual(action_token_1, action_token_2)
def test_add_and_cancel_plugin_permissions(self): simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') endpoint = self.get_add_plugin_uri(simple_placeholder, 'TextPlugin') with self.login_user_context(self.user): response = self.client.post(endpoint, {}) self.assertEqual(response.status_code, 302) # Point to the newly created text plugin text_plugin_pk = self.get_plugin_id_from_response(response) cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk) text_plugin_class = cms_plugin.get_plugin_class_instance() endpoint = self.get_custom_admin_url(TextPlugin, 'delete_on_cancel') # Assert a standard user (no staff) can't delete ghost plugin with self.login_user_context(self.get_standard_user()): request = self.get_request() action_token = text_plugin_class.get_action_token(request, cms_plugin) data = {'token': action_token} response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 403) staff_user = self._create_user('addonly-staff', is_staff=True, is_superuser=False) self._give_cms_permissions(staff_user) self._give_permission(staff_user, text_plugin_class.model, 'add') with self.login_user_context(staff_user): request = self.get_request() action_token = text_plugin_class.get_action_token(request, cms_plugin) data = {'token': action_token} response = self.client.post(endpoint, data) self.assertEqual(response.status_code, 204)
def test_add_and_cancel_child_plugin(self): """ Test that you can add a text plugin """ admin = self.get_superuser() simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin_1 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_2 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_3 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_4 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_1) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_4) with self.login_user_context(admin): request = self.get_request() action_token = text_plugin_class.get_action_token(request, text_plugin) # Assert user is unable to delete a saved child plugin data = {'token': action_token, 'child_plugins': [child_plugin_1.pk]} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_1.pk) # Assert user is unable to delete if plugins array contains # an unsaved plugin. plugin_ids = [ child_plugin_1.pk, child_plugin_2.pk, child_plugin_3.pk, child_plugin_4.pk, ] data = {'token': action_token, 'child_plugins': plugin_ids} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_1.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_2.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_3.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_4.pk) plugin_ids = [ child_plugin_2.pk, child_plugin_3.pk, ] data = {'token': action_token, 'child_plugins': plugin_ids} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 204) self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=child_plugin_2.pk) self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=child_plugin_3.pk)
def test_copy_referenced_plugins(self): """ Test that copy+pasting a child plugin between text editors creates proper copies of the child plugin and messes no other data up """ simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') def _get_text_plugin_with_children(): text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body='Text plugin we copy child plugins to') _add_child_plugins_to_text_plugin(text_plugin) return text_plugin def _add_child_plugins_to_text_plugin(text_plugin): child_plugin_1 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Child plugin one', ) child_plugin_2 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Child plugin two', ) self.add_plugin_to_text(text_plugin, child_plugin_1) self.add_plugin_to_text(text_plugin, child_plugin_2) def _copy_child_plugins_from_text(text_plugin_source, text_plugin_destination): for child_plugin in text_plugin_source.cmsplugin_set.all(): text_plugin_destination.body += ' ' + plugin_to_tag( child_plugin) text_plugin_destination.save() _run_clean_and_copy(text_plugin_destination) def _run_clean_and_copy(text_plugin): text_plugin.clean_plugins() text_plugin.copy_referenced_plugins() def _get_common_children_ids(text_plugin_one, text_plugin_two): original_children_ids = set( plugin_tags_to_id_list(text_plugin_one.body)) copied_children_ids = set( plugin_tags_to_id_list(text_plugin_two.body)) return original_children_ids.intersection(copied_children_ids) text_plugin_copy_from = _get_text_plugin_with_children() text_plugin_copy_to = _get_text_plugin_with_children() _copy_child_plugins_from_text(text_plugin_copy_from, text_plugin_copy_to) self.assertEqual(text_plugin_copy_from.cmsplugin_set.count(), 2) self.assertEqual(text_plugin_copy_to.cmsplugin_set.count(), 4) _run_clean_and_copy(text_plugin_copy_from) _run_clean_and_copy(text_plugin_copy_to) self.assertEqual(text_plugin_copy_from.cmsplugin_set.count(), 2) self.assertEqual(text_plugin_copy_to.cmsplugin_set.count(), 4) common_children_ids = _get_common_children_ids(text_plugin_copy_from, text_plugin_copy_to) self.assertFalse(common_children_ids)
def setUp(self): super(DjangoCMSTranslationsIntegrationTestCase, self).setUp() self.page = create_page('test page', 'page.html', 'en', published=True) self.placeholder = get_page_placeholders(self.page, 'en').get(slot='content')
def test_add_and_cancel_child_plugin(self): """ Test that you can add a text plugin """ admin = self.get_superuser() simple_page = create_page('test page', 'page.html', u'en') simple_placeholder = get_page_placeholders(simple_page, 'en').get(slot='content') text_plugin = add_plugin( simple_placeholder, 'TextPlugin', 'en', body="I'm the first", ) text_plugin_class = text_plugin.get_plugin_class_instance() child_plugin_1 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_2 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_3 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) child_plugin_4 = add_plugin( simple_placeholder, 'PicturePlugin', 'en', target=text_plugin, picture=self.create_filer_image_object(), caption_text='Foo', ) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_1) text_plugin = self.add_plugin_to_text(text_plugin, child_plugin_4) with self.login_user_context(admin): request = self.get_request() action_token = text_plugin_class.get_action_token( request, text_plugin) # Assert user is unable to delete a saved child plugin data = { 'token': action_token, 'child_plugins': [child_plugin_1.pk] } request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_1.pk) # Assert user is unable to delete if plugins array contains # an unsaved plugin. plugin_ids = [ child_plugin_1.pk, child_plugin_2.pk, child_plugin_3.pk, child_plugin_4.pk, ] data = {'token': action_token, 'child_plugins': plugin_ids} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 400) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_1.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_2.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_3.pk) self.assertObjectExist(CMSPlugin.objects.all(), pk=child_plugin_4.pk) plugin_ids = [ child_plugin_2.pk, child_plugin_3.pk, ] data = {'token': action_token, 'child_plugins': plugin_ids} request = self.get_post_request(data) response = text_plugin_class.delete_on_cancel(request) self.assertEqual(response.status_code, 204) self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=child_plugin_2.pk) self.assertObjectDoesNotExist(CMSPlugin.objects.all(), pk=child_plugin_3.pk)
def setUp(self): super().setUp() self.page = create_page('test page', 'page.html', 'en', published=True) self.placeholder = get_page_placeholders(self.page, 'en').get(slot='content')
def setUp(self): super(DjangoCMSTranslationsIntegrationTestCase, self).setUp() self.page = create_page('test page', 'page.html', 'en', published=True) self.placeholder = get_page_placeholders(self.page, 'en').get(slot='content')