[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
parent
f597b71ddb
commit
7bd7c02c89
|
@ -204,9 +204,11 @@ class AttachmentSynchronizeTask(models.Model):
|
|||
)
|
||||
|
||||
def _file_to_import(self, filenames):
|
||||
imported = self.attachment_ids.filtered(
|
||||
lambda r: r.name in filenames
|
||||
).mapped("name")
|
||||
imported = (
|
||||
self.env["attachment.queue"]
|
||||
.search([("name", "in", filenames)])
|
||||
.mapped("name")
|
||||
)
|
||||
return list(set(filenames) - set(imported))
|
||||
|
||||
def button_toogle_enabled(self):
|
||||
|
|
|
@ -29,7 +29,7 @@ class SyncCommon(Common):
|
|||
self.env.cr.commit = mock.Mock()
|
||||
self.registry.enter_test_mode(self.env.cr)
|
||||
self.directory_input = "test_import"
|
||||
self.directory_output = "test_output"
|
||||
self.directory_output = "test_export"
|
||||
self.directory_archived = "test_archived"
|
||||
self._clean_testing_directory()
|
||||
self._create_test_file()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
import mock
|
||||
from .common import SyncCommon
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
def raising_side_effect(*args, **kwargs):
|
||||
|
@ -29,6 +30,7 @@ class TestExport(SyncCommon):
|
|||
result = self.backend._list("test_export")
|
||||
self.assertEqual(result, ["foo.txt"])
|
||||
|
||||
@mute_logger("odoo.addons.attachment_queue.models.attachment_queue")
|
||||
def test_failing_export(self):
|
||||
with mock.patch.object(
|
||||
type(self.backend),
|
||||
|
|
|
@ -15,9 +15,7 @@ class TestImport(SyncCommon):
|
|||
return self.backend._list(self.directory_input)
|
||||
|
||||
def _check_attachment_created(self, count=1):
|
||||
attachment = self.env["attachment.queue"].search(
|
||||
[("name", "=", "bar.txt")]
|
||||
)
|
||||
attachment = self.env["attachment.queue"].search([("name", "=", "bar.txt")])
|
||||
self.assertEqual(len(attachment), count)
|
||||
|
||||
def test_import_with_rename(self):
|
||||
|
@ -28,9 +26,7 @@ class TestImport(SyncCommon):
|
|||
self.assertEqual(self.archived_files, [])
|
||||
|
||||
def test_import_with_move(self):
|
||||
self.task.write(
|
||||
{"after_import": "move", "move_path": self.directory_archived}
|
||||
)
|
||||
self.task.write({"after_import": "move", "move_path": self.directory_archived})
|
||||
self.task.run_import()
|
||||
self._check_attachment_created()
|
||||
self.assertEqual(self.input_files, [])
|
||||
|
|
Loading…
Reference in New Issue