Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
e775a91c
Commit
e775a91c
authored
Mar 22, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WebDAVSupport: py3
parent
983b3e2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
54 deletions
+69
-54
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testWebDavSupport.py
...lateItem/portal_components/test.erp5.testWebDavSupport.py
+63
-51
product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py
...mplateItem/portal_components/module.erp5.WebDAVSupport.py
+6
-3
No files found.
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testWebDavSupport.py
View file @
e775a91c
...
...
@@ -35,7 +35,7 @@ from Products.ERP5Type.tests.utils import FileUpload
from
unittest
import
expectedFailure
import
six.moves.http_client
from
six.moves
import
cStringIO
as
String
IO
from
io
import
Bytes
IO
from
DateTime
import
DateTime
from
lxml
import
etree
...
...
@@ -46,11 +46,6 @@ def makeFilePath(name):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
Products
.
ERP5
.
tests
.
__file__
),
'test_data'
,
name
)
def
makeFileUpload
(
name
,
as_name
=
None
):
if
as_name
is
None
:
as_name
=
name
path
=
makeFilePath
(
name
)
return
FileUpload
(
path
,
as_name
)
class
TestWebDavSupport
(
ERP5TypeTestCase
):
"""Test for WEBDAV access.
...
...
@@ -58,6 +53,14 @@ class TestWebDavSupport(ERP5TypeTestCase):
authentication
=
'ERP5TypeTestCase:'
def
makeFileUpload
(
self
,
name
,
as_name
=
None
):
if
as_name
is
None
:
as_name
=
name
path
=
makeFilePath
(
name
)
fu
=
FileUpload
(
path
,
as_name
)
self
.
addCleanup
(
fu
.
close
)
return
fu
def
getTitle
(
self
):
return
"Test WebDav Support"
...
...
@@ -94,11 +97,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
"""
person
=
self
.
portal
.
person_module
.
newContent
()
self
.
tic
()
file_object
=
makeFileUpload
(
'images/erp5_logo.png'
)
response
=
self
.
publish
(
person
.
getPath
()
+
'/erp5_logo.png'
,
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
'images/erp5_logo.png'
)
response
=
self
.
publish
(
person
.
getPath
()
+
'/erp5_logo.png'
,
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'image/png'
},
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
CREATED
)
image
=
person
[
'erp5_logo.png'
]
self
.
assertEqual
(
image
.
getPortalType
(),
'Embedded File'
)
...
...
@@ -113,11 +118,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
# Create a new document via FTP/DAV
path
=
self
.
portal
.
portal_contributions
.
getPath
()
filename
=
'P-DMS-Presentation.3.Pages-001-en.odp'
file_object
=
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'application/vnd.oasis.opendocument.presentation'
},
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
CREATED
)
document_module
=
self
.
getDocumentModule
()
...
...
@@ -135,11 +142,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
# Create a new document via FTP/DAV
path
=
self
.
portal
.
portal_contributions
.
getPath
()
filename
=
'P-DMS-Presentation.3.Pages-001-en.odp'
file_object
=
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'application/vnd.oasis.opendocument.presentation'
},
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
CREATED
)
self
.
tic
()
...
...
@@ -152,7 +161,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
# force usage of manage_FTPget like zwebdav_server does
response
=
self
.
publish
(
'%s/%s/manage_FTPget'
%
(
path
,
document_id
),
request_method
=
'GET'
,
stdin
=
String
IO
(),
stdin
=
Bytes
IO
(),
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
OK
)
self
.
assertEqual
(
response
.
getBody
(),
document
.
getData
(),
...
...
@@ -175,7 +184,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
self
.
assertEqual
(
web_page_module
[
filename
].
getPortalType
(),
'Web Page'
)
# Edit a new document via FTP/DAV
text_content
=
"""<html>
text_content
=
u
"""<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
...
...
@@ -185,19 +194,20 @@ class TestWebDavSupport(ERP5TypeTestCase):
</body>
</html>
"""
iso_text_content
=
text_content
.
decode
(
'utf-8'
).
encode
(
'iso-8859-1'
)
iso_text_content
=
text_content
.
encode
(
'iso-8859-1'
)
path
=
web_page_module
.
getPath
()
for
_
in
range
(
2
):
# Run twice to check the code that compares
# old & new data when setting file attribute.
# Run twice to check the code that compares old & new data
# when setting file attribute.
for
_
in
range
(
2
):
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
String
IO
(
iso_text_content
),
stdin
=
Bytes
IO
(
iso_text_content
),
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
NO_CONTENT
)
self
.
assertEqual
(
web_page_module
[
filename
].
getData
(),
iso_text_content
)
# Convert to base format and run conversion into utf-8
self
.
tic
()
# Content-Type header is replaced if
s
onversion encoding succeed
# Content-Type header is replaced if
c
onversion encoding succeed
new_text_content
=
text_content
.
replace
(
'charset=iso-8859-1'
,
'charset=utf-8'
)
self
.
assertEqual
(
web_page_module
[
filename
].
getTextContent
(),
new_text_content
)
...
...
@@ -206,11 +216,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
"""
path
=
self
.
portal
.
portal_contributions
.
getPath
()
filename
=
'P-DMS-Presentation.3.Pages-001-en.odp'
file_object
=
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'application/vnd.oasis.opendocument.presentation'
},
basic
=
self
.
authentication
)
# Convert to base format and run conversion into utf-8
self
.
tic
()
...
...
@@ -219,9 +231,9 @@ class TestWebDavSupport(ERP5TypeTestCase):
# This is HTTPServer.zhttp_server not HTTPServer.zwebdav_server
# force usage of manage_FTPget like zwebdav_server does
response
=
self
.
publish
(
document
.
getPath
()
+
'/manage_FTPget'
,
response
=
self
.
publish
(
document
.
getPath
()
+
'/manage_FTPget'
,
request_method
=
'GET'
,
stdin
=
String
IO
(),
stdin
=
Bytes
IO
(),
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
OK
)
...
...
@@ -233,11 +245,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
"""
path
=
self
.
portal
.
portal_contributions
.
getPath
()
filename
=
'P-DMS-Presentation.3.Pages-001-en.odp'
file_object
=
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'application/vnd.oasis.opendocument.presentation'
},
basic
=
self
.
authentication
)
document_module
=
self
.
getDocumentModule
()
document
=
document_module
[
filename
]
...
...
@@ -245,7 +259,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
response
=
self
.
publish
(
document
.
getPath
(),
request_method
=
'PROPFIND'
,
env
=
{
'HTTP_DEPTH'
:
'0'
},
stdin
=
String
IO
(),
stdin
=
Bytes
IO
(),
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
MULTI_STATUS
)
...
...
@@ -271,11 +285,13 @@ class TestWebDavSupport(ERP5TypeTestCase):
"""
path
=
self
.
portal
.
portal_contributions
.
getPath
()
filename
=
'P-DMS-Presentation.3.Pages-001-en.odp'
file_object
=
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
basic
=
self
.
authentication
)
file_object
=
self
.
makeFileUpload
(
filename
)
response
=
self
.
publish
(
'%s/%s'
%
(
path
,
filename
),
request_method
=
'PUT'
,
stdin
=
file_object
,
env
=
{
"CONTENT_TYPE"
:
'application/vnd.oasis.opendocument.presentation'
},
basic
=
self
.
authentication
)
document_module
=
self
.
getDocumentModule
()
document
=
document_module
[
filename
]
...
...
@@ -283,7 +299,7 @@ class TestWebDavSupport(ERP5TypeTestCase):
response
=
self
.
publish
(
document
.
getPath
(),
request_method
=
'PROPFIND'
,
env
=
{
'HTTP_DEPTH'
:
'0'
},
stdin
=
String
IO
(),
stdin
=
Bytes
IO
(),
basic
=
self
.
authentication
)
self
.
assertEqual
(
response
.
getStatus
(),
six
.
moves
.
http_client
.
MULTI_STATUS
)
...
...
@@ -293,7 +309,3 @@ class TestWebDavSupport(ERP5TypeTestCase):
'{DAV:}response/{DAV:}propstat/{DAV:}prop/{DAV:}creationdate'
).
text
,
document
.
getCreationDate
().
HTML4
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestWebDavSupport
))
return
suite
product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.WebDAVSupport.py
View file @
e775a91c
...
...
@@ -23,7 +23,7 @@ from Products.ERP5Type.Globals import InitializeClass
from
Products.ERP5Type
import
Permissions
from
Products.CMFCore.PortalContent
import
ResourceLockedError
from
zExceptions
import
Forbidden
from
six.moves
import
cStringIO
as
String
IO
from
io
import
Bytes
IO
import
six
security
=
ModuleSecurityInfo
(
__name__
)
...
...
@@ -50,7 +50,10 @@ class TextContent:
raise
Exception
except
Exception
:
# this is probably not html code, try rfc822 parsing
message
=
email
.
message_from_string
(
text
)
if
six
.
PY3
:
message
=
email
.
message_from_bytes
(
text
)
else
:
message
=
email
.
message_from_string
(
text
)
return
{
k
.
capitalize
():
'
\
n
'
.
join
(
message
.
get_all
(
k
))
for
k
in
message
.
keys
()}
...
...
@@ -78,7 +81,7 @@ class TextContent:
headers
=
self
.
parseHeadersFromText
(
body
)
content_type
=
REQUEST
.
get_header
(
'Content-Type'
,
''
)
headers
.
setdefault
(
'content_type'
,
content_type
)
headers
[
'file'
]
=
String
IO
(
body
)
headers
[
'file'
]
=
Bytes
IO
(
body
)
self
.
_edit
(
**
headers
)
except
ResourceLockedError
:
transaction
.
abort
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment