From db6a130889150fd36ac5e2d202f0a806eb4ec61f Mon Sep 17 00:00:00 2001
From: Christophe Monniez <moc@odoo.com>
Date: Tue, 23 Feb 2021 13:24:08 +0000
Subject: [PATCH] [FIX] tests: test support for modules without `__init__.py`

Now that a test exists to enforce `__init__.py` in odoo module, we must
ensure that we keep the feature.

For that reason, a white-list system is added in `test_dunderinit` and a
test is added in order to be sure that a module without `__init__.py` can
be exists.

This this is made of a fake module `test_data_module` without
 `__init__.py` and a test module which ensure the fake module was
installed.

closes odoo/odoo#66778

X-original-commit: 506755ef8ced187c0f5cd2fa600e7bb1e1fc0fe3
Related: odoo/enterprise#16653
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
---
 odoo/addons/test_data_module/__manifest__.py        |  7 +++++++
 odoo/addons/test_data_module_install/__init__.py    |  0
 .../addons/test_data_module_install/__manifest__.py |  7 +++++++
 .../test_data_module_install/tests/__init__.py      |  1 +
 .../tests/test_data_module_installed.py             | 13 +++++++++++++
 odoo/addons/test_lint/tests/test_dunderinit.py      |  4 +++-
 6 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 odoo/addons/test_data_module/__manifest__.py
 create mode 100644 odoo/addons/test_data_module_install/__init__.py
 create mode 100644 odoo/addons/test_data_module_install/__manifest__.py
 create mode 100644 odoo/addons/test_data_module_install/tests/__init__.py
 create mode 100644 odoo/addons/test_data_module_install/tests/test_data_module_installed.py

diff --git a/odoo/addons/test_data_module/__manifest__.py b/odoo/addons/test_data_module/__manifest__.py
new file mode 100644
index 000000000000..7b9f25f37f4b
--- /dev/null
+++ b/odoo/addons/test_data_module/__manifest__.py
@@ -0,0 +1,7 @@
+{
+    'name': 'test module to test data only modules',
+    'description': 'Fake module to test data module installation without __init__.py',
+    'version': '0.0.1',
+    'category': 'Hidden/Tests',
+    'sequence': 0,
+}
diff --git a/odoo/addons/test_data_module_install/__init__.py b/odoo/addons/test_data_module_install/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/odoo/addons/test_data_module_install/__manifest__.py b/odoo/addons/test_data_module_install/__manifest__.py
new file mode 100644
index 000000000000..357449a696d3
--- /dev/null
+++ b/odoo/addons/test_data_module_install/__manifest__.py
@@ -0,0 +1,7 @@
+{
+    'name': 'test installation of data module',
+    'description': 'Test data module (see test_data_module) installation',
+    'version': '0.0.1',
+    'category': 'Hidden/Tests',
+    'sequence': 10,
+}
diff --git a/odoo/addons/test_data_module_install/tests/__init__.py b/odoo/addons/test_data_module_install/tests/__init__.py
new file mode 100644
index 000000000000..0df9a0101a79
--- /dev/null
+++ b/odoo/addons/test_data_module_install/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_data_module_installed
diff --git a/odoo/addons/test_data_module_install/tests/test_data_module_installed.py b/odoo/addons/test_data_module_install/tests/test_data_module_installed.py
new file mode 100644
index 000000000000..fa65961afc33
--- /dev/null
+++ b/odoo/addons/test_data_module_install/tests/test_data_module_installed.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from odoo.tests import common
+
+
+class TestDataModuleInstalled(common.TransactionCase):
+    """ Test that the fake data module `test_data_module` is correctly installed.
+    The use case of this test is that odoo supports installation of data modules only without `__init__.py`.
+    """
+
+    def test_data_module_installed(self):
+
+        data_module = self.env['ir.module.module'].search([('name', '=', 'test_data_module')])
+        self.assertEqual(data_module.state, 'installed')
diff --git a/odoo/addons/test_lint/tests/test_dunderinit.py b/odoo/addons/test_lint/tests/test_dunderinit.py
index a074896832c5..3a209258dd0d 100644
--- a/odoo/addons/test_lint/tests/test_dunderinit.py
+++ b/odoo/addons/test_lint/tests/test_dunderinit.py
@@ -9,13 +9,15 @@ from . import lint_case
 
 _logger = logging.getLogger(__name__)
 
+# whitelist that allow data modules only
+WHITELIST = ['test_data_module', ]
 
 class TestDunderinit(lint_case.LintCase):
 
     def test_dunderinit(self):
         """ Test that __init__.py exists in Odoo modules, otherwise they won't get packaged"""
 
-        modules_list = get_modules()
+        modules_list = [mod for mod in get_modules() if mod not in WHITELIST]
         for mod in modules_list:
             dunderinit_path = Path(get_module_path(mod)) / '__init__.py'
             self.assertTrue(dunderinit_path.is_file(), "Missing `__init__.py ` in module %s" % mod)
-- 
GitLab