From a52ffe47013007e26b55f74ed180231900fa166e Mon Sep 17 00:00:00 2001 From: Angel Moya Date: Mon, 3 Oct 2016 14:16:44 +0200 Subject: [PATCH] ADD tests --- attachment_base_synchronize/README.rst | 1 + attachment_base_synchronize/__openerp__.py | 3 ++ .../demo/attachment_metadata_demo.xml | 12 +++++ attachment_base_synchronize/tests/__init__.py | 5 ++ .../tests/test_attachment_base_synchronize.py | 50 +++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 attachment_base_synchronize/demo/attachment_metadata_demo.xml create mode 100644 attachment_base_synchronize/tests/__init__.py create mode 100644 attachment_base_synchronize/tests/test_attachment_base_synchronize.py diff --git a/attachment_base_synchronize/README.rst b/attachment_base_synchronize/README.rst index 5abfa0cc4..fe25020d2 100644 --- a/attachment_base_synchronize/README.rst +++ b/attachment_base_synchronize/README.rst @@ -67,6 +67,7 @@ Contributors * Sebastien BEAU * Joel Grand-Guillaume Camptocamp * initOS +* Angel Moya Maintainer ---------- diff --git a/attachment_base_synchronize/__openerp__.py b/attachment_base_synchronize/__openerp__.py index 2b0fbae79..cdc33023c 100644 --- a/attachment_base_synchronize/__openerp__.py +++ b/attachment_base_synchronize/__openerp__.py @@ -18,6 +18,9 @@ 'security/ir.model.access.csv', 'data/cron.xml', ], + 'demo': [ + 'demo/attachment_metadata_demo.xml' + ], 'installable': True, 'application': False, 'images': [], diff --git a/attachment_base_synchronize/demo/attachment_metadata_demo.xml b/attachment_base_synchronize/demo/attachment_metadata_demo.xml new file mode 100644 index 000000000..1a8444557 --- /dev/null +++ b/attachment_base_synchronize/demo/attachment_metadata_demo.xml @@ -0,0 +1,12 @@ + + + + + + bWlncmF0aW9uIHRlc3Q= + attachment_metadata.doc + attachment_metadata.doc + + + + diff --git a/attachment_base_synchronize/tests/__init__.py b/attachment_base_synchronize/tests/__init__.py new file mode 100644 index 000000000..ef5480f44 --- /dev/null +++ b/attachment_base_synchronize/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Angel Moya (http://angelmoya.es) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_attachment_base_synchronize diff --git a/attachment_base_synchronize/tests/test_attachment_base_synchronize.py b/attachment_base_synchronize/tests/test_attachment_base_synchronize.py new file mode 100644 index 000000000..7ace25276 --- /dev/null +++ b/attachment_base_synchronize/tests/test_attachment_base_synchronize.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Angel Moya (http://angelmoya.es) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase +import openerp +from openerp import api + + +class TestAttachmentBaseSynchronize(TransactionCase): + + def setUp(self): + super(TestAttachmentBaseSynchronize, self).setUp() + self.registry.enter_test_mode() + self.env = api.Environment(self.registry.test_cr, self.env.uid, + self.env.context) + self.attachment = self.env.ref( + 'attachment_base_synchronize.attachment_metadata') + self.ir_attachment_metadata = self.env['ir.attachment.metadata'] + + def tearDown(self): + self.registry.leave_test_mode() + super(TestAttachmentBaseSynchronize, self).tearDown() + + def test_attachment_metadata(self): + """Test run_attachment_metadata_scheduler to ensure set state to done + """ + self.assertEqual( + self.attachment.state, + 'pending' + ) + self.ir_attachment_metadata.run_attachment_metadata_scheduler() + self.env.invalidate_all() + with openerp.registry(self.env.cr.dbname).cursor() as new_cr: + new_env = api.Environment( + new_cr, self.env.uid, self.env.context) + attach = self.attachment.with_env(new_env) + self.assertEqual( + attach.state, + 'done' + ) + + def test_set_done(self): + """Test set_done manually + """ + self.attachment.set_done() + self.assertEqual( + self.attachment.state, + 'done' + )