Skip to content

test: add tests/ folders to 5 modules missing CI coverage (#1040)#218

Open
emjay0921 wants to merge 3 commits into
19.0from
fix/1040-add-missing-tests
Open

test: add tests/ folders to 5 modules missing CI coverage (#1040)#218
emjay0921 wants to merge 3 commits into
19.0from
fix/1040-add-missing-tests

Conversation

@emjay0921
Copy link
Copy Markdown
Contributor

@emjay0921 emjay0921 commented May 28, 2026

Summary

4 OpenSPP2 modules shipped without a tests/ folder, so CI's detect-changes coverage matrix had no flags to upload against them. This wires up at minimum one passing test per module so the matrix can start reporting coverage.

Module Test type Test count
spp_drims_sl Data-only sanity (SL locale) 3
spp_hide_menus_base Model behaviour (hide / show round-trip + catalog well-formed) 6
spp_indicator_studio UI-bridge sanity (views + act_window) 4
spp_starter_farmer_registry Bundle sanity (every declared dep installed) 3

Out of scope per the ticket:

  • spp_registry — handled on a separate branch.
  • theme_openspp_muk — theme module, no Python logic.

Pulled out of this PR for a follow-up:

  • spp_farmer_registry_dashboard — depends on spp_dashboard_base, which still lives in the private openspp-modules-v2 repo and isn't mounted in the OpenSPP2 CI runner, so the module can't install in CI. The test scaffolding can land in a follow-up once spp_dashboard_base is migrated to OpenSPP2 (or CI is updated to pull the private repo).

Test plan

Locally verified the two modules whose dependency graph fits entirely inside OpenSPP2:

  • spp_drims_sl0 failed, 0 error(s) of 3 tests
  • spp_hide_menus_base0 failed, 0 error(s) of 6 tests

The other two (spp_indicator_studio, spp_starter_farmer_registry) hit a pre-existing read_group issue in spp_hazard during local install — CI doesn't trigger that path. Already passing on the previous CI run for both:

  • spp_indicator_studio reports tests in CI
  • spp_starter_farmer_registry reports tests in CI

Codecov:

  • Codecov shows a new flag/upload for each of the 4 modules after merge — verify in the codecov dashboard.

Related links

  • OP#1040

Five OpenSPP2 modules shipped without a tests/ folder, so CI's
detect-changes coverage matrix had no flags to upload against them. This
patch wires up at minimum one passing test per module so the matrix can
start reporting coverage.

- spp_drims_sl (data-only, SL locale): install + key hazard category +
  LKR currency activation.
- spp_farmer_registry_dashboard (data-only, dashboard records): install
  + farmer dashboard category / group / overview records loaded.
- spp_hide_menus_base (models): install + group_hide_menus_user seed +
  hide_menu/show_menu round-trip + idempotency + MENU_APP catalog
  well-formed.
- spp_indicator_studio (UI bridge): install + indicator views + indicator
  category views + act_window points at spp.indicator.
- spp_starter_farmer_registry (bundle): install + every declared
  dependency installed + config_smallholder_threshold seed loaded.

Locally verified: spp_drims_sl reports 3/3 tests, spp_hide_menus_base
reports 6/6. The other three fail to install in the local Docker setup
only because they depend on modules outside OpenSPP2 (spp_dashboard_base
lives in the private openspp-modules-v2 repo) — CI mounts both repos so
those will install + run there.

Out of scope per the ticket:
- spp_registry — handled on a separate branch.
- theme_openspp_muk — theme module, no Python logic to cover.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive unit tests and sanity checks across several OpenSPP Odoo modules, including spp_drims_sl, spp_farmer_registry_dashboard, spp_hide_menus_base, spp_indicator_studio, and spp_starter_farmer_registry. These tests verify successful module installation, seed data loading, and menu visibility transitions. The review feedback suggests improving test isolation in spp_hide_menus_base by creating a dedicated dummy menu instead of querying an arbitrary existing one, and removing redundant browse calls on already available recordsets.

Comment on lines +22 to +25
# Pick any existing menu we can safely toggle in a test transaction.
cls.menu = cls.env["ir.ui.menu"].search([], limit=1)
if not cls.menu:
raise AssertionError("No ir.ui.menu records found to test against")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Searching for an arbitrary existing menu in the database can lead to flaky tests or unexpected failures if the selected menu already has restricted groups or other custom configurations. Creating a dedicated dummy menu for the test class ensures complete isolation and deterministic test behavior.

Suggested change
# Pick any existing menu we can safely toggle in a test transaction.
cls.menu = cls.env["ir.ui.menu"].search([], limit=1)
if not cls.menu:
raise AssertionError("No ir.ui.menu records found to test against")
# Create a dummy menu to safely toggle in tests without relying on existing database records.
cls.menu = cls.env["ir.ui.menu"].create({"name": "Test Menu"})


def test_hide_menu_transition(self):
"""hide_menu() flips state show → hide and snapshots original groups."""
original_groups = self.env["ir.ui.menu"].browse(self.menu.id).group_ids
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since self.menu is already an ir.ui.menu recordset, calling self.env["ir.ui.menu"].browse(self.menu.id) is redundant. You can access group_ids directly from self.menu.

Suggested change
original_groups = self.env["ir.ui.menu"].browse(self.menu.id).group_ids
original_groups = self.menu.group_ids


def test_show_menu_restores_original_groups(self):
"""show_menu() restores the snapshot taken at hide time."""
original_groups = self.env["ir.ui.menu"].browse(self.menu.id).group_ids
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, calling self.env["ir.ui.menu"].browse(self.menu.id) here is redundant. You can access group_ids directly from self.menu.

Suggested change
original_groups = self.env["ir.ui.menu"].browse(self.menu.id).group_ids
original_groups = self.menu.group_ids

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.50%. Comparing base (5900a2e) to head (ce53fd4).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #218      +/-   ##
==========================================
+ Coverage   71.49%   71.50%   +0.01%     
==========================================
  Files         993     1002       +9     
  Lines       58564    58627      +63     
==========================================
+ Hits        41869    41921      +52     
- Misses      16695    16706      +11     
Flag Coverage Δ
spp_analytics 93.13% <ø> (ø)
spp_api_v2 80.33% <ø> (ø)
spp_api_v2_change_request 66.85% <ø> (ø)
spp_api_v2_cycles 71.12% <ø> (ø)
spp_api_v2_data 64.41% <ø> (ø)
spp_api_v2_entitlements 70.19% <ø> (ø)
spp_api_v2_gis 71.52% <ø> (ø)
spp_approval 50.29% <ø> (ø)
spp_area 80.07% <ø> (ø)
spp_area_hdx 81.43% <ø> (ø)
spp_audit 72.60% <ø> (ø)
spp_base_common 90.26% <ø> (ø)
spp_case_cel 89.01% <ø> (ø)
spp_drims_sl 0.00% <ø> (?)
spp_hide_menus_base 88.13% <ø> (?)
spp_indicator_studio 0.00% <ø> (?)
spp_programs 64.84% <ø> (ø)
spp_registry 86.83% <ø> (ø)
spp_security 66.66% <ø> (ø)
spp_starter_farmer_registry 0.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

emjay0921 added 2 commits May 28, 2026 09:40
…g spp_dashboard_base in OpenSPP2

The dashboard module depends on spp_dashboard_base, which still lives in
the private openspp-modules-v2 repo and isn't mounted in the OpenSPP2 CI
runner. So 'odoo -i spp_farmer_registry_dashboard' fails in CI with
"depends on module spp_dashboard_base. But the latter module is not
available".

Pulling the test scaffolding out of this PR so the rest of the OP#1040
tests can merge cleanly. spp_farmer_registry_dashboard tests can land in
a follow-up once spp_dashboard_base is migrated to OpenSPP2 (or CI is
updated to pull the private repo).
…walk

Adds three more tests so the post-install hook on ir.module.module is
exercised:

- test_hide_menus_processes_catalog asserts the method walks MENU_APP and
  creates a state=hide spp.hide.menu record for every entry whose menu
  xml_id resolves in the test DB.
- test_hide_menus_is_idempotent runs the method twice and asserts no
  duplicates / no state churn.
- test_hide_menus_skips_unknown_modules confirms modules absent from
  MENU_APP (e.g. base) are left alone.

Bumps the module's branch coverage from ~64% to >90%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant