Skip to content

Commit

Permalink
tests for folder contents pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Apr 11, 2016
1 parent b7a9a14 commit 2203918
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions plone/app/content/tests/test_contents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# -*- coding: utf-8 -*-
from plone.app.content.testing import PLONE_APP_CONTENT_DX_INTEGRATION_TESTING
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.dexterity.fti import DexterityFTI

import json
import mock
import unittest


Expand Down Expand Up @@ -76,3 +85,71 @@ def physicalPathFromURL(self, url):
ctx = MockContext('/approot/PloneSite/folder/SubSite/folder')
ctx.vh_root = '/approot/PloneSite/folder/SubSite'
self.assertEqual(get_top_site_from_url(ctx, req).id, 'SubSite')


class ContentsPasteTests(unittest.TestCase):
layer = PLONE_APP_CONTENT_DX_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']

# TYPE 1
type1_fti = DexterityFTI('type1')
type1_fti.klass = 'plone.dexterity.content.Container'
type1_fti.filter_content_types = True
type1_fti.allowed_content_types = ['type1']
type1_fti.behaviors = (
'Products.CMFPlone.interfaces.constrains.ISelectableConstrainTypes', # noqa
'plone.app.dexterity.behaviors.metadata.IBasic'
)
self.portal.portal_types._setObject('type1', type1_fti)
self.type1_fti = type1_fti

login(self.portal, TEST_USER_NAME)
setRoles(self.portal, TEST_USER_ID, ['Manager'])

self.portal.invokeFactory('type1', id='it1', title='Item 1')

@mock.patch('plone.app.content.browser.contents.ContentsBaseAction.protect', lambda x: True) # noqa
def test_paste_success(self):
"""Copy content item and paste in portal root.
"""
# # setup copying via @@fc-copy
# from plone.uuid.interfaces import IUUID
# self.request['selection'] = [IUUID(self.portal.it1)]
# self.portal.restrictedTraverse('@@fc-copy')()

self.request['__cp'] = self.portal.manage_copyObjects(['it1'])
self.request.form['folder'] = '/'
res = self.portal.restrictedTraverse('@@fc-paste')()

res = json.loads(res)
self.assertEqual(res['status'], 'success')
self.assertEqual(len(self.portal.contentIds()), 2)

@mock.patch('plone.app.content.browser.contents.ContentsBaseAction.protect', lambda x: True) # noqa
def test_paste_success_paste_in_itself(self):
"""Copy content item and paste in itself. Because we can.
"""
self.request['__cp'] = self.portal.manage_copyObjects(['it1'])
self.request.form['folder'] = '/it1'
res = self.portal.it1.restrictedTraverse('@@fc-paste')()

res = json.loads(res)
self.assertEqual(res['status'], 'success')
self.assertEqual(len(self.portal.it1.contentIds()), 1)

@mock.patch('plone.app.content.browser.contents.ContentsBaseAction.protect', lambda x: True) # noqa
def test_paste_fail_constraint(self):
"""Fail pasting content item in itself when folder constraints don't
allow to.
"""
self.type1_fti.allowed_content_types = [] # set folder constraints
self.request['__cp'] = self.portal.manage_copyObjects(['it1'])
self.request.form['folder'] = '/it1'
res = self.portal.it1.restrictedTraverse('@@fc-paste')()

res = json.loads(res)
self.assertEqual(res['status'], 'warning')
self.assertEqual(len(self.portal.it1.contentIds()), 0)

0 comments on commit 2203918

Please sign in to comment.