Repository navigation
[REVIEW] OCA/server-tools#3518: jsonifier migration to 19.0 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0-review-pr3518-precommit
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,12 +263,13 @@ Contributors | |
| - Iván Todorovich <[email protected]> | ||
| - Nguyen Minh Chien <[email protected]> | ||
| - Thien Vo <[email protected]> | ||
| - Mangono team <[email protected]> | ||
|
|
||
| Other credits | ||
| ------------- | ||
|
|
||
| The migration of this module from 17.0 to 18.0 was financially supported | ||
| by Camptocamp. | ||
| The migration of this module from 18.0 to 19.0 was financially supported | ||
| by Mangono. | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ | |
| - Iván Todorovich \<<[email protected]>\> | ||
| - Nguyen Minh Chien \<<[email protected]>\> | ||
| - Thien Vo \<<[email protected]>\> | ||
| - Mangono team \<<[email protected]>\> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp. | ||
| The migration of this module from 18.0 to 19.0 was financially supported by Mangono. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from . import test_data_setup | ||
| from . import test_get_parser | ||
| from . import test_helpers | ||
| from . import test_ir_exports_line |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| class JsonifierTestDataMixin: | ||
| @classmethod | ||
| def _create_demo_export_class(cls): | ||
| cls.ir_exp_partner = cls.env["ir.exports"].create( | ||
| { | ||
| "name": "Partner Export", | ||
| "resource": "res.partner", | ||
| } | ||
| ) | ||
| return cls.ir_exp_partner | ||
|
|
||
| @classmethod | ||
| def _create_demo_export_lines_class(cls): | ||
| export_lines_data = [ | ||
| {"name": "name"}, | ||
| {"name": "active"}, | ||
| {"name": "partner_latitude"}, | ||
| {"name": "color"}, | ||
| {"name": "category_id/name"}, | ||
| {"name": "country_id/name"}, | ||
| {"name": "country_id/code"}, | ||
| {"name": "child_ids/name"}, | ||
| {"name": "child_ids/id"}, | ||
| {"name": "child_ids/email"}, | ||
| {"name": "child_ids/country_id/name"}, | ||
| {"name": "child_ids/country_id/code"}, | ||
| {"name": "child_ids/child_ids/name"}, | ||
| {"name": "lang"}, | ||
| {"name": "comment"}, | ||
| ] | ||
|
|
||
| export_lines = cls.env["ir.exports.line"] | ||
|
|
||
| for line_data in export_lines_data: | ||
| line_data["export_id"] = cls.ir_exp_partner.id | ||
| line = cls.env["ir.exports.line"].create(line_data) | ||
| export_lines |= line | ||
|
|
||
| return export_lines | ||
|
|
||
| @classmethod | ||
| def _create_demo_resolver_class(cls): | ||
| python_code = """is_number = field_type in ('integer', 'float') | ||
| ftype = "NUMBER" if is_number else "TEXT" | ||
| value = value if is_number else str(value) | ||
| result = {"Key": name, "Value": value, "Type": ftype, "IsPublic": True}""" | ||
|
|
||
| cls.ir_exports_resolver_dict = cls.env["ir.exports.resolver"].create( | ||
| { | ||
| "name": "ExtraData dictionary (number/text)", | ||
| "python_code": python_code, | ||
| } | ||
| ) | ||
| return cls.ir_exports_resolver_dict | ||
|
|
||
| @classmethod | ||
| def setUpClass_demo_data(cls): | ||
| cls._create_demo_export_class() | ||
| cls._create_demo_export_lines_class() | ||
| cls._create_demo_resolver_class() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,18 @@ | |
| from odoo.tests.common import TransactionCase | ||
|
|
||
| from ..models.utils import convert_simple_to_full_parser | ||
| from .test_data_setup import JsonifierTestDataMixin | ||
|
|
||
|
|
||
| def jsonify_custom(self, field_name): | ||
| return "yeah!" | ||
|
|
||
|
|
||
| class TestParser(TransactionCase): | ||
| class TestParser(TransactionCase, JsonifierTestDataMixin): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.setUpClass_demo_data() | ||
| # disable tracking test suite wise | ||
| cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
| cls.env.user.tz = "Europe/Brussels" | ||
|
|
@@ -104,16 +106,8 @@ def test_getting_parser(self): | |
| "comment", | ||
| ] | ||
|
|
||
| exporter = self.env.ref("jsonifier.ir_exp_partner") | ||
| parser = exporter.get_json_parser() | ||
| expected_full_parser = convert_simple_to_full_parser(expected_parser) | ||
| self.assertEqual(parser, expected_full_parser) | ||
| exporter = self.ir_exp_partner | ||
|
|
||
| # modify an ir.exports_line to put a target for a field | ||
| self.env.ref("jsonifier.category_id_name").write( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · In-transaction edits keep stale targets When an export line is edited after its parser is cached in the same transaction, the export line’s Restore a test that generates the parser, edits the target, generates the parser again in the same transaction, and asserts the updated result. Also at Prompt for AI agentsIn `jsonifier/tests/test_get_parser.py` at line 113:
**In-transaction edits keep stale targets**
When an export line is edited after its parser is cached in the same transaction, the export line’s `write_date` stays at the transaction timestamp, so `get_json_parser()` reuses the cached parser and exports keep using the old target; without an edit-and-reparse assertion, the suite passes.
Restore a test that generates the parser, edits the target, generates the parser again in the same transaction, and asserts the updated result.
Also at `jsonifier/tests/test_get_parser.py:115`. |
||
| {"target": "category_id:category/name"} | ||
| ) | ||
| expected_parser[4] = ("category_id:category", ["name"]) | ||
| parser = exporter.get_json_parser() | ||
| expected_full_parser = convert_simple_to_full_parser(expected_parser) | ||
| self.assertEqual(parser, expected_full_parser) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Demo installs lose sample exports
When a user installs the module with demo data enabled, the manifest no longer loads the sample export, resolver, or CSV records, so demo-enabled installations have no packaged example configuration for users exploring the module.
Retain the packaged examples as demo data while keeping unit tests independent by creating their own fixtures.
Prompt for AI agents