|
| 1 | +# Part of OpenSPP. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +"""Tests for case_demo_stories module - pure Python, no Odoo model access needed.""" |
| 4 | + |
| 5 | +from odoo.tests import TransactionCase, tagged |
| 6 | + |
| 7 | +from ..models.case_demo_stories import ( |
| 8 | + BACKGROUND_CASES, |
| 9 | + CASE_DEMO_STORIES, |
| 10 | + RESERVED_CASE_NAMES, |
| 11 | + get_all_case_stories, |
| 12 | + get_background_case_stories, |
| 13 | + get_case_story_by_id, |
| 14 | + get_main_case_stories, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +@tagged("post_install", "-at_install") |
| 19 | +class TestCaseDemoStories(TransactionCase): |
| 20 | + """Tests for the demo stories data module.""" |
| 21 | + |
| 22 | + def test_case_demo_stories_list_not_empty(self): |
| 23 | + """The main stories list should have entries.""" |
| 24 | + self.assertTrue(CASE_DEMO_STORIES, "CASE_DEMO_STORIES must not be empty") |
| 25 | + |
| 26 | + def test_background_cases_list_not_empty(self): |
| 27 | + """The background cases list should have entries.""" |
| 28 | + self.assertTrue(BACKGROUND_CASES, "BACKGROUND_CASES must not be empty") |
| 29 | + |
| 30 | + def test_reserved_case_names_not_empty(self): |
| 31 | + """Reserved names list should have entries.""" |
| 32 | + self.assertTrue(RESERVED_CASE_NAMES, "RESERVED_CASE_NAMES must not be empty") |
| 33 | + |
| 34 | + def test_each_main_story_has_required_keys(self): |
| 35 | + """Every main story must have id, case_name, case_profile, and journey.""" |
| 36 | + required_keys = {"id", "case_name", "case_profile", "journey"} |
| 37 | + for story in CASE_DEMO_STORIES: |
| 38 | + missing = required_keys - set(story.keys()) |
| 39 | + self.assertFalse( |
| 40 | + missing, |
| 41 | + f"Story '{story.get('case_name', '?')}' is missing keys: {missing}", |
| 42 | + ) |
| 43 | + |
| 44 | + def test_each_story_journey_is_list(self): |
| 45 | + """Every story's journey must be a list.""" |
| 46 | + for story in get_all_case_stories(): |
| 47 | + self.assertIsInstance( |
| 48 | + story["journey"], |
| 49 | + list, |
| 50 | + f"Journey for '{story.get('case_name', '?')}' must be a list", |
| 51 | + ) |
| 52 | + |
| 53 | + def test_each_story_case_profile_is_dict(self): |
| 54 | + """Every story's case_profile must be a dict.""" |
| 55 | + for story in get_all_case_stories(): |
| 56 | + self.assertIsInstance( |
| 57 | + story["case_profile"], |
| 58 | + dict, |
| 59 | + f"case_profile for '{story.get('case_name', '?')}' must be a dict", |
| 60 | + ) |
| 61 | + |
| 62 | + def test_story_ids_are_unique(self): |
| 63 | + """All story IDs must be unique.""" |
| 64 | + all_ids = [s["id"] for s in get_all_case_stories()] |
| 65 | + self.assertEqual( |
| 66 | + len(all_ids), |
| 67 | + len(set(all_ids)), |
| 68 | + "Duplicate story IDs detected", |
| 69 | + ) |
| 70 | + |
| 71 | + def test_get_main_case_stories_returns_main_list(self): |
| 72 | + """get_main_case_stories should return CASE_DEMO_STORIES.""" |
| 73 | + result = get_main_case_stories() |
| 74 | + self.assertEqual(result, CASE_DEMO_STORIES) |
| 75 | + |
| 76 | + def test_get_background_case_stories_returns_background_list(self): |
| 77 | + """get_background_case_stories should return BACKGROUND_CASES.""" |
| 78 | + result = get_background_case_stories() |
| 79 | + self.assertEqual(result, BACKGROUND_CASES) |
| 80 | + |
| 81 | + def test_get_all_case_stories_combines_both_lists(self): |
| 82 | + """get_all_case_stories should combine main and background stories.""" |
| 83 | + all_stories = get_all_case_stories() |
| 84 | + expected_count = len(CASE_DEMO_STORIES) + len(BACKGROUND_CASES) |
| 85 | + self.assertEqual(len(all_stories), expected_count) |
| 86 | + |
| 87 | + def test_get_all_case_stories_main_stories_first(self): |
| 88 | + """Main stories should appear before background stories in the combined list.""" |
| 89 | + all_stories = get_all_case_stories() |
| 90 | + main_count = len(CASE_DEMO_STORIES) |
| 91 | + self.assertEqual(all_stories[:main_count], CASE_DEMO_STORIES) |
| 92 | + self.assertEqual(all_stories[main_count:], BACKGROUND_CASES) |
| 93 | + |
| 94 | + def test_get_case_story_by_id_found(self): |
| 95 | + """get_case_story_by_id should return the correct story when it exists.""" |
| 96 | + # Use the first story in main stories as a known ID |
| 97 | + first_story = CASE_DEMO_STORIES[0] |
| 98 | + result = get_case_story_by_id(first_story["id"]) |
| 99 | + self.assertEqual(result, first_story) |
| 100 | + |
| 101 | + def test_get_case_story_by_id_background_story(self): |
| 102 | + """get_case_story_by_id should also find background case stories.""" |
| 103 | + first_background = BACKGROUND_CASES[0] |
| 104 | + result = get_case_story_by_id(first_background["id"]) |
| 105 | + self.assertEqual(result, first_background) |
| 106 | + |
| 107 | + def test_get_case_story_by_id_not_found_returns_none(self): |
| 108 | + """get_case_story_by_id should return None for an unknown ID.""" |
| 109 | + result = get_case_story_by_id("this_id_does_not_exist_xyz") |
| 110 | + self.assertIsNone(result) |
| 111 | + |
| 112 | + def test_santos_family_support_story_exists(self): |
| 113 | + """The Santos Family Support story must exist by its known ID.""" |
| 114 | + story = get_case_story_by_id("santos_family_support") |
| 115 | + self.assertIsNotNone(story) |
| 116 | + self.assertEqual(story["case_name"], "Santos Family Support") |
| 117 | + |
| 118 | + def test_dela_cruz_emergency_story_exists(self): |
| 119 | + """The Dela Cruz Emergency story must exist.""" |
| 120 | + story = get_case_story_by_id("dela_cruz_emergency") |
| 121 | + self.assertIsNotNone(story) |
| 122 | + |
| 123 | + def test_garcia_elder_care_story_exists(self): |
| 124 | + """The Garcia Elder Care story must exist.""" |
| 125 | + story = get_case_story_by_id("garcia_elder_care") |
| 126 | + self.assertIsNotNone(story) |
| 127 | + |
| 128 | + def test_mendoza_child_protection_story_exists(self): |
| 129 | + """The Mendoza Child Protection story must exist.""" |
| 130 | + story = get_case_story_by_id("mendoza_child_protection") |
| 131 | + self.assertIsNotNone(story) |
| 132 | + |
| 133 | + def test_hassan_resettlement_story_exists(self): |
| 134 | + """The Hassan Resettlement story must exist.""" |
| 135 | + story = get_case_story_by_id("hassan_resettlement") |
| 136 | + self.assertIsNotNone(story) |
| 137 | + |
| 138 | + def test_morales_household_crisis_story_exists(self): |
| 139 | + """The Morales Household Crisis story must exist.""" |
| 140 | + story = get_case_story_by_id("morales_household_crisis") |
| 141 | + self.assertIsNotNone(story) |
| 142 | + |
| 143 | + def test_martinez_disability_support_story_exists(self): |
| 144 | + """The Martinez Disability Support story must exist.""" |
| 145 | + story = get_case_story_by_id("martinez_disability_support") |
| 146 | + self.assertIsNotNone(story) |
| 147 | + |
| 148 | + def test_al_rahman_family_assessment_story_exists(self): |
| 149 | + """The Al-Rahman Family Assessment story must exist.""" |
| 150 | + story = get_case_story_by_id("al_rahman_family_assessment") |
| 151 | + self.assertIsNotNone(story) |
| 152 | + |
| 153 | + def test_said_family_support_story_exists(self): |
| 154 | + """The Said Family Support story must exist.""" |
| 155 | + story = get_case_story_by_id("said_family_support") |
| 156 | + self.assertIsNotNone(story) |
| 157 | + |
| 158 | + def test_story_journey_actions_are_strings(self): |
| 159 | + """Every journey step must have an action key that is a string.""" |
| 160 | + for story in get_all_case_stories(): |
| 161 | + for step in story["journey"]: |
| 162 | + self.assertIn("action", step, f"Journey step missing 'action' in story {story['id']}") |
| 163 | + self.assertIsInstance(step["action"], str) |
| 164 | + |
| 165 | + def test_story_journey_days_back_non_negative(self): |
| 166 | + """Journey steps that specify days_back must have a non-negative value.""" |
| 167 | + for story in get_all_case_stories(): |
| 168 | + for step in story["journey"]: |
| 169 | + if "days_back" in step: |
| 170 | + self.assertGreaterEqual( |
| 171 | + step["days_back"], |
| 172 | + 0, |
| 173 | + f"days_back must be >= 0 in story '{story['id']}'", |
| 174 | + ) |
| 175 | + |
| 176 | + def test_santos_story_has_close_case_action(self): |
| 177 | + """The Santos story should include a close_case journey step.""" |
| 178 | + story = get_case_story_by_id("santos_family_support") |
| 179 | + actions = [step["action"] for step in story["journey"]] |
| 180 | + self.assertIn("close_case", actions) |
| 181 | + |
| 182 | + def test_background_pending_intake_story(self): |
| 183 | + """The pending_intake background story must exist.""" |
| 184 | + story = get_case_story_by_id("pending_intake") |
| 185 | + self.assertIsNotNone(story) |
| 186 | + |
| 187 | + def test_background_assessment_phase_story(self): |
| 188 | + """The assessment_phase background story must exist.""" |
| 189 | + story = get_case_story_by_id("assessment_phase") |
| 190 | + self.assertIsNotNone(story) |
| 191 | + |
| 192 | + def test_background_closed_unsuccessful_story(self): |
| 193 | + """The closed_unsuccessful background story must exist and have a close_case step.""" |
| 194 | + story = get_case_story_by_id("closed_unsuccessful") |
| 195 | + self.assertIsNotNone(story) |
| 196 | + actions = [step["action"] for step in story["journey"]] |
| 197 | + self.assertIn("close_case", actions) |
0 commit comments