0002-cmis-mute-cmislib-logs-56881.patch
passerelle/apps/cmis/models.py | ||
---|---|---|
18 | 18 |
import binascii |
19 | 19 |
import functools |
20 | 20 |
import re |
21 |
from contextlib import contextmanager |
|
21 | 22 | |
22 | 23 |
import httplib2 |
23 | 24 |
from cmislib import CmisClient |
... | ... | |
37 | 38 |
from passerelle.base.models import BaseResource |
38 | 39 |
from passerelle.utils.api import endpoint |
39 | 40 |
from passerelle.utils.jsonresponse import APIError |
41 |
from passerelle.utils.logging import ignore_loggers |
|
40 | 42 | |
41 | 43 |
SPECIAL_CHARS = '!#$%&+-^_`~;[]{}+=~' |
42 | 44 |
FILE_PATH_PATTERN = r'^(/|(/[\w%s]+)+)$' % re.escape(SPECIAL_CHARS) |
... | ... | |
105 | 107 |
verbose_name = _('CMIS connector') |
106 | 108 | |
107 | 109 |
def check_status(self): |
108 |
cmis_gateway = self.get_cmis_gateway()
|
|
109 |
cmis_gateway.repo |
|
110 |
with self.get_cmis_gateway() as cmis_gateway:
|
|
111 |
cmis_gateway.repo
|
|
110 | 112 | |
111 | 113 |
@endpoint( |
112 | 114 |
description=_('File upload'), |
... | ... | |
126 | 128 |
raise APIError(error_msg, http_status=400) |
127 | 129 |
filename = data.get('filename') or data['file']['filename'] |
128 | 130 |
self.logger.info("received file_name: '%s', file_path: '%s'", filename, data["path"]) |
129 |
cmis_gateway = self.get_cmis_gateway() |
|
130 |
doc = cmis_gateway.create_doc( |
|
131 |
filename, |
|
132 |
data['path'], |
|
133 |
data['file_byte_content'], |
|
134 |
content_type=data['file'].get('content_type'), |
|
135 |
object_type=data.get('object_type'), |
|
136 |
properties=data.get('properties'), |
|
137 |
) |
|
138 |
return {'data': {'properties': doc.properties}} |
|
139 | ||
131 |
with self.get_cmis_gateway() as cmis_gateway: |
|
132 |
doc = cmis_gateway.create_doc( |
|
133 |
filename, |
|
134 |
data['path'], |
|
135 |
data['file_byte_content'], |
|
136 |
content_type=data['file'].get('content_type'), |
|
137 |
object_type=data.get('object_type'), |
|
138 |
properties=data.get('properties'), |
|
139 |
) |
|
140 |
return {'data': {'properties': doc.properties}} |
|
141 | ||
142 |
@contextmanager |
|
140 | 143 |
def get_cmis_gateway(self): |
141 |
return CMISGateway(self.cmis_endpoint, self.username, self.password, self.logger) |
|
144 |
with ignore_loggers('cmislib'): |
|
145 |
yield CMISGateway(self.cmis_endpoint, self.username, self.password, self.logger) |
|
142 | 146 | |
143 | 147 |
def _validate_inputs(self, data): |
144 | 148 |
"""process dict |
passerelle/apps/cmis/views.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
from cmislib import CmisClient |
|
18 | 17 |
from cmislib.exceptions import ObjectNotFoundException |
19 | 18 |
from django.http import Http404 |
20 | 19 |
from django.utils.translation import ugettext_lazy as _ |
... | ... | |
27 | 26 |
model = CmisConnector |
28 | 27 |
template_name = 'cmis/cmis_type.html' |
29 | 28 | |
30 |
def get(self, request, *args, **kwargs):
|
|
29 |
def dispatch(self, request, *args, **kwargs):
|
|
31 | 30 |
self.connector = CmisConnector.objects.get(slug=kwargs['connector_slug']) |
32 |
self.cmis_gateway = self.connector.get_cmis_gateway() |
|
31 |
with self.connector.get_cmis_gateway() as cmis_gateway: |
|
32 |
self.cmis_gateway = cmis_gateway |
|
33 |
return super().dispatch(request, *args, **kwargs) |
|
33 | 34 | |
35 |
def get(self, request, *args, **kwargs): |
|
34 | 36 |
type_id = request.GET.get('id') |
35 | 37 |
if type_id: |
36 | 38 |
try: |
... | ... | |
39 | 41 |
raise Http404(_('Cmis type not found.')) |
40 | 42 |
else: |
41 | 43 |
self.current_type = None |
42 | ||
43 | 44 |
return super(CmisTypeView, self).get(request, *args, **kwargs) |
44 | 45 | |
45 | 46 |
def get_context_data(self, **kwargs): |
tests/test_cmis.py | ||
---|---|---|
510 | 510 | |
511 | 511 |
@pytest.mark.parametrize('debug', (False, True)) |
512 | 512 |
@mock.patch('httplib2.Http.request') |
513 |
def test_raw_uploadfile(mocked_request, app, setup, debug): |
|
513 |
def test_raw_uploadfile(mocked_request, app, setup, debug, caplog):
|
|
514 | 514 |
""" Simulate the bellow bash query : |
515 | 515 |
$ http https://passerelle.dev.publik.love/cmis/ged/uploadfile \ |
516 | 516 |
file:='{"filename": "test2", "content": "c2FsdXQK"}' path=/test-eo |
517 | 517 |
""" |
518 |
caplog.set_level('DEBUG') |
|
518 | 519 |
file_name = "test2" |
519 | 520 |
file_content = 'salut\n' |
520 | 521 |
path = "/test-eo" |
... | ... | |
587 | 588 |
assert logs[9].message == 'cmislib POST response (200)' |
588 | 589 |
assert logs[9].extra['response'].startswith('<?xml') |
589 | 590 | |
591 |
assert not any('cmislib' in record.name for record in caplog.records) |
|
592 | ||
590 | 593 | |
591 | 594 |
def test_cmis_check_status(app, setup, monkeypatch): |
592 | 595 |
cmis_gateway = Mock() |
593 |
- |