1717 has_key ,
1818)
1919
20- from eligibility_signposting_api .model .campaign_config import CampaignConfig , RuleComparator
20+ from eligibility_signposting_api .model .campaign_config import (
21+ CampaignConfig ,
22+ RuleAttributeLevel ,
23+ RuleComparator ,
24+ RuleOperator ,
25+ RuleType ,
26+ )
2127from eligibility_signposting_api .model .consumer_mapping import ConsumerId , ConsumerMapping
2228from eligibility_signposting_api .model .eligibility_status import (
2329 NHSNumber ,
@@ -1273,35 +1279,59 @@ def test_if_correct_campaign_is_chosen_for_the_consumer_when_multiple_campaign_e
12731279 assert_that (len (audit_data ["response" ]["condition" ]), equal_to (0 ))
12741280
12751281 @pytest .mark .parametrize (
1276- ("campaign_1_start_date" , "campaign_2_start_date" , "postcode_for_comparator" , "expected_campaign_id" ),
1282+ (
1283+ "campaign_1_start_date" ,
1284+ "campaign_2_start_date" ,
1285+ "postcode_for_comparator" ,
1286+ "cohort_for_comparator" ,
1287+ "expected_campaign_id" ,
1288+ ),
12771289 [
12781290 (
12791291 ("RSV_campaign_id_1" , today ()),
12801292 ("RSV_campaign_id_2" , today () - timedelta (days = 1 )),
1281- "SW19" , # postcode for resulting in not-actionable
1293+ "SW19" , # postcode for resulting in not-actionable (used by the suppression rule)
1294+ "cohort2" ,
12821295 "RSV_campaign_id_1" ,
12831296 ),
12841297 (
12851298 ("RSV_campaign_id_1" , today () - timedelta (days = 1 )),
12861299 ("RSV_campaign_id_2" , today ()),
12871300 "SW19" , # postcode for resulting in not-actionable
1301+ "cohort2" ,
12881302 "RSV_campaign_id_2" ,
12891303 ),
12901304 (
12911305 ("RSV_campaign_id_1" , today ()),
12921306 ("RSV_campaign_id_2" , today () - timedelta (days = 1 )),
12931307 "M4" , # postcode for resulting in actionable
1308+ "cohort2" ,
12941309 "RSV_campaign_id_1" ,
12951310 ),
12961311 (
12971312 ("RSV_campaign_id_1" , today () - timedelta (days = 1 )),
12981313 ("RSV_campaign_id_2" , today ()),
12991314 "M4" , # postcode for resulting in actionable
1315+ "cohort2" ,
1316+ "RSV_campaign_id_2" ,
1317+ ),
1318+ (
1319+ ("RSV_campaign_id_1" , today ()),
1320+ ("RSV_campaign_id_2" , today () - timedelta (days = 1 )),
1321+ "M4" , # cohort for resulting in not-eligible
1322+ "cohort1" ,
1323+ "RSV_campaign_id_1" ,
1324+ ),
1325+ (
1326+ ("RSV_campaign_id_1" , today () - timedelta (days = 1 )),
1327+ ("RSV_campaign_id_2" , today ()),
1328+ "M4" ,
1329+ "cohort1" , # cohort for resulting in not-eligible (used by the filter rule)
13001330 "RSV_campaign_id_2" ,
13011331 ),
13021332 ],
13031333 )
1304- def test_if_cc_with_latest_active_iteration_is_chosen_if_exists_multiple_campaign_with_diff_iteration_date ( # noqa : PLR0913
1334+ def test_if_cc_with_latest_active_iteration_is_chosen_if_exists_multiple_campaign_with_diff_iteration_date ( # noqa: PLR0913
13051335 self ,
13061336 client : FlaskClient ,
13071337 persisted_person_pc_sw19 : NHSNumber ,
@@ -1313,6 +1343,7 @@ def test_if_cc_with_latest_active_iteration_is_chosen_if_exists_multiple_campaig
13131343 campaign_1_start_date : tuple [str , date ],
13141344 campaign_2_start_date : tuple [str , date ],
13151345 postcode_for_comparator : str ,
1346+ cohort_for_comparator : str ,
13161347 expected_campaign_id : NHSNumber ,
13171348 ):
13181349 # Given
@@ -1344,6 +1375,13 @@ def test_if_cc_with_latest_active_iteration_is_chosen_if_exists_multiple_campaig
13441375 rule .IterationFactory .build (
13451376 iteration_date = campaign_1_start_date [1 ],
13461377 iteration_rules = [
1378+ rule .IterationRuleFactory .build (
1379+ type = RuleType .filter ,
1380+ name = "Exclude if cohort matches" ,
1381+ attribute_level = RuleAttributeLevel .COHORT ,
1382+ comparator = RuleComparator (cohort_for_comparator ),
1383+ operator = RuleOperator .member_of ,
1384+ ),
13471385 rule .PostcodeSuppressionRuleFactory .build (
13481386 name = "Exclude M4" , comparator = RuleComparator (postcode_for_comparator )
13491387 ),
0 commit comments