From 686c766b7dd965ad6d8bbf4d409ccd918844d449 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Sat, 9 Nov 2019 11:48:38 +0100 Subject: [PATCH] [12.0] Add shopinvader_locomotive_algolia --- shopinvader_locomotive_algolia/README.rst | 86 ++++ shopinvader_locomotive_algolia/__init__.py | 1 + .../__manifest__.py | 15 + .../component/__init__.py | 1 + .../shopinvader_site_export_mapper.py | 25 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/CREDITS.rst | 4 + .../readme/DESCRIPTION.rst | 1 + .../readme/HISTORY.rst | 4 + .../static/description/index.html | 441 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_search_engine_site_export.py | 94 ++++ 12 files changed, 674 insertions(+) create mode 100644 shopinvader_locomotive_algolia/README.rst create mode 100644 shopinvader_locomotive_algolia/__init__.py create mode 100644 shopinvader_locomotive_algolia/__manifest__.py create mode 100644 shopinvader_locomotive_algolia/component/__init__.py create mode 100644 shopinvader_locomotive_algolia/component/shopinvader_site_export_mapper.py create mode 100644 shopinvader_locomotive_algolia/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_locomotive_algolia/readme/CREDITS.rst create mode 100644 shopinvader_locomotive_algolia/readme/DESCRIPTION.rst create mode 100644 shopinvader_locomotive_algolia/readme/HISTORY.rst create mode 100644 shopinvader_locomotive_algolia/static/description/index.html create mode 100644 shopinvader_locomotive_algolia/tests/__init__.py create mode 100644 shopinvader_locomotive_algolia/tests/test_search_engine_site_export.py diff --git a/shopinvader_locomotive_algolia/README.rst b/shopinvader_locomotive_algolia/README.rst new file mode 100644 index 0000000000..a4ba5aa377 --- /dev/null +++ b/shopinvader_locomotive_algolia/README.rst @@ -0,0 +1,86 @@ +============================== +Shopinvader Locomotive algolia +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fodoo--shopinvader-lightgray.png?logo=github + :target: https://github.com/OCA/odoo-shopinvader/tree/12.0/shopinvader_locomotive_algolia + :alt: OCA/odoo-shopinvader +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/odoo-shopinvader-12-0/odoo-shopinvader-12-0-shopinvader_locomotive_algolia + :alt: Translate me on Weblate + +|badge1| |badge2| |badge3| |badge4| + +Takes care of exporting Algolia related data to Locomotive. + +**Table of contents** + +.. contents:: + :local: + +Changelog +========= + +12.0.1.0.0 (2019-11-20) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [12.0] Add shopinvader_locomotive_algolia + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptcamp SA + +Contributors +~~~~~~~~~~~~ + +* Simone Orsi + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* Camptocamp +* Cosanum + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/shopinvader_locomotive_algolia/__init__.py b/shopinvader_locomotive_algolia/__init__.py new file mode 100644 index 0000000000..34ea9e4b12 --- /dev/null +++ b/shopinvader_locomotive_algolia/__init__.py @@ -0,0 +1 @@ +from . import component diff --git a/shopinvader_locomotive_algolia/__manifest__.py b/shopinvader_locomotive_algolia/__manifest__.py new file mode 100644 index 0000000000..c3e105b045 --- /dev/null +++ b/shopinvader_locomotive_algolia/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2019 Camptocamp (http://www.camptocamp.com). +# @author Simone Orsi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Locomotive algolia", + "summary": """ + This addons is used to push the initial algolia configuration + to locomotive""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "Camptcamp SA", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": ["component", "shopinvader_locomotive", "shopinvader_algolia"], +} diff --git a/shopinvader_locomotive_algolia/component/__init__.py b/shopinvader_locomotive_algolia/component/__init__.py new file mode 100644 index 0000000000..289ffc3336 --- /dev/null +++ b/shopinvader_locomotive_algolia/component/__init__.py @@ -0,0 +1 @@ +from . import shopinvader_site_export_mapper diff --git a/shopinvader_locomotive_algolia/component/shopinvader_site_export_mapper.py b/shopinvader_locomotive_algolia/component/shopinvader_site_export_mapper.py new file mode 100644 index 0000000000..36b1e5f63a --- /dev/null +++ b/shopinvader_locomotive_algolia/component/shopinvader_site_export_mapper.py @@ -0,0 +1,25 @@ +# Copyright 2019 Camptocamp (http://www.camptocamp.com). +# @author Simone Orsi +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.component.core import Component + + +class ShopinvaderSiteExportMapper(Component): + _inherit = ["shopinvader.site.export.mapper"] + + # matching $searchengine_name + '_config' + def _algolia_config(self, se_backend, config): + if ( + self.options["force"] + or not config.get("application_id") + or not config.get("api_key") + ): + spec_backend = se_backend.specific_backend + config.update( + { + "application_id": spec_backend.algolia_app_id, + "api_key": spec_backend.algolia_api_key, + } + ) + return config diff --git a/shopinvader_locomotive_algolia/readme/CONTRIBUTORS.rst b/shopinvader_locomotive_algolia/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..47349558c8 --- /dev/null +++ b/shopinvader_locomotive_algolia/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Simone Orsi diff --git a/shopinvader_locomotive_algolia/readme/CREDITS.rst b/shopinvader_locomotive_algolia/readme/CREDITS.rst new file mode 100644 index 0000000000..3038e84ea8 --- /dev/null +++ b/shopinvader_locomotive_algolia/readme/CREDITS.rst @@ -0,0 +1,4 @@ +The development of this module has been financially supported by: + +* Camptocamp +* Cosanum diff --git a/shopinvader_locomotive_algolia/readme/DESCRIPTION.rst b/shopinvader_locomotive_algolia/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..8e3bbf8cac --- /dev/null +++ b/shopinvader_locomotive_algolia/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Takes care of exporting Algolia related data to Locomotive. diff --git a/shopinvader_locomotive_algolia/readme/HISTORY.rst b/shopinvader_locomotive_algolia/readme/HISTORY.rst new file mode 100644 index 0000000000..d0a00a8625 --- /dev/null +++ b/shopinvader_locomotive_algolia/readme/HISTORY.rst @@ -0,0 +1,4 @@ +12.0.1.0.0 (2019-11-20) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [12.0] Add shopinvader_locomotive_algolia diff --git a/shopinvader_locomotive_algolia/static/description/index.html b/shopinvader_locomotive_algolia/static/description/index.html new file mode 100644 index 0000000000..82a978074c --- /dev/null +++ b/shopinvader_locomotive_algolia/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Shopinvader Locomotive algolia + + + +
+

Shopinvader Locomotive algolia

+ + +

Beta License: AGPL-3 OCA/odoo-shopinvader Translate me on Weblate

+

Takes care of exporting Algolia related data to Locomotive.

+

Table of contents

+ +
+

Changelog

+
+

12.0.1.0.0 (2019-11-20)

+
    +
  • [12.0] Add shopinvader_locomotive_algolia
  • +
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptcamp SA
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • Camptocamp
  • +
  • Cosanum
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/odoo-shopinvader project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/shopinvader_locomotive_algolia/tests/__init__.py b/shopinvader_locomotive_algolia/tests/__init__.py new file mode 100644 index 0000000000..da4ddc0780 --- /dev/null +++ b/shopinvader_locomotive_algolia/tests/__init__.py @@ -0,0 +1 @@ +from . import test_search_engine_site_export diff --git a/shopinvader_locomotive_algolia/tests/test_search_engine_site_export.py b/shopinvader_locomotive_algolia/tests/test_search_engine_site_export.py new file mode 100644 index 0000000000..05f58ca83d --- /dev/null +++ b/shopinvader_locomotive_algolia/tests/test_search_engine_site_export.py @@ -0,0 +1,94 @@ +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import json + +from odoo.addons.shopinvader_locomotive import tests as base_tests + +# black is not able to format this properly :/ +Base = base_tests.test_search_engine_site_export.TestSiteSearchEngineExportBase + + +class TestSiteSearchEngineExport(Base): + @classmethod + def setUpClass(cls): + super(TestSiteSearchEngineExport, cls).setUpClass() + cls.indexes = [ + { + "name": "categories", + "index": "demo_algolia_backend_shopinvader_category", + }, + { + "name": "products", + "index": "demo_algolia_backend_shopinvader_variant", + }, + ] + cls.expected_settings["indices"] = json.dumps(cls.indexes) + cls.expected_settings["application_id"] = "ABCDEFG" + cls.expected_settings["api_key"] = "123456789" + + @classmethod + def _setup_search_engine(cls): + cls.specific_backend = cls.env.ref("connector_algolia.se_algolia_demo") + cls.specific_backend.write( + {"algolia_app_id": "ABCDEFG", "algolia_api_key": "123456789"} + ) + cls.backend.se_backend_id = cls.specific_backend.se_backend_id + cls.search_engine_name = cls.backend.se_backend_id.search_engine_name + + def test_search_engine_synchronize_01(self): + """ + Data: + * SE data not filled into locomotive + Test case: + * synchronize metadata + Expected result: + * SE data is filled + :return: + """ + # wipe current settings + self._update_site_metafields(self.search_engine_name, {}) + # run sync -> we get the expected default ones + self._test_sync(self.expected_settings) + + def test_search_engine_synchronize_02(self): + """ + Data: + * SE data filled into locomotive + Test case: + * synchronize metadata + Expected result: + * SE data not updated into locomotive + :return: + """ + old_values = { + "indices": "foo", + "routes": "baz", + "application_id": "REPLACE_ID", + "api_key": "REPLACE_KEY", + } + # force this values in settings + self._update_site_metafields(self.search_engine_name, old_values) + # run sync w/no reset -> they are preserved + self._test_sync(old_values) + + def test_search_engine_synchronize_03(self): + """ + Data: + * SE data filled into locomotive + Test case: + * force reset settings + Expected result: + * SE data updated into locomotive + :return: + """ + old_values = { + "indices": "foo", + "routes": "baz", + "application_id": "REPLACE_ID", + "api_key": "REPLACE_KEY", + } + # force this values in settings + self._update_site_metafields(self.search_engine_name, old_values) + # run sync w/ reset -> they are computed again + self._test_sync(self.expected_settings, reset=True)