diff --git a/cmis/cmis_model.py b/cmis/cmis_model.py index 9a2b6365..e9de9b0f 100644 --- a/cmis/cmis_model.py +++ b/cmis/cmis_model.py @@ -20,13 +20,9 @@ # ############################################################################## -from openerp.osv import orm, fields, osv +from openerp.osv import orm, fields from openerp.tools.translate import _ -from openerp.addons.connector.queue.job import job from cmislib.model import CmisClient -import openerp.addons.connector as connector -from openerp.addons.connector.session import ConnectorSession -import base64 import cmislib.exceptions @@ -57,10 +53,10 @@ class cmis_backend(orm.Model): try: return client.defaultRepository except cmislib.exceptions.ObjectNotFoundException: - raise osv.except_osv(_('Cmis connection Error!'), + raise orm.except_orm(_('Cmis connection Error!'), _("Check your cmis account configuration.")) except cmislib.exceptions.PermissionDeniedException: - raise osv.except_osv(_('Cmis connection Error!'), + raise orm.except_orm(_('Cmis connection Error!'), _("Check your cmis account configuration.")) def check_directory_of_write(self, cr, uid, ids, context=None): @@ -68,7 +64,7 @@ class cmis_backend(orm.Model): context = {} cmis_backend_obj = self.pool.get('cmis.backend') datas_fname = 'testdoc' - #login with the cmis account + # login with the cmis account repo = self._auth(cr, uid, context=context) folder_path_write = cmis_backend_obj.read( @@ -81,7 +77,7 @@ class cmis_backend(orm.Model): # Document properties if bool_path_write: sub = repo.getObjectByPath(folder_path_write) - someDoc = sub.createDocumentFromString( + sub.createDocumentFromString( datas_fname, contentString='hello, world', contentType='text/plain') @@ -89,12 +85,10 @@ class cmis_backend(orm.Model): def check_directory_of_read(self, cr, uid, ids, context=None): ir_attach_obj = self.pool.get('ir.attachment') - ir_attach_dms_obj = self.pool.get('ir.attachment.dms') if context is None: context = {} cmis_backend_obj = self.pool.get('cmis.backend') - #login with the cmis account - #login with the cmis account + # login with the cmis account repo = self._auth(cr, uid, context=context) folder_path_read = cmis_backend_obj.read( cr, uid, ids, ['initial_directory_read'], @@ -117,8 +111,7 @@ class cmis_backend(orm.Model): 'type': 'binary', 'datas': result.getContentStream().read().encode('base64'), } - res = ir_attach_obj.create(cr, uid, data_attach, - context=context) + ir_attach_obj.create(cr, uid, data_attach, context=context) self.get_error_for_path(bool_path_read, folder_path_read) def check_existing_path(self, rs, folder_path): @@ -134,10 +127,10 @@ class cmis_backend(orm.Model): def get_error_for_path(self, bool, path): if bool: - raise osv.except_osv(_('Cmis Message'), + raise orm.except_orm(_('Cmis Message'), _("Path is correct for : " + path)) else: - raise osv.except_osv(_('Cmis Error!'), + raise orm.except_orm(_('Cmis Error!'), _("Error path for : " + path)) _columns = { diff --git a/cmis/security/ir.model.access.csv b/cmis/security/ir.model.access.csv new file mode 100644 index 00000000..a999cc5b --- /dev/null +++ b/cmis/security/ir.model.access.csv @@ -0,0 +1,2 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +access_cmis_backend_user,access_cmis_backend_user,model_cmis_backend,base.group_user,1,0,0,0 diff --git a/cmis/tests/__init__.py b/cmis/tests/__init__.py new file mode 100644 index 00000000..be75a744 --- /dev/null +++ b/cmis/tests/__init__.py @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013-2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import ( + test_model, +) + +checks = [ + test_model, +] diff --git a/cmis/tests/test_model.py b/cmis/tests/test_model.py new file mode 100644 index 00000000..4d81b804 --- /dev/null +++ b/cmis/tests/test_model.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +############################################################################### +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp.tests.common import TransactionCase + + +class test_model(TransactionCase): + + def setUp(self): + super(test_model, self).setUp() + # Clean up registries + self.registry('ir.model').clear_caches() + self.registry('ir.model.data').clear_caches() + # Get registries + self.model = self.registry("cmis.backend") + # Get context + self.context = self.model.context_get(self.cr, self.uid) + + self.vals = { + 'name': "Test cmis", + 'version': '1.0', + 'location': "http://localhost:8081/alfresco/s/cmis", + 'username': 'admin', + 'password': 'admin', + } + + def test_create_model(self): + model_id = self.model.create( + self.cr, self.uid, self.vals, context=self.context) + self.assertTrue(model_id)