From b62e8a5ec4c9f5ee32e75e17befee8dd874ab524 Mon Sep 17 00:00:00 2001 From: EL HADJI DEM Date: Tue, 13 May 2014 15:30:04 -0400 Subject: [PATCH] [IMP] FIxed comments from LP, added unittests,fix pep8 errors --- cmis_write/__openerp__.py | 6 +- cmis_write/ir_attachment.py | 2 +- cmis_write/metadata.py | 4 +- cmis_write/tests/__init__.py | 29 ++++++++++ cmis_write/tests/test_attachment.py | 88 +++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 cmis_write/tests/__init__.py create mode 100644 cmis_write/tests/test_attachment.py diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index f1cbc463..6f0dc20c 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -24,9 +24,9 @@ 'name': 'CMIS Write', 'version': '0.1', 'category': 'Knowledge Management', - 'summary': 'Create Document in DMS from OpenErp', + 'summary': 'Create Document in DMS from OpenERP', 'description': """ -Add Documents from OpenErp +Add Documents from OpenERP ========================== This module allows you to store OpenERP document in the DMS repository. @@ -55,7 +55,7 @@ you have to: http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model. * Add the custom aspect to the document you upload or create in Alfresco. -Using CMIS I suggest you: +Using CMIS I suggest you: http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-adding.html. * Set the custom property in the way you probably know using CMIS. diff --git a/cmis_write/ir_attachment.py b/cmis_write/ir_attachment.py index b8484b40..01dd3ea6 100644 --- a/cmis_write/ir_attachment.py +++ b/cmis_write/ir_attachment.py @@ -122,7 +122,7 @@ def create_doc_in_edm(session, model_name, value, res, value['datas']), contentType=value['file_type']) # TODO: create custom properties on a document (Alfresco) - #someDoc.getProperties().update(props) + # someDoc.getProperties().update(props) # Updating ir.attachment object with the new id # of document generated by DMS ir_attach_obj.write(session.cr, session.uid, res, { diff --git a/cmis_write/metadata.py b/cmis_write/metadata.py index 29a8bb1e..3ab11414 100644 --- a/cmis_write/metadata.py +++ b/cmis_write/metadata.py @@ -54,8 +54,8 @@ class metadata(orm.Model): return {'value': {'model_ids': [(6, 0, [])]}} model_ids = [model_id] model_obj = self.pool.get('ir.model') - active_model_obj = self.pool.get(model_obj.browse(cr, uid, - model_id).model) + active_model_obj = self.pool.get(model_obj.browse( + cr, uid, model_id, context=context).model) if active_model_obj._inherits: for key, val in active_model_obj._inherits.items(): found_model_ids = model_obj.search(cr, diff --git a/cmis_write/tests/__init__.py b/cmis_write/tests/__init__.py new file mode 100644 index 00000000..4189b3d0 --- /dev/null +++ b/cmis_write/tests/__init__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 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_attachment, +) + +checks = [ + test_attachment, +] diff --git a/cmis_write/tests/test_attachment.py b/cmis_write/tests/test_attachment.py new file mode 100644 index 00000000..d3d796d9 --- /dev/null +++ b/cmis_write/tests/test_attachment.py @@ -0,0 +1,88 @@ +# -*- 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 +from openerp.addons.connector.session import ConnectorSession + + +class test_attachment(TransactionCase): + + def setUp(self): + super(test_attachment, self).setUp() + # Clean up registries + self.registry('ir.model').clear_caches() + self.registry('ir.model.data').clear_caches() + # Get registries + self.user_model = self.registry("res.users") + self.ir_attachment_model = self.registry("ir.attachment") + self.partner_model = self.registry('res.partner') + self.metadata_model = self.registry('metadata') + # Get context + self.context = self.user_model.context_get(self.cr, self.uid) + + partner_id = self.partner_model.create( + self.cr, self.uid, + {'name': 'Test Partner', + 'email': 'test@localhost', + 'is_company': True, + }, context=None) + + blob1 = 'blob1' + blob1_b64 = blob1.encode('base64') + + self.vals = { + 'name': 'a1', + 'datas': blob1_b64, + 'attachment_document_ids': [(0, 0, { + 'res_model': "res.partner", + 'res_id': partner_id, + 'res_name': 'Test Partner', + })], + } + + def test_create_test_attachment(self): + cr, uid, vals, context = self.cr, self.uid, self.vals, self.context + metadata_ids = self.metadata_model.search(cr, uid, [], context=context) + dict_metadata = {} + list_fields = [] + + # Get list of metadata + if vals['res_model']: + for line in self.metadata_obj.browse( + cr, uid, metadata_ids, context=context): + if line.model_id.model == vals['res_model']: + if line.metadata_list_ids: + for one_field in line.metadata_list_ids: + list_fields.append(one_field.field_id.name) + result = self.pool.get(vals['res_model']).read(cr, uid, [ + vals['res_id']], list_fields, context=context)[0] + + for one_field in list_fields: + dict_metadata['cmis:' + one_field] = result[one_field] + context['bool_testdoc'] = True + + ir_attachment_id = self.ir_attachment_model.create( + cr, uid, vals, context=context) + ir_attachment_pool = self.ir_attachment_model.browse( + cr, uid, ir_attachment_id, context=context) + + self.assertEqual(ir_attachment_pool.name, vals['name'])