cmis: use 'filename' parameter for wcs compliance (#22409)

Use 'data' keyword for the returned data.
This commit is contained in:
Emmanuel Cazenave 2018-03-13 12:00:06 +01:00
parent 537a2cfd8e
commit 5f792313c1
4 changed files with 30 additions and 30 deletions

View File

@ -26,13 +26,13 @@ def test_uploadfile(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, monkeypatch
file_b64_content = base64.b64encode(f.read())
response = requests.post(
url, json={"path": cmis_tmpdir + path,
"file": {"content": file_b64_content, "name": file_name,
"file": {"content": file_b64_content, "filename": file_name,
"content_type": "image/jpeg"}})
assert response.status_code == 200
resp_data = response.json()
assert resp_data['err'] == 0
assert resp_data['properties']['cmis:name'] == file_name
doc = cmisclient.defaultRepository.getObject(resp_data['properties']['cmis:objectId'])
assert resp_data['data']['properties']['cmis:name'] == file_name
doc = cmisclient.defaultRepository.getObject(resp_data['data']['properties']['cmis:objectId'])
with open(result_filename, 'wb') as f:
result = doc.getContentStream()
f.write(result.read())
@ -51,7 +51,7 @@ def test_uploadfile_conflict(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, mo
file_b64_content = base64.b64encode('file_content')
response = requests.post(
url, json={"path": cmis_tmpdir + '/uploadconflict',
"file": {"content": file_b64_content, "name": 'some.file',
"file": {"content": file_b64_content, "filename": 'some.file',
"content_type": "image/jpeg"}})
assert response.status_code == 200
resp_data = response.json()
@ -59,7 +59,7 @@ def test_uploadfile_conflict(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, mo
file_b64_content = base64.b64encode('other_file_content')
response = requests.post(
url, json={"path": cmis_tmpdir + '/uploadconflict',
"file": {"content": file_b64_content, "name": 'some.file',
"file": {"content": file_b64_content, "filename": 'some.file',
"content_type": "image/jpeg"}})
assert response.status_code == 200
resp_data = response.json()

View File

@ -63,14 +63,14 @@ class CmisConnector(BaseResource):
if error:
self.logger.debug("received invalid data: %s" % error_msg)
raise APIError(error_msg, http_status=400)
self.logger.info("received file_name: '%s', file_path: '%s'", data['file']['name'],
self.logger.info("received file_name: '%s', file_path: '%s'", data['file']['filename'],
data["path"])
cmis_gateway = CMISGateway(self.cmis_endpoint, self.username, self.password, self.logger)
doc = cmis_gateway.create_doc(
data['file']['name'], data['path'], data['file_byte_content'])
data['file']['filename'], data['path'], data['file_byte_content'])
self.logger.info(
"create document '%s' with path '%s'", data['file']['name'], data['path'])
return {'properties': doc.properties}
"create document '%s' with path '%s'", data['file']['filename'], data['path'])
return {'data': {'properties': doc.properties}}
def _validate_inputs(self, body):
""" process JSON body
@ -93,12 +93,12 @@ class CmisConnector(BaseResource):
file_ = data['file']
if 'name' not in file_:
return True, '"file[\'name\']" is required', None
if not isinstance(file_['name'], unicode):
return True, '"file[\'name\']" must be string', None
if not RE_FILE_NAME.match(file_['name']):
return True, '"file[\'name\']" must be valid file name', None
if 'filename' not in file_:
return True, '"file[\'filename\']" is required', None
if not isinstance(file_['filename'], unicode):
return True, '"file[\'filename\']" must be string', None
if not RE_FILE_NAME.match(file_['filename']):
return True, '"file[\'filename\']" must be valid file name', None
if 'content' not in file_:
return True, '"file[\'content\']" is required', None

View File

@ -11,7 +11,7 @@
data_send = {
'path': '/a/path',
'file': {
'name': 'test.txt',
'filename': 'test.txt',
'content': 'ZmlsZSBjb250ZW50',
'content_type': 'image/jpeg'
}

View File

@ -45,7 +45,7 @@ def test_uploadfile(app, setup, tmpdir, monkeypatch):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": file_name,
"file": {"filename": file_name,
"content": base64.b64encode(file_content),
"content_type": "image/jpeg"}})
result_file = py.path.local(file_name)
@ -54,7 +54,7 @@ def test_uploadfile(app, setup, tmpdir, monkeypatch):
assert result_file.read() == file_content
json_result = response.json_body
assert json_result['err'] == 0
assert json_result['properties'] == {"toto": "tata"}
assert json_result['data']['properties'] == {"toto": "tata"}
def test_uploadfile_error_if_no_file_name(app, setup):
@ -65,37 +65,37 @@ def test_uploadfile_error_if_no_file_name(app, setup):
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
assert response.json_body['err_desc'].startswith('"file[\'name\']" is required')
assert response.json_body['err_desc'].startswith('"file[\'filename\']" is required')
def test_uploadfile_error_if_non_string_file_name(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": 1, "content": base64.b64encode('aaaa'),
"file": {"filename": 1, "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
assert response.json_body['err_desc'].startswith('"file[\'name\']" must be string')
assert response.json_body['err_desc'].startswith('"file[\'filename\']" must be string')
def test_uploadfile_error_if_non_valid_file_name(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": ",.,", "content": base64.b64encode('aaaa'),
"file": {"filename": ",.,", "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
assert response.json_body['err_desc'].startswith('"file[\'name\']" must be valid file name')
assert response.json_body['err_desc'].startswith('"file[\'filename\']" must be valid file name')
def test_uploadfile_error_if_no_path(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"file": {"name": 'somefile.txt', "content": base64.b64encode('aaaa'),
params={"file": {"filename": 'somefile.txt', "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
@ -107,7 +107,7 @@ def test_uploadfile_error_if_non_string_path(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": 1,
"file": {"name": 'somefile.txt', "content": base64.b64encode('aaaa'),
"file": {"filename": 'somefile.txt', "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
@ -119,7 +119,7 @@ def test_uploadfile_error_if_no_regular_path(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "no/leading/slash",
"file": {"name": 'somefile.txt', "content": base64.b64encode('aaaa'),
"file": {"filename": 'somefile.txt', "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
@ -131,7 +131,7 @@ def test_uploadfile_error_if_no_file_content(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": 'somefile.txt', "content_type": "image/jpeg"}},
"file": {"filename": 'somefile.txt', "content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
@ -142,7 +142,7 @@ def test_uploadfile_error_if_non_string_file_content(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": 'somefile.txt', "content": 1, "content_type": "image/jpeg"}},
"file": {"filename": 'somefile.txt', "content": 1, "content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
@ -153,7 +153,7 @@ def test_uploadfile_error_if_no_proper_base64_encoding(app, setup):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": 'somefile.txt', "content": "1", "content_type": "image/jpeg"}},
"file": {"filename": 'somefile.txt', "content": "1", "content_type": "image/jpeg"}},
expect_errors=True)
assert response.status_code == 400
assert response.json_body['err'] == 1
@ -171,7 +171,7 @@ def test_uploadfile_cmis_gateway_error(app, setup, monkeypatch):
response = app.post_json(
'/cmis/slug-cmis/uploadfile',
params={"path": "/some/folder/structure",
"file": {"name": "file_name", "content": base64.b64encode('aaaa'),
"file": {"filename": "file_name", "content": base64.b64encode('aaaa'),
"content_type": "image/jpeg"}})
assert response.json_body['err'] == 1
assert response.json_body['err_desc'].startswith("some error")