cmis: add check_status method (#41986)

This commit is contained in:
Valentin Deniaud 2021-07-07 17:34:26 +02:00
parent fcef614d90
commit 80f50e5c65
2 changed files with 24 additions and 4 deletions

View File

@ -29,6 +29,7 @@ from cmislib.exceptions import (
UpdateConflictException,
)
from django.db import models
from django.utils.functional import cached_property
from django.utils.six import BytesIO
from django.utils.six.moves.urllib import error as urllib2
from django.utils.translation import ugettext_lazy as _
@ -84,6 +85,10 @@ class CmisConnector(BaseResource):
class Meta:
verbose_name = _('CMIS connector')
def check_status(self):
cmis_gateway = CMISGateway(self.cmis_endpoint, self.username, self.password, self.logger)
cmis_gateway.repo
@endpoint(
perm='can_access',
post={
@ -157,22 +162,25 @@ class CMISGateway(object):
self._cmis_client = CmisClient(cmis_endpoint, username, password)
self._logger = logger
@cached_property
def repo(self):
return self._cmis_client.defaultRepository
def _get_or_create_folder(self, file_path):
repo = self._cmis_client.defaultRepository
try:
self._logger.debug("searching '%s'" % file_path)
res = repo.getObjectByPath(file_path)
res = self.repo.getObjectByPath(file_path)
self._logger.debug("'%s' found" % file_path)
return res
except ObjectNotFoundException:
self._logger.debug("'%s' not found" % file_path)
basepath = ""
folder = repo.rootFolder
folder = self.repo.rootFolder
for path_part in file_path.strip('/').split('/'):
basepath += '/%s' % path_part
try:
self._logger.debug("searching '%s'" % basepath)
folder = repo.getObjectByPath(basepath)
folder = self.repo.getObjectByPath(basepath)
self._logger.debug("'%s' found" % basepath)
except ObjectNotFoundException:
self._logger.debug("'%s' not found" % basepath)

View File

@ -582,3 +582,15 @@ def test_raw_uploadfile(mocked_request, app, setup):
assert json_result['err'] == 0
assert json_result['data']['properties']['cmis:objectTypeId'] == "cmis:document"
assert json_result['data']['properties']['cmis:name'] == file_name
def test_cmis_check_status(app, setup, monkeypatch):
cmis_gateway = Mock()
type(cmis_gateway).repo = mock.PropertyMock(side_effect=CmisException)
cmis_gateway_cls = Mock(return_value=cmis_gateway)
import passerelle.apps.cmis.models
monkeypatch.setattr(passerelle.apps.cmis.models, 'CMISGateway', cmis_gateway_cls)
with pytest.raises(CmisException):
setup.check_status()