Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,2 @@
from . import test_import
from . import test_export

View file

@ -0,0 +1,54 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import base64
from odoo.tests.common import TransactionCase
class SyncCommon(TransactionCase):
def _clean_testing_directory(self):
for test_dir in [
self.directory_input,
self.directory_output,
self.directory_archived,
]:
fs = self.backend.fs
if not fs.exists(test_dir):
fs.makedirs(test_dir)
for filename in fs.ls(test_dir, detail=False):
fs.rm(filename)
def _create_test_file(self):
fs = self.backend.fs
path = fs.sep.join([self.directory_input, "bar.txt"])
with fs.open(path, "wb") as f:
f.write(self.filedata)
def setUp(self):
super().setUp()
self.backend = self.env.ref("fs_storage.default_fs_storage")
self.filedata = base64.b64encode(b"This is a simple file")
self.directory_input = "test_import"
self.directory_output = "test_export"
self.directory_archived = "test_archived"
self._clean_testing_directory()
self._create_test_file()
self.task = self.env.ref("attachment_synchronize.import_from_filestore")
self.task_delete = self.env.ref(
"attachment_synchronize.import_from_filestore_delete"
)
self.task_move = self.env.ref(
"attachment_synchronize.import_from_filestore_move"
)
self.task_rename = self.env.ref(
"attachment_synchronize.import_from_filestore_rename"
)
self.task_move_rename = self.env.ref(
"attachment_synchronize.import_from_filestore_move_rename"
)
def tearDown(self):
self._clean_testing_directory()
super().tearDown()

View file

@ -0,0 +1,43 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from unittest import mock
from odoo.tools import mute_logger
from .common import SyncCommon
def raising_side_effect(*args, **kwargs):
raise Exception("Boom")
class TestExport(SyncCommon):
def setUp(self):
super().setUp()
self.task = self.env.ref("attachment_synchronize.export_to_filestore")
self.attachment = self.env["attachment.queue"].create(
{
"name": "foo.txt",
"task_id": self.task.id,
"file_type": "export",
"datas": self.filedata,
}
)
def test_export(self):
self.attachment.run()
result = self.backend.fs.ls("test_export", detail=False)
self.assertEqual(result, ["test_export/foo.txt"])
@mute_logger("odoo.addons.attachment_queue.models.attachment_queue")
def test_failing_export(self):
with mock.patch.object(
type(self.backend.fs),
"open",
side_effect=raising_side_effect,
):
self.attachment.with_context(queue_job__no_delay=True).run_as_job()
self.assertEqual(self.attachment.state, "failed")
self.assertEqual(self.attachment.state_message, "Boom")

View file

@ -0,0 +1,87 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api
from .common import SyncCommon
class TestImport(SyncCommon):
def tearDown(self):
self.registry.leave_test_mode()
super().tearDown()
def setUp(self):
super().setUp()
self.registry.enter_test_mode(self.env.cr)
self.env = api.Environment(
self.registry.test_cr, self.env.uid, self.env.context
)
@property
def archived_files(self):
return self.backend.fs.ls(self.directory_archived, detail=False)
@property
def input_files(self):
return self.backend.fs.ls(self.directory_input, detail=False)
def _check_attachment_created(self, count=1):
with self.env.registry.cursor() as new_cr:
attachment = self.env(cr=new_cr)["attachment.queue"].search(
[("name", "=", "bar.txt")]
)
self.assertEqual(len(attachment), count)
def test_import_with_rename(self):
self.task_rename.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, ["test_import/test-bar.txt"])
self.assertEqual(self.archived_files, [])
def test_import_with_move(self):
self.task_move.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, ["test_archived/bar.txt"])
def test_import_with_move_and_rename(self):
self.task_move_rename.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, ["test_archived/foo.txt"])
def test_import_with_delete(self):
self.task_delete.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, [])
def test_import_twice(self):
self.task_delete.run_import()
self._check_attachment_created(count=1)
self._create_test_file()
self.task_delete.run_import()
self._check_attachment_created(count=2)
def test_import_twice_no_duplicate(self):
self.task.run_import()
self._check_attachment_created(count=1)
self._create_test_file()
self.task.run_import()
self._check_attachment_created(count=1)
def test_running_cron(self):
self.env["attachment.synchronize.task"].search(
[("id", "!=", self.task.id)]
).write({"active": False})
self.env["attachment.synchronize.task"].run_task_import_scheduler()
self._check_attachment_created(count=1)
def test_running_cron_disable_task(self):
self.env["attachment.synchronize.task"].search([]).write({"active": False})
self.env["attachment.synchronize.task"].run_task_import_scheduler()
self._check_attachment_created(count=0)