|
| 1 | +# Part of OpenSPP. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +""" |
| 4 | +Tests for spp_cel_registry_search module. |
| 5 | +
|
| 6 | +Validates: |
| 7 | +- Module installation |
| 8 | +- Security group hierarchy and implied permissions |
| 9 | +- Client action configuration |
| 10 | +- Menu item configuration and visibility by role |
| 11 | +""" |
| 12 | + |
| 13 | +from odoo import Command |
| 14 | +from odoo.tests import TransactionCase, tagged |
| 15 | + |
| 16 | + |
| 17 | +@tagged("post_install", "-at_install") |
| 18 | +class TestCelRegistrySearch(TransactionCase): |
| 19 | + """Test security groups, client action, and menu for CEL Registry Search.""" |
| 20 | + |
| 21 | + @classmethod |
| 22 | + def setUpClass(cls): |
| 23 | + super().setUpClass() |
| 24 | + |
| 25 | + # Security groups |
| 26 | + cls.group_cel_search_user = cls.env.ref("spp_cel_registry_search.group_cel_search_user") |
| 27 | + cls.group_registry_viewer = cls.env.ref("spp_registry.group_registry_viewer") |
| 28 | + cls.group_registry_officer = cls.env.ref("spp_registry.group_registry_officer") |
| 29 | + |
| 30 | + # Client action |
| 31 | + cls.action = cls.env.ref("spp_cel_registry_search.action_cel_search_portal") |
| 32 | + |
| 33 | + # Menu item |
| 34 | + cls.menu = cls.env.ref("spp_cel_registry_search.menu_cel_search_portal") |
| 35 | + |
| 36 | + # --- Security Group Tests --- |
| 37 | + |
| 38 | + def test_group_cel_search_user_exists(self): |
| 39 | + """group_cel_search_user should exist after installation.""" |
| 40 | + self.assertTrue(self.group_cel_search_user) |
| 41 | + self.assertEqual(self.group_cel_search_user.name, "CEL Search User") |
| 42 | + |
| 43 | + def test_group_cel_search_user_implies_registry_viewer(self): |
| 44 | + """group_cel_search_user should imply group_registry_viewer.""" |
| 45 | + implied_ids = self.group_cel_search_user.implied_ids.ids |
| 46 | + self.assertIn( |
| 47 | + self.group_registry_viewer.id, |
| 48 | + implied_ids, |
| 49 | + "group_cel_search_user should imply group_registry_viewer", |
| 50 | + ) |
| 51 | + |
| 52 | + def test_registry_officer_implies_cel_search_user(self): |
| 53 | + """group_registry_officer should imply group_cel_search_user.""" |
| 54 | + implied_ids = self.group_registry_officer.implied_ids.ids |
| 55 | + self.assertIn( |
| 56 | + self.group_cel_search_user.id, |
| 57 | + implied_ids, |
| 58 | + "group_registry_officer should imply group_cel_search_user", |
| 59 | + ) |
| 60 | + |
| 61 | + # --- Client Action Tests --- |
| 62 | + |
| 63 | + def test_client_action_exists(self): |
| 64 | + """Client action for CEL Search Portal should exist.""" |
| 65 | + self.assertTrue(self.action) |
| 66 | + self.assertEqual(self.action.name, "Advanced Search") |
| 67 | + |
| 68 | + def test_client_action_tag(self): |
| 69 | + """Client action should have the correct tag matching the JS component.""" |
| 70 | + self.assertEqual(self.action.tag, "spp_cel_registry_search.cel_search_portal") |
| 71 | + |
| 72 | + def test_client_action_path(self): |
| 73 | + """Client action should have the correct pretty URL path.""" |
| 74 | + self.assertEqual(self.action.path, "registry-cel") |
| 75 | + |
| 76 | + # --- Menu Item Tests --- |
| 77 | + |
| 78 | + def test_menu_exists(self): |
| 79 | + """Menu item for CEL Search Portal should exist.""" |
| 80 | + self.assertTrue(self.menu) |
| 81 | + self.assertEqual(self.menu.name, "Advanced Search") |
| 82 | + |
| 83 | + def test_menu_parent(self): |
| 84 | + """Menu should be parented under the registry root menu.""" |
| 85 | + registry_root = self.env.ref("spp_registry.spp_main_menu_root") |
| 86 | + self.assertEqual( |
| 87 | + self.menu.parent_id.id, |
| 88 | + registry_root.id, |
| 89 | + "Menu should be under Registry root menu", |
| 90 | + ) |
| 91 | + |
| 92 | + def test_menu_restricted_to_cel_search_group(self): |
| 93 | + """Menu should be restricted to group_cel_search_user.""" |
| 94 | + self.assertIn( |
| 95 | + self.group_cel_search_user, |
| 96 | + self.menu.group_ids, |
| 97 | + "Menu should be restricted to group_cel_search_user", |
| 98 | + ) |
| 99 | + |
| 100 | + # --- Menu Visibility by Role --- |
| 101 | + |
| 102 | + def test_menu_visible_to_cel_search_user(self): |
| 103 | + """A user with group_cel_search_user should see the menu.""" |
| 104 | + user = self.env["res.users"].create( |
| 105 | + { |
| 106 | + "name": "Test CEL Search User", |
| 107 | + "login": "test_cel_search_user", |
| 108 | + "group_ids": [ |
| 109 | + Command.link(self.env.ref("base.group_user").id), |
| 110 | + Command.link(self.group_cel_search_user.id), |
| 111 | + ], |
| 112 | + } |
| 113 | + ) |
| 114 | + visible_menus = self.env["ir.ui.menu"].with_user(user).search([]) |
| 115 | + self.assertIn( |
| 116 | + self.menu, |
| 117 | + visible_menus, |
| 118 | + "Menu should be visible to CEL Search users", |
| 119 | + ) |
| 120 | + |
| 121 | + def test_menu_visible_to_registry_officer(self): |
| 122 | + """A registry officer should see the menu via implied group.""" |
| 123 | + user = self.env["res.users"].create( |
| 124 | + { |
| 125 | + "name": "Test Registry Officer", |
| 126 | + "login": "test_registry_officer_cel", |
| 127 | + "group_ids": [ |
| 128 | + Command.link(self.env.ref("base.group_user").id), |
| 129 | + Command.link(self.group_registry_officer.id), |
| 130 | + ], |
| 131 | + } |
| 132 | + ) |
| 133 | + # Verify the officer has the CEL search group via implication |
| 134 | + self.assertTrue( |
| 135 | + user.has_group("spp_cel_registry_search.group_cel_search_user"), |
| 136 | + "Registry officer should have CEL Search group via implication", |
| 137 | + ) |
| 138 | + visible_menus = self.env["ir.ui.menu"].with_user(user).search([]) |
| 139 | + self.assertIn( |
| 140 | + self.menu, |
| 141 | + visible_menus, |
| 142 | + "Menu should be visible to registry officers", |
| 143 | + ) |
| 144 | + |
| 145 | + def test_base_user_does_not_have_cel_search_group(self): |
| 146 | + """A base user without explicit assignment should not have the CEL Search group.""" |
| 147 | + user = self.env["res.users"].create( |
| 148 | + { |
| 149 | + "name": "Test Base User", |
| 150 | + "login": "test_base_user_cel", |
| 151 | + "group_ids": [ |
| 152 | + Command.link(self.env.ref("base.group_user").id), |
| 153 | + ], |
| 154 | + } |
| 155 | + ) |
| 156 | + self.assertFalse( |
| 157 | + user.has_group("spp_cel_registry_search.group_cel_search_user"), |
| 158 | + "Base user should not have CEL Search group", |
| 159 | + ) |
0 commit comments