|
5 | 5 | from faker import Faker |
6 | 6 | from flask import Flask |
7 | 7 | from freezegun import freeze_time |
8 | | -from hamcrest import assert_that, contains_exactly, contains_inanyorder, equal_to, has_item, has_items, is_, is_in |
| 8 | +from hamcrest import assert_that, contains_exactly, contains_inanyorder, has_item, has_items, is_, is_in |
9 | 9 | from pydantic import HttpUrl |
10 | 10 |
|
11 | 11 | from eligibility_signposting_api.model import campaign_config as rules_model |
|
14 | 14 | AvailableAction, |
15 | 15 | CohortLabel, |
16 | 16 | Description, |
17 | | - IterationCohort, |
18 | 17 | RuleAttributeLevel, |
19 | 18 | RuleAttributeName, |
20 | 19 | RuleAttributeTarget, |
|
39 | 38 | RulePriority, |
40 | 39 | Status, |
41 | 40 | SuggestedAction, |
42 | | - UrlLabel, |
43 | | - UrlLink, |
44 | 41 | ) |
45 | 42 | from eligibility_signposting_api.services.calculators.eligibility_calculator import EligibilityCalculator |
46 | 43 | from tests.fixtures.builders.model import rule as rule_builder |
|
49 | 46 | is_cohort_result, |
50 | 47 | is_condition, |
51 | 48 | is_eligibility_status, |
52 | | - is_reason, |
53 | 49 | ) |
54 | 50 |
|
55 | 51 |
|
@@ -104,55 +100,6 @@ def test_base_eligible_with_when_magic_cohort_is_present( |
104 | 100 | ) |
105 | 101 |
|
106 | 102 |
|
107 | | -@freeze_time("2025-04-25") |
108 | | -def test_only_live_campaigns_considered(faker: Faker): |
109 | | - # Given |
110 | | - nhs_number = NHSNumber(faker.nhs_number()) |
111 | | - |
112 | | - person_rows = person_rows_builder(nhs_number, cohorts=["cohort1"]) |
113 | | - campaign_configs = [ |
114 | | - rule_builder.CampaignConfigFactory.build( |
115 | | - name="Live", |
116 | | - target="RSV", |
117 | | - iterations=[ |
118 | | - rule_builder.IterationFactory.build( |
119 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort2")], |
120 | | - iteration_rules=[], |
121 | | - ) |
122 | | - ], |
123 | | - start_date=datetime.date(2025, 4, 20), |
124 | | - end_date=datetime.date(2025, 4, 30), |
125 | | - ), |
126 | | - rule_builder.CampaignConfigFactory.build( |
127 | | - name="No longer live", |
128 | | - target="RSV", |
129 | | - iterations=[ |
130 | | - rule_builder.IterationFactory.build( |
131 | | - iteration_cohorts=[ |
132 | | - rule_builder.IterationCohortFactory.build(cohort_label="cohort1"), |
133 | | - rule_builder.IterationCohortFactory.build(cohort_label="cohort2"), |
134 | | - ], |
135 | | - ) |
136 | | - ], |
137 | | - start_date=datetime.date(2025, 4, 1), |
138 | | - end_date=datetime.date(2025, 4, 24), |
139 | | - ), |
140 | | - ] |
141 | | - |
142 | | - calculator = EligibilityCalculator(person_rows, campaign_configs) |
143 | | - |
144 | | - # When |
145 | | - actual = calculator.get_eligibility_status("Y", ["ALL"], "ALL") |
146 | | - |
147 | | - # Then |
148 | | - assert_that( |
149 | | - actual, |
150 | | - is_eligibility_status().with_conditions( |
151 | | - has_item(is_condition().with_condition_name(ConditionName("RSV")).and_status(Status.not_eligible)) |
152 | | - ), |
153 | | - ) |
154 | | - |
155 | | - |
156 | 103 | @pytest.mark.parametrize( |
157 | 104 | "iteration_type", |
158 | 105 | ["A", "M", "S", "O"], |
@@ -319,161 +266,6 @@ def test_rules_with_same_priority_must_all_match_to_exclude( |
319 | 266 | ) |
320 | 267 |
|
321 | 268 |
|
322 | | -def test_multiple_conditions_where_both_are_actionable(faker: Faker): |
323 | | - # Given |
324 | | - nhs_number = NHSNumber(faker.nhs_number()) |
325 | | - date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=76, maximum_age=78)) |
326 | | - |
327 | | - person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=["cohort1"], icb="QE1") |
328 | | - campaign_configs = [ |
329 | | - rule_builder.CampaignConfigFactory.build( |
330 | | - target="RSV", |
331 | | - iterations=[ |
332 | | - rule_builder.IterationFactory.build( |
333 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
334 | | - iteration_rules=[rule_builder.PersonAgeSuppressionRuleFactory.build()], |
335 | | - default_comms_routing="defaultcomms", |
336 | | - actions_mapper=rule_builder.ActionsMapperFactory.build( |
337 | | - root={"rule_1_comms_routing": book_nbs_comms, "defaultcomms": default_comms_detail} |
338 | | - ), |
339 | | - ) |
340 | | - ], |
341 | | - ), |
342 | | - rule_builder.CampaignConfigFactory.build( |
343 | | - target="COVID", |
344 | | - iterations=[ |
345 | | - rule_builder.IterationFactory.build( |
346 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
347 | | - iteration_rules=[ |
348 | | - rule_builder.PersonAgeSuppressionRuleFactory.build(), |
349 | | - rule_builder.ICBRedirectRuleFactory.build(), |
350 | | - ], |
351 | | - default_comms_routing="defaultcomms", |
352 | | - actions_mapper=rule_builder.ActionsMapperFactory.build( |
353 | | - root={"ActionCode1": book_nbs_comms, "defaultcomms": default_comms_detail} |
354 | | - ), |
355 | | - ) |
356 | | - ], |
357 | | - ), |
358 | | - ] |
359 | | - |
360 | | - calculator = EligibilityCalculator(person_rows, campaign_configs) |
361 | | - |
362 | | - # When |
363 | | - actual = calculator.get_eligibility_status("Y", ["ALL"], "ALL") |
364 | | - |
365 | | - # Then |
366 | | - assert_that( |
367 | | - actual, |
368 | | - is_eligibility_status().with_conditions( |
369 | | - has_items( |
370 | | - is_condition() |
371 | | - .with_condition_name(ConditionName("RSV")) |
372 | | - .and_status(Status.actionable) |
373 | | - .and_actions( |
374 | | - [ |
375 | | - SuggestedAction( |
376 | | - internal_action_code=InternalActionCode("defaultcomms"), |
377 | | - action_type=ActionType("CareCardWithText"), |
378 | | - action_code=ActionCode("BookLocal"), |
379 | | - action_description=ActionDescription("You can get an RSV vaccination at your GP surgery"), |
380 | | - url_link=None, |
381 | | - url_label=None, |
382 | | - ) |
383 | | - ] |
384 | | - ), |
385 | | - is_condition() |
386 | | - .with_condition_name(ConditionName("COVID")) |
387 | | - .and_status(Status.actionable) |
388 | | - .and_actions( |
389 | | - [ |
390 | | - SuggestedAction( |
391 | | - internal_action_code=InternalActionCode("ActionCode1"), |
392 | | - action_type=ActionType("ButtonAuthLink"), |
393 | | - action_code=ActionCode("BookNBS"), |
394 | | - action_description=ActionDescription("Action description"), |
395 | | - url_link=UrlLink(HttpUrl("https://www.nhs.uk/book-rsv")), |
396 | | - url_label=UrlLabel("Continue to booking"), |
397 | | - ) |
398 | | - ] |
399 | | - ), |
400 | | - ) |
401 | | - ), |
402 | | - ) |
403 | | - |
404 | | - |
405 | | -@pytest.mark.parametrize( |
406 | | - ("test_comment", "campaign1", "campaign2"), |
407 | | - [ |
408 | | - ( |
409 | | - "1st campaign allows, 2nd excludes", |
410 | | - rule_builder.CampaignConfigFactory.build( |
411 | | - target="RSV", |
412 | | - iterations=[ |
413 | | - rule_builder.IterationFactory.build( |
414 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
415 | | - iteration_rules=[rule_builder.PersonAgeSuppressionRuleFactory.build()], |
416 | | - ) |
417 | | - ], |
418 | | - ), |
419 | | - rule_builder.CampaignConfigFactory.build( |
420 | | - target="RSV", |
421 | | - iterations=[ |
422 | | - rule_builder.IterationFactory.build( |
423 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
424 | | - iteration_rules=[rule_builder.PersonAgeSuppressionRuleFactory.build(comparator="-85")], |
425 | | - ) |
426 | | - ], |
427 | | - ), |
428 | | - ), |
429 | | - ( |
430 | | - "1st campaign excludes, 2nd allows", |
431 | | - rule_builder.CampaignConfigFactory.build( |
432 | | - target="RSV", |
433 | | - iterations=[ |
434 | | - rule_builder.IterationFactory.build( |
435 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
436 | | - iteration_rules=[rule_builder.PersonAgeSuppressionRuleFactory.build(comparator="-85")], |
437 | | - ) |
438 | | - ], |
439 | | - ), |
440 | | - rule_builder.CampaignConfigFactory.build( |
441 | | - target="RSV", |
442 | | - iterations=[ |
443 | | - rule_builder.IterationFactory.build( |
444 | | - iteration_cohorts=[rule_builder.IterationCohortFactory.build(cohort_label="cohort1")], |
445 | | - iteration_rules=[rule_builder.PersonAgeSuppressionRuleFactory.build()], |
446 | | - ) |
447 | | - ], |
448 | | - ), |
449 | | - ), |
450 | | - ], |
451 | | -) |
452 | | -def test_multiple_campaigns_for_single_condition( |
453 | | - test_comment: str, campaign1: rules_model.CampaignConfig, campaign2: rules_model.CampaignConfig, faker: Faker |
454 | | -): |
455 | | - # Given |
456 | | - nhs_number = NHSNumber(faker.nhs_number()) |
457 | | - date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=76, maximum_age=78)) |
458 | | - |
459 | | - person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=["cohort1"]) |
460 | | - campaign_configs = [campaign1, campaign2] |
461 | | - |
462 | | - calculator = EligibilityCalculator(person_rows, campaign_configs) |
463 | | - |
464 | | - # When |
465 | | - actual = calculator.get_eligibility_status("Y", ["ALL"], "ALL") |
466 | | - |
467 | | - # Then |
468 | | - assert_that( |
469 | | - actual, |
470 | | - is_eligibility_status().with_conditions( |
471 | | - contains_exactly(is_condition().with_condition_name(ConditionName("RSV")).and_status(Status.actionable)) |
472 | | - ), |
473 | | - test_comment, |
474 | | - ) |
475 | | - |
476 | | - |
477 | 269 | @pytest.mark.parametrize( |
478 | 270 | ("vaccine", "last_successful_date", "expected_status", "test_comment"), |
479 | 271 | [ |
@@ -718,7 +510,6 @@ def test_cohort_groups_and_their_descriptions_when_magic_cohort_is_present( |
718 | 510 | ) |
719 | 511 |
|
720 | 512 |
|
721 | | - |
722 | 513 | @pytest.mark.parametrize( |
723 | 514 | ("person_rows", "expected_description", "test_comment"), |
724 | 515 | [ |
@@ -794,8 +585,6 @@ def test_cohort_group_descriptions_are_selected_based_on_priority_when_cohorts_h |
794 | 585 | ) |
795 | 586 |
|
796 | 587 |
|
797 | | - |
798 | | - |
799 | 588 | book_nbs_comms = AvailableAction( |
800 | 589 | ActionType="ButtonAuthLink", |
801 | 590 | ExternalRoutingCode="BookNBS", |
|
0 commit comments