[FIX] attachment_synchronize: fix tests

- correct `directory_output` value

- mute logger for desired raise exception

- change how the "already imported files" are checked when
"check_duplicated_files = True" :
It occurs that a task o2m field `attachment_ids` returns an empty record
when checked during the `_file_to_import()` method... but only when
the module `autovacuum_message_attachment` is installed !
pull/2632/head
clementmbr 2020-06-22 15:48:37 -03:00 committed by Florian da Costa
parent f597b71ddb
commit 7bd7c02c89
4 changed files with 10 additions and 10 deletions

View File

@ -204,9 +204,11 @@ class AttachmentSynchronizeTask(models.Model):
) )
def _file_to_import(self, filenames): def _file_to_import(self, filenames):
imported = self.attachment_ids.filtered( imported = (
lambda r: r.name in filenames self.env["attachment.queue"]
).mapped("name") .search([("name", "in", filenames)])
.mapped("name")
)
return list(set(filenames) - set(imported)) return list(set(filenames) - set(imported))
def button_toogle_enabled(self): def button_toogle_enabled(self):

View File

@ -29,7 +29,7 @@ class SyncCommon(Common):
self.env.cr.commit = mock.Mock() self.env.cr.commit = mock.Mock()
self.registry.enter_test_mode(self.env.cr) self.registry.enter_test_mode(self.env.cr)
self.directory_input = "test_import" self.directory_input = "test_import"
self.directory_output = "test_output" self.directory_output = "test_export"
self.directory_archived = "test_archived" self.directory_archived = "test_archived"
self._clean_testing_directory() self._clean_testing_directory()
self._create_test_file() self._create_test_file()

View File

@ -4,6 +4,7 @@
import mock import mock
from .common import SyncCommon from .common import SyncCommon
from odoo.tools import mute_logger
def raising_side_effect(*args, **kwargs): def raising_side_effect(*args, **kwargs):
@ -29,6 +30,7 @@ class TestExport(SyncCommon):
result = self.backend._list("test_export") result = self.backend._list("test_export")
self.assertEqual(result, ["foo.txt"]) self.assertEqual(result, ["foo.txt"])
@mute_logger("odoo.addons.attachment_queue.models.attachment_queue")
def test_failing_export(self): def test_failing_export(self):
with mock.patch.object( with mock.patch.object(
type(self.backend), type(self.backend),

View File

@ -15,9 +15,7 @@ class TestImport(SyncCommon):
return self.backend._list(self.directory_input) return self.backend._list(self.directory_input)
def _check_attachment_created(self, count=1): def _check_attachment_created(self, count=1):
attachment = self.env["attachment.queue"].search( attachment = self.env["attachment.queue"].search([("name", "=", "bar.txt")])
[("name", "=", "bar.txt")]
)
self.assertEqual(len(attachment), count) self.assertEqual(len(attachment), count)
def test_import_with_rename(self): def test_import_with_rename(self):
@ -28,9 +26,7 @@ class TestImport(SyncCommon):
self.assertEqual(self.archived_files, []) self.assertEqual(self.archived_files, [])
def test_import_with_move(self): def test_import_with_move(self):
self.task.write( self.task.write({"after_import": "move", "move_path": self.directory_archived})
{"after_import": "move", "move_path": self.directory_archived}
)
self.task.run_import() self.task.run_import()
self._check_attachment_created() self._check_attachment_created()
self.assertEqual(self.input_files, []) self.assertEqual(self.input_files, [])