From 2e94231d11bef911f92d2b54c8ba0142414f7ca1 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 10 Oct 2016 17:30:40 +0200 Subject: [PATCH] [IMP] Add tests for cmis_web_alf --- cmis_web_alf/tests/__init__.py | 6 +++ cmis_web_alf/tests/test_cmis_backend.py | 54 +++++++++++++++++++++++++ cmis_web_alf/tests/test_fields.py | 22 ++++++++++ 3 files changed, 82 insertions(+) create mode 100644 cmis_web_alf/tests/__init__.py create mode 100644 cmis_web_alf/tests/test_cmis_backend.py create mode 100644 cmis_web_alf/tests/test_fields.py diff --git a/cmis_web_alf/tests/__init__.py b/cmis_web_alf/tests/__init__.py new file mode 100644 index 00000000..bbff5b54 --- /dev/null +++ b/cmis_web_alf/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_fields +from . import test_cmis_backend diff --git a/cmis_web_alf/tests/test_cmis_backend.py b/cmis_web_alf/tests/test_cmis_backend.py new file mode 100644 index 00000000..e34ec0a2 --- /dev/null +++ b/cmis_web_alf/tests/test_cmis_backend.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import mock + +from openerp.tests import common + + +class TestCmisBackend(common.SavepointCase): + + def setUp(self): + super(TestCmisBackend, self).setUp() + self.cmis_backend = self.env['cmis.backend'] + self.backend_instance = self.env.ref('cmis.cmis_backend_alfresco') + + def test_get_content_details_url(self): + with mock.patch("openerp.addons.cmis.models.cmis_backend." + "CmisBackend.get_cmis_repository" + ) as mocked_get_repository: + mocked_cmis_repository = mock.MagicMock() + mocked_get_repository.return_value = mocked_cmis_repository + mocked_cmis_object = mock.MagicMock() + mocked_cmis_repository.getObject.return_value = mocked_cmis_object + # test folder url without cmis:path + mocked_cmis_object.getProperties.return_value = { + 'cmis:baseTypeId': 'cmis:folder', + 'cmis:path': None, + 'alfcmis:nodeRef': 'alfnoderef'} + url = self.backend_instance.get_content_details_url('my_id') + self.assertEqual( + url, + 'http://localhost:8080/share/page/folder-details' + '?nodeRef=alfnoderef') + # test folder url with cmis:path + mocked_cmis_object.getProperties.return_value = { + 'cmis:baseTypeId': 'cmis:folder', + 'cmis:path': '/odoo/my-folder', + 'alfcmis:nodeRef': 'alfnoderef'} + url = self.backend_instance.get_content_details_url('my_id') + self.assertEqual( + url, + 'http://localhost:8080/share/page/repository' + '#filter=path%7C%2Fodoo%2Fmy-folder') + # test document + mocked_cmis_object.getProperties.return_value = { + 'cmis:baseTypeId': 'cmis:document', + 'alfcmis:nodeRef': 'alfnoderef'} + url = self.backend_instance.get_content_details_url('my_id') + self.assertEqual( + url, + 'http://localhost:8080/share/page/document-details' + '?nodeRef=alfnoderef') diff --git a/cmis_web_alf/tests/test_fields.py b/cmis_web_alf/tests/test_fields.py new file mode 100644 index 00000000..701a7b0b --- /dev/null +++ b/cmis_web_alf/tests/test_fields.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp.addons.cmis_field.tests import common + + +class TestCmisFields(common.BaseTestCmis): + + def test_cmis_folder_get_desciption(self): + inst = self.env['cmis.test.model'].create({'name': 'folder_name'}) + # get_description is the method call by the method fields_get + # to return to the UI the desciption of the UI + descr = inst._fields['cmis_folder'].get_description(self.env) + backend_description = descr.get('backend') + share_location = backend_description.get( + 'share_location') + alfresco_api_location = backend_description.get( + 'alfresco_api_location') + self.assertEqual( + self.cmis_backend.share_location, share_location) + self.assertEqual( + self.cmis_backend.alfresco_api_location, alfresco_api_location)