Commit ac0959f8 authored by Nicolas Delaby's avatar Nicolas Delaby

Check contribution feature through HTTP

mapply needs to know which parameters it has to extract from the request.
that's what fill_args_from_request decorator does.
parent 8f74bb98
...@@ -43,6 +43,7 @@ from Products.ERP5Type import Permissions ...@@ -43,6 +43,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type.Utils import reencodeUrlEscapes from Products.ERP5Type.Utils import reencodeUrlEscapes
from Products.ERP5 import _dtmldir from Products.ERP5 import _dtmldir
from Products.ERP5.Document.Url import no_crawl_protocol_list from Products.ERP5.Document.Url import no_crawl_protocol_list
from Products.ERP5Type.Utils import fill_args_from_request
from AccessControl import Unauthorized from AccessControl import Unauthorized
from DateTime import DateTime from DateTime import DateTime
...@@ -97,7 +98,9 @@ class ContributionTool(BaseTool): ...@@ -97,7 +98,9 @@ class ContributionTool(BaseTool):
manage_overview = DTMLFile( 'explainContributionTool', _dtmldir ) manage_overview = DTMLFile( 'explainContributionTool', _dtmldir )
security.declareProtected(Permissions.AddPortalContent, 'newContent') security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, **kw): @fill_args_from_request('data', 'filename', 'portal_type', 'container_path',
'discover_metadata', 'temp_object', 'reference')
def newContent(self, REQUEST=None, **kw):
""" """
The newContent method is overriden to implement smart content The newContent method is overriden to implement smart content
creation by detecting the portal type based on whatever information creation by detecting the portal type based on whatever information
...@@ -225,6 +228,8 @@ class ContributionTool(BaseTool): ...@@ -225,6 +228,8 @@ class ContributionTool(BaseTool):
.discoverMetadata(filename=filename, .discoverMetadata(filename=filename,
user_login=user_login, user_login=user_login,
input_parameter_dict=input_parameter_dict) input_parameter_dict=input_parameter_dict)
if REQUEST is not None:
return REQUEST.RESPONSE.redirect(self.absolute_url())
return document return document
# #
...@@ -275,6 +280,8 @@ class ContributionTool(BaseTool): ...@@ -275,6 +280,8 @@ class ContributionTool(BaseTool):
# Document does not have such attribute # Document does not have such attribute
pass pass
document.reindexObject() document.reindexObject()
if REQUEST is not None:
return REQUEST.RESPONSE.redirect(self.absolute_url())
return document return document
security.declareProtected( Permissions.AddPortalContent, 'newXML' ) security.declareProtected( Permissions.AddPortalContent, 'newXML' )
......
...@@ -47,6 +47,10 @@ from zLOG import LOG, INFO, ERROR ...@@ -47,6 +47,10 @@ from zLOG import LOG, INFO, ERROR
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from zExceptions import BadRequest from zExceptions import BadRequest
from Products.ERP5Type.tests.backportUnittest import expectedFailure from Products.ERP5Type.tests.backportUnittest import expectedFailure
import urllib
import urllib2
import httplib
import urlparse
# test files' home # test files' home
TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document') TEST_FILES_HOME = os.path.join(os.path.dirname(__file__), 'test_document')
...@@ -2004,6 +2008,41 @@ return result ...@@ -2004,6 +2008,41 @@ return result
reference='I.want.a.pdf', reference='I.want.a.pdf',
portal_type='PDF') portal_type='PDF')
def test_newContent_trough_http(self):
filename = 'import_region_category.xls'
path = makeFilePath(filename)
data = open(path, 'r').read()
reference = 'ITISAREFERENCE'
portal_url = self.portal.absolute_url()
url_split = urlparse.urlsplit(portal_url)
url_dict = dict(protocol=url_split[0],
hostname=url_split[1])
uri = '%(protocol)s://%(hostname)s' % url_dict
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(realm=None, uri=uri, user='ERP5TypeTestCase',
passwd='')
opener = urllib2.build_opener(urllib2.HTTPDigestAuthHandler(password_mgr),
urllib2.HTTPBasicAuthHandler(password_mgr))
urllib2.install_opener(opener)
push_url = '%s%s/newContent' % (uri, self.portal.portal_contributions.getPath(),)
request = urllib2.Request(push_url, urllib.urlencode(
{'data': data,
'filename': filename,
'reference': reference,
'disable_cookie_login__': 1,
}))
# disable_cookie_login__ is required to force zope to raise Unauthorized (401)
# then HTTPDigestAuthHandler can perform HTTP Authentication
response = urllib2.urlopen(request)
self.assertEquals(response.getcode(), httplib.OK)
transaction.commit()
self.tic()
document = self.portal.portal_catalog.getResultValue(portal_type='Spreadsheet',
reference=reference)
self.assertTrue(document is not None)
self.assertEquals(document.getData(), data)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment