Skip to content

Commit f085daf

Browse files
committed
[FIX] vcp_odoo: adapt function
1 parent 5d1f542 commit f085daf

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

vcp_management/tests/test_vcp_rule.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,67 @@ def test_process_rules_update(self):
176176
self.assertEqual(rule_info.documentation_count, 1)
177177
self.assertEqual(rule_info.empty_count, 3)
178178
self.assertEqual(rule_info.total_count, 6)
179+
180+
def test_process_rules_only_one_cloc_execution(self):
181+
rule = self.env["vcp.rule"].create(
182+
{
183+
"name": "Test Rule with cloc response",
184+
"rule_type": "cloc",
185+
"paths": "*.js",
186+
}
187+
)
188+
self.rule.paths = "*.py"
189+
self.platform.rule_ids = rule | self.rule
190+
self.assertFalse(os.path.exists(self.repository_branch.local_path))
191+
self.assertFalse(self.repository_branch.rule_information_ids)
192+
with (
193+
patch(
194+
"odoo.addons.vcp_management.models.vcp_repository_branch.VcpRepositoryBranch._download_code_dummy",
195+
_download_code_dummy,
196+
create=True,
197+
),
198+
patch(
199+
"odoo.addons.vcp_management.models.vcp_rule.VcpRule._call_cloc_command"
200+
) as mock_cloc,
201+
):
202+
mock_cloc.return_value = {
203+
f"{self.repository_branch.local_path}/demofile.py": {
204+
"code": 2,
205+
"comment": 1,
206+
"empty": 2,
207+
"total": 6,
208+
"blank": 0,
209+
},
210+
f"{self.repository_branch.local_path}/demofile.js": {
211+
"code": 1,
212+
"comment": 0,
213+
"empty": 0,
214+
"total": 1,
215+
"blank": 0,
216+
},
217+
}
218+
os.makedirs(self.repository_branch.local_path, exist_ok=True)
219+
with open(f"{self.repository_branch.local_path}/demofile.py", "w") as f:
220+
f.write("""
221+
# This is a comment
222+
print('Hello World')
223+
print('Hello World')
224+
""")
225+
with open(f"{self.repository_branch.local_path}/demofile.js", "w") as f:
226+
f.write("console.log('Hello World');")
227+
self.repository_branch.process_rules()
228+
mock_cloc.assert_called_once()
229+
self.repository_branch.invalidate_recordset()
230+
self.assertEqual(2, len(self.repository_branch.rule_information_ids))
231+
self.assertEqual(
232+
1,
233+
self.repository_branch.rule_information_ids.filtered(
234+
lambda x: x.rule_id == rule
235+
).code_count,
236+
)
237+
self.assertEqual(
238+
2,
239+
self.repository_branch.rule_information_ids.filtered(
240+
lambda x: x.rule_id == self.rule
241+
).code_count,
242+
)

vcp_odoo/models/vcp_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class VcpRule(models.Model):
2828
"odoo_module_rule_id",
2929
)
3030

31-
def _process_rule_odoo_module(self, record):
31+
def _process_rule_odoo_module(self, record, parameters=None):
3232
"""
3333
Process the rule as an Odoo module analysis.
3434
"""

0 commit comments

Comments
 (0)