Skip to content

Commit

Permalink
[IMP] util/helpers: tests for import/export empty paths
Browse files Browse the repository at this point in the history
Commits 5b944f7 and
1d9e20e did not consider the case of empty
paths, what was fixed in a05df66.
Due to its urgent nature, no tests were added with the fix's commit.

That said, this commit adds tests for the case when `base_import.mapping` or
`ir.export.line` present path fields which are empty.
  • Loading branch information
pauloamed committed Jul 8, 2024
1 parent 86d814b commit c4a7f2a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def setUp(self):
(0, 0, {"name": "rate_ids/company_id/user_ids/name"}),
(0, 0, {"name": "rate_ids/company_id/user_ids/partner_id/user_ids/name"}),
(0, 0, {"name": "rate_ids/name"}),
(0, 0, {}),
],
}
]
Expand All @@ -444,7 +445,7 @@ def test_rename_field(self):
def test_remove_field(self):
util.remove_field(self.cr, "res.currency.rate", "company_id")
self._invalidate()
self.assertEqual(len(self.export.export_fields), 2)
self.assertEqual(len(self.export.export_fields), 3)
self.assertEqual(self.export.export_fields[0].name, "full_name")
self.assertEqual(self.export.export_fields[1].name, "rate_ids/name")

Expand All @@ -456,11 +457,11 @@ def test_rename_model(self):
def test_remove_model(self):
util.remove_model(self.cr, "res.currency.rate")
self._invalidate()
self.assertEqual(len(self.export.export_fields), 1)
self.assertEqual(self.export.export_fields[0].name, "full_name")
self.assertEqual(len(self.export.export_fields), 2)
self.assertEqual(self.export.export_fields.mapped("name"), ["full_name", False])

util.remove_model(self.cr, "res.currency")
self.cr.execute("SELECT * FROM ir_exports WHERE id = %s", [self.export.id])
self.cr.execute("SELECT * FROM ir_exports WHERE id IN %s", [tuple(self.export.ids)])
self.assertFalse(self.cr.fetchall())


Expand All @@ -478,6 +479,9 @@ def setUp(self):
]
]
)
self.import_mapping = self.import_mapping + self.env["base_import.mapping"].create(
{"res_model": "res.currency", "column_name": "Column name"}
)

util.flush(self.import_mapping)

Expand Down Expand Up @@ -523,10 +527,10 @@ def test_remove_model(self):
remaining_mappings = self.import_mapping - removed_mappings

self.assertEqual(len(removed_mappings), 3)
self.assertEqual(remaining_mappings[0].field_name, "full_name")
self.assertEqual(remaining_mappings.mapped("field_name"), ["full_name", False])

util.remove_model(self.cr, "res.currency")
self.cr.execute("SELECT * FROM base_import_mapping WHERE id = %s", [remaining_mappings.id])
self.cr.execute("SELECT * FROM base_import_mapping WHERE id IN %s", [tuple(remaining_mappings.ids)])
self.assertFalse(self.cr.fetchall())


Expand Down

0 comments on commit c4a7f2a

Please sign in to comment.