|
| 1 | +# Copyright 2023 Akretion (https://www.akretion.com). |
| 2 | +# @author Kévin Roche <[email protected]> |
| 3 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
| 4 | +from uuid import uuid4 |
| 5 | +from odoo.tests.common import SavepointCase |
| 6 | +from odoo.addons.pattern_import_export.tests.test_pattern_import import ( |
| 7 | + TestPatternImport, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +class TestPatternImportExportImportType(TestPatternImport): |
| 12 | + @classmethod |
| 13 | + def setUpClass(cls): |
| 14 | + super().setUpClass() |
| 15 | + |
| 16 | + def test_import_type_update_only(self): |
| 17 | + # simulate a record update with "create only" (fail) |
| 18 | + # then with "update only" (success) import type. |
| 19 | + unique_name = str(uuid4()) |
| 20 | + data = [{"login#key": self.user3.login, "name": unique_name}] |
| 21 | + pattern_file = self.create_pattern(self.pattern_config_m2m, "import", data) |
| 22 | + pattern_file.pattern_config_id.import_type = "create_only" |
| 23 | + records = self.run_pattern_file(pattern_file) |
| 24 | + chunk = pattern_file.chunk_ids |
| 25 | + self.assertIn("Import Type not allowing updating record.", chunk.result_info) |
| 26 | + self.assertNotEqual(unique_name, self.user3.name) |
| 27 | + pattern_file.pattern_config_id.import_type = "update_only" |
| 28 | + records = self.run_pattern_file(pattern_file) |
| 29 | + chunk = pattern_file.chunk_ids |
| 30 | + self.assertNotIn("Import Type not allowing", chunk.result_info) |
| 31 | + self.assertEqual(unique_name, self.user3.name) |
| 32 | + |
| 33 | + def test_import_type_create(self): |
| 34 | + # simulate a record creation with "update only" (fail) |
| 35 | + # then with "update and create" (success) import type. |
| 36 | + unique_name = str(uuid4()) |
| 37 | + unique_login = str(uuid4()) |
| 38 | + data = [{"name": unique_name, "login": unique_login}] |
| 39 | + pattern_file = self.create_pattern(self.pattern_config_m2m, "import", data) |
| 40 | + pattern_file.pattern_config_id.import_type = "update_only" |
| 41 | + records = self.run_pattern_file(pattern_file) |
| 42 | + chunk = pattern_file.chunk_ids |
| 43 | + self.assertIn("Import Type not allowing record creation.", chunk.result_info) |
| 44 | + self.assertFalse(records) |
| 45 | + |
| 46 | + pattern_file.pattern_config_id.import_type = "update_and_creation" |
| 47 | + records = self.run_pattern_file(pattern_file) |
| 48 | + chunk = pattern_file.chunk_ids |
| 49 | + self.assertNotIn("Import Type not allowing", chunk.result_info) |
| 50 | + self.assertEqual(len(records), 1) |
0 commit comments