Skip to content

Commit

Permalink
[15.0] connector-interfaces: fix test cases mock import
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 committed May 6, 2024
1 parent e452bd1 commit fad47ff
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
5 changes: 4 additions & 1 deletion connector_importer/models/import_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def _check_options(self):
)

def _load_options(self):
return yaml.safe_load(self.options or "") or []
options = []
if self.options:
options = yaml.safe_load(self.options)
return options if isinstance(options, list) else [options]

def available_importers(self):
self.ensure_one()
Expand Down
6 changes: 5 additions & 1 deletion connector_importer/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def _setup_records(cls):
"key": "fake",
"options": """
- model: res.partner
importer: fake.partner.importer
importer:
name: fake.partner.importer
options:
record_handler:
match_domain: "[('name', '=', values['name'])]"
""",
}
)
Expand Down
9 changes: 7 additions & 2 deletions connector_importer/tests/test_event_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import mock
from unittest import mock

from odoo_test_helper import FakeModelLoader

from odoo.tools import mute_logger
Expand Down Expand Up @@ -56,7 +57,11 @@ def setUpClass(cls):
{
"options": f"""
- model: res.partner
importer: fake.partner.importer
importer:
name: fake.partner.importer
options:
record_handler:
match_domain: "[('name', '=', values['name'])]"
- model: {FakeImportedModel._name}
options:
record_handler:
Expand Down
6 changes: 3 additions & 3 deletions connector_importer/tests/test_import_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_available_importers_legacy(self):
importers,
(
{
"importer": "partner.importer",
"model": "res.partner",
"importer": "partner.importer",
"is_last_importer": False,
"context": {},
"options": {
Expand All @@ -54,8 +54,8 @@ def test_available_importers_legacy(self):
},
},
{
"importer": "user.importer",
"model": "res.users",
"importer": "user.importer",
"is_last_importer": False,
"context": {},
"options": {
Expand All @@ -66,8 +66,8 @@ def test_available_importers_legacy(self):
},
},
{
"importer": "import.withspaces",
"model": "another.one",
"importer": "import.withspaces",
"is_last_importer": True,
"context": {},
"options": {
Expand Down
2 changes: 1 addition & 1 deletion connector_importer/tests/test_recordset_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import mock
from unittest import mock

from odoo.tools import mute_logger

Expand Down
3 changes: 2 additions & 1 deletion connector_importer/tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


import mock
from unittest import mock

from odoo_test_helper import FakeModelLoader

from .common import BaseTestCase
Expand Down
2 changes: 1 addition & 1 deletion connector_importer/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def to_b64(file_content):
"""Safe convertion to b64"""
try:
# py > 3.9
return base64.encodestring(file_content)
return base64.encodebytes(file_content)
except AttributeError:
# py <= 3.9
return base64.b64encode(file_content)
7 changes: 2 additions & 5 deletions connector_importer_source_sftp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# @author: Simone Orsi <simahawk@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.component.tests.common import (
TransactionComponentCase,
TransactionComponentRegistryCase,
)
from odoo.addons.component.tests.common import TransactionComponentCase
from odoo.addons.connector_importer.tests.common import TestImporterMixin


Expand All @@ -28,7 +25,7 @@ def setUpClass(cls):


class SFTPSourceTransactionComponentRegistryCase(
TransactionComponentRegistryCase, TestImporterMixin, TestSourceCSVSFTPMixin
TestImporterMixin, TestSourceCSVSFTPMixin
):
@classmethod
def setUpClass(cls):
Expand Down
4 changes: 1 addition & 3 deletions connector_importer_source_sftp/tests/test_csv_sftp_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import base64
import io

import mock
from unittest import mock

from odoo.tools import mute_logger

Expand All @@ -15,7 +14,6 @@


class TestSourceCSV(SFTPSourceTransactionComponentCase):

extra_fields = [
"chunk_size",
"csv_filesize",
Expand Down
3 changes: 1 addition & 2 deletions connector_importer_source_sftp/tests/test_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import base64
import io

import mock
from unittest import mock

from odoo.tools import mute_logger

Expand Down

0 comments on commit fad47ff

Please sign in to comment.