0001-cmis-add-check_status-method-41986.patch
passerelle/apps/cmis/models.py | ||
---|---|---|
29 | 29 |
UpdateConflictException, |
30 | 30 |
) |
31 | 31 |
from django.db import models |
32 |
from django.utils.functional import cached_property |
|
32 | 33 |
from django.utils.six import BytesIO |
33 | 34 |
from django.utils.six.moves.urllib import error as urllib2 |
34 | 35 |
from django.utils.translation import ugettext_lazy as _ |
... | ... | |
84 | 85 |
class Meta: |
85 | 86 |
verbose_name = _('CMIS connector') |
86 | 87 | |
88 |
def check_status(self): |
|
89 |
cmis_gateway = CMISGateway(self.cmis_endpoint, self.username, self.password, self.logger) |
|
90 |
cmis_gateway.repo |
|
91 | ||
87 | 92 |
@endpoint( |
88 | 93 |
perm='can_access', |
89 | 94 |
post={ |
... | ... | |
157 | 162 |
self._cmis_client = CmisClient(cmis_endpoint, username, password) |
158 | 163 |
self._logger = logger |
159 | 164 | |
165 |
@cached_property |
|
166 |
def repo(self): |
|
167 |
return self._cmis_client.defaultRepository |
|
168 | ||
160 | 169 |
def _get_or_create_folder(self, file_path): |
161 |
repo = self._cmis_client.defaultRepository |
|
162 | 170 |
try: |
163 | 171 |
self._logger.debug("searching '%s'" % file_path) |
164 |
res = repo.getObjectByPath(file_path) |
|
172 |
res = self.repo.getObjectByPath(file_path)
|
|
165 | 173 |
self._logger.debug("'%s' found" % file_path) |
166 | 174 |
return res |
167 | 175 |
except ObjectNotFoundException: |
168 | 176 |
self._logger.debug("'%s' not found" % file_path) |
169 | 177 |
basepath = "" |
170 |
folder = repo.rootFolder |
|
178 |
folder = self.repo.rootFolder
|
|
171 | 179 |
for path_part in file_path.strip('/').split('/'): |
172 | 180 |
basepath += '/%s' % path_part |
173 | 181 |
try: |
174 | 182 |
self._logger.debug("searching '%s'" % basepath) |
175 |
folder = repo.getObjectByPath(basepath) |
|
183 |
folder = self.repo.getObjectByPath(basepath)
|
|
176 | 184 |
self._logger.debug("'%s' found" % basepath) |
177 | 185 |
except ObjectNotFoundException: |
178 | 186 |
self._logger.debug("'%s' not found" % basepath) |
tests/test_cmis.py | ||
---|---|---|
582 | 582 |
assert json_result['err'] == 0 |
583 | 583 |
assert json_result['data']['properties']['cmis:objectTypeId'] == "cmis:document" |
584 | 584 |
assert json_result['data']['properties']['cmis:name'] == file_name |
585 | ||
586 | ||
587 |
def test_cmis_check_status(app, setup, monkeypatch): |
|
588 |
cmis_gateway = Mock() |
|
589 |
type(cmis_gateway).repo = mock.PropertyMock(side_effect=CmisException) |
|
590 |
cmis_gateway_cls = Mock(return_value=cmis_gateway) |
|
591 |
import passerelle.apps.cmis.models |
|
592 | ||
593 |
monkeypatch.setattr(passerelle.apps.cmis.models, 'CMISGateway', cmis_gateway_cls) |
|
594 | ||
595 |
with pytest.raises(CmisException): |
|
596 |
setup.check_status() |
|
585 |
- |