Browse Source

[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 !
12.0-mig-module_prototyper_last
clementmbr 4 years ago
committed by David Beal
parent
commit
dde33b0acf
  1. 8
      attachment_synchronize/models/task.py
  2. 2
      attachment_synchronize/tests/common.py
  3. 2
      attachment_synchronize/tests/test_export.py
  4. 8
      attachment_synchronize/tests/test_import.py

8
attachment_synchronize/models/task.py

@ -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(
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)) return list(set(filenames) - set(imported))
def button_toogle_enabled(self): def button_toogle_enabled(self):

2
attachment_synchronize/tests/common.py

@ -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()

2
attachment_synchronize/tests/test_export.py

@ -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),

8
attachment_synchronize/tests/test_import.py

@ -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(
[("name", "=", "bar.txt")]
)
attachment = self.env["attachment.queue"].search([("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(
{"after_import": "move", "move_path": self.directory_archived}
)
self.task.write({"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, [])

Loading…
Cancel
Save