@@ -700,7 +700,7 @@ def firehose_delivery_stream(firehose_client: BaseClient, audit_bucket: BucketNa
700700
701701
702702@pytest .fixture (scope = "class" )
703- def campaign_config (s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [CampaignConfig ]:
703+ def rsv_campaign_config (s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [CampaignConfig ]:
704704 campaign : CampaignConfig = rule .CampaignConfigFactory .build (
705705 target = "RSV" ,
706706 iterations = [
@@ -729,45 +729,6 @@ def campaign_config(s3_client: BaseClient, rules_bucket: BucketName) -> Generato
729729 s3_client .delete_object (Bucket = rules_bucket , Key = f"{ campaign .name } .json" )
730730
731731
732- @pytest .fixture (scope = "class" )
733- def consumer_mapping (s3_client : BaseClient , consumer_mapping_bucket : BucketName ) -> Generator [ConsumerMapping ]:
734- consumer_mapping = ConsumerMapping .model_validate ({})
735- consumer_mapping .root [ConsumerId ("23-mic7heal-jor6don" )] = [CampaignID ("42-hi5tch-hi5kers-gu5ide-t2o-t3he-gal6axy" )]
736-
737- consumer_mapping_data = consumer_mapping .model_dump (by_alias = True )
738- s3_client .put_object (
739- Bucket = consumer_mapping_bucket ,
740- Key = "consumer_mapping.json" ,
741- Body = json .dumps (consumer_mapping_data ),
742- ContentType = "application/json" ,
743- )
744- yield consumer_mapping
745- s3_client .delete_object (Bucket = consumer_mapping_bucket , Key = "consumer_mapping.json" )
746-
747-
748- @pytest .fixture (scope = "class" )
749- def consumer_mapping_with_various_targets (
750- s3_client : BaseClient , consumer_mapping_bucket : BucketName
751- ) -> Generator [ConsumerMapping ]:
752- consumer_mapping = ConsumerMapping .model_validate ({})
753- consumer_mapping .root [ConsumerId ("23-mic7heal-jor6don" )] = [
754- CampaignID ("campaign_start_date" ),
755- CampaignID ("campaign_start_date_plus_one_day" ),
756- CampaignID ("campaign_today" ),
757- CampaignID ("campaign_tomorrow" ),
758- ]
759-
760- consumer_mapping_data = consumer_mapping .model_dump (by_alias = True )
761- s3_client .put_object (
762- Bucket = consumer_mapping_bucket ,
763- Key = "consumer_mapping.json" ,
764- Body = json .dumps (consumer_mapping_data ),
765- ContentType = "application/json" ,
766- )
767- yield consumer_mapping
768- s3_client .delete_object (Bucket = consumer_mapping_bucket , Key = "consumer_mapping.json" )
769-
770-
771732@pytest .fixture
772733def campaign_config_with_rules_having_rule_code (
773734 s3_client : BaseClient , rules_bucket : BucketName
@@ -1030,7 +991,7 @@ def campaign_config_with_invalid_tokens(s3_client: BaseClient, rules_bucket: Buc
1030991 s3_client .delete_object (Bucket = rules_bucket , Key = f"{ campaign .name } .json" )
1031992
1032993
1033- @pytest .fixture (scope = "class " )
994+ @pytest .fixture (scope = "function " )
1034995def multiple_campaign_configs (s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [list [CampaignConfig ]]:
1035996 """Create and upload multiple campaign configs to S3, then clean up after tests."""
1036997 campaigns , campaign_data_keys = [], []
@@ -1053,6 +1014,7 @@ def multiple_campaign_configs(s3_client: BaseClient, rules_bucket: BucketName) -
10531014 for i in range (3 ):
10541015 campaign = rule .CampaignConfigFactory .build (
10551016 name = f"campaign_{ i } " ,
1017+ id = f"{ targets [i ]} _campaign_id" ,
10561018 target = targets [i ],
10571019 type = "V" ,
10581020 iterations = [
@@ -1149,6 +1111,168 @@ def campaign_config_with_missing_descriptions_missing_rule_text(
11491111 yield campaign
11501112 s3_client .delete_object (Bucket = rules_bucket , Key = f"{ campaign .name } .json" )
11511113
1114+ @pytest .fixture (scope = "function" )
1115+ def multiple_campaign_configs (request , s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [list [CampaignConfig ]]:
1116+ """Create and upload multiple campaign configs to S3, then clean up after tests."""
1117+ campaigns , campaign_data_keys = [], []
1118+
1119+ targets = getattr (request , "param" , ["RSV" , "COVID" , "FLU" ])
1120+ target_rules_map = {
1121+ targets [0 ]: [
1122+ rule .PersonAgeSuppressionRuleFactory .build (type = RuleType .filter , description = "TOO YOUNG" ),
1123+ rule .PostcodeSuppressionRuleFactory .build (type = RuleType .filter , priority = 8 , cohort_label = "cohort_label4" ),
1124+ ],
1125+ targets [1 ]: [
1126+ rule .PersonAgeSuppressionRuleFactory .build (description = "TOO YOUNG, your icb is: [[PERSON.ICB]]" ),
1127+ rule .PostcodeSuppressionRuleFactory .build (
1128+ priority = 12 , cohort_label = "cohort_label2" , description = "Your postcode is: [[PERSON.POSTCODE]]"
1129+ ),
1130+ ],
1131+ targets [2 ]: [rule .ICBRedirectRuleFactory .build ()],
1132+ }
1133+
1134+ for i in range (3 ):
1135+ campaign = rule .CampaignConfigFactory .build (
1136+ name = f"campaign_{ i } " ,
1137+ id = f"{ targets [i ]} _campaign_id" ,
1138+ target = targets [i ],
1139+ type = "V" ,
1140+ iterations = [
1141+ rule .IterationFactory .build (
1142+ iteration_rules = target_rules_map .get (targets [i ]),
1143+ iteration_cohorts = [
1144+ rule .IterationCohortFactory .build (
1145+ cohort_label = f"cohort_label{ i + 1 } " ,
1146+ cohort_group = f"cohort_group{ i + 1 } " ,
1147+ positive_description = f"positive_desc_{ i + 1 } " ,
1148+ negative_description = f"negative_desc_{ i + 1 } " ,
1149+ ),
1150+ rule .IterationCohortFactory .build (
1151+ cohort_label = "cohort_label4" ,
1152+ cohort_group = "cohort_group4" ,
1153+ positive_description = "positive_desc_4" ,
1154+ negative_description = "negative_desc_4" ,
1155+ ),
1156+ ],
1157+ status_text = StatusText (
1158+ NotEligible = f"You are not eligible to take { targets [i ]} vaccines." ,
1159+ NotActionable = f"You have taken { targets [i ]} vaccine in the last 90 days" ,
1160+ Actionable = f"You can take { targets [i ]} vaccine." ,
1161+ ),
1162+ )
1163+ ],
1164+ )
1165+ campaign_data = {"CampaignConfig" : campaign .model_dump (by_alias = True )}
1166+ key = f"{ campaign .name } .json"
1167+ s3_client .put_object (
1168+ Bucket = rules_bucket , Key = key , Body = json .dumps (campaign_data ), ContentType = "application/json"
1169+ )
1170+ campaigns .append (campaign )
1171+ campaign_data_keys .append (key )
1172+
1173+ yield campaigns
1174+
1175+ for key in campaign_data_keys :
1176+ s3_client .delete_object (Bucket = rules_bucket , Key = key )
1177+
1178+ @pytest .fixture (scope = "function" )
1179+ def campaign_configs (request , s3_client : BaseClient , rules_bucket : BucketName ) -> Generator [list [CampaignConfig ]]:
1180+ """Create and upload multiple campaign configs to S3, then clean up after tests."""
1181+ campaigns , campaign_data_keys = [], []
1182+
1183+ targets = getattr (request , "param" , ["RSV" , "COVID" , "FLU" ])
1184+
1185+ for i in range (len (targets )):
1186+ campaign : CampaignConfig = rule .CampaignConfigFactory .build (
1187+ name = f"campaign_{ i } " ,
1188+ id = f"{ targets [i ]} _campaign_id" ,
1189+ target = targets [i ],
1190+ type = "V" ,
1191+ iterations = [
1192+ rule .IterationFactory .build (
1193+ iteration_rules = [
1194+ rule .PostcodeSuppressionRuleFactory .build (type = RuleType .filter ),
1195+ rule .PersonAgeSuppressionRuleFactory .build (),
1196+ rule .PersonAgeSuppressionRuleFactory .build (name = "Exclude 76 rolling" , description = "" ),
1197+ ],
1198+ iteration_cohorts = [
1199+ rule .IterationCohortFactory .build (
1200+ cohort_label = "cohort1" ,
1201+ cohort_group = "cohort_group1" ,
1202+ positive_description = "" ,
1203+ negative_description = "" ,
1204+ )
1205+ ],
1206+ status_text = None ,
1207+ )
1208+ ],
1209+ )
1210+ campaign_data = {"CampaignConfig" : campaign .model_dump (by_alias = True )}
1211+ key = f"{ campaign .name } .json"
1212+ s3_client .put_object (
1213+ Bucket = rules_bucket , Key = key , Body = json .dumps (campaign_data ), ContentType = "application/json"
1214+ )
1215+ campaigns .append (campaign )
1216+ campaign_data_keys .append (key )
1217+
1218+ yield campaigns
1219+
1220+ for key in campaign_data_keys :
1221+ s3_client .delete_object (Bucket = rules_bucket , Key = key )
1222+
1223+ @pytest .fixture (scope = "class" )
1224+ def consumer_mapping (s3_client : BaseClient , consumer_mapping_bucket : BucketName ) -> Generator [ConsumerMapping ]:
1225+ consumer_mapping = ConsumerMapping .model_validate ({})
1226+ consumer_mapping .root [ConsumerId ("23-mic7heal-jor6don" )] = [CampaignID ("42-hi5tch-hi5kers-gu5ide-t2o-t3he-gal6axy" )]
1227+
1228+ consumer_mapping_data = consumer_mapping .model_dump (by_alias = True )
1229+ s3_client .put_object (
1230+ Bucket = consumer_mapping_bucket ,
1231+ Key = "consumer_mapping.json" ,
1232+ Body = json .dumps (consumer_mapping_data ),
1233+ ContentType = "application/json" ,
1234+ )
1235+ yield consumer_mapping
1236+ s3_client .delete_object (Bucket = consumer_mapping_bucket , Key = "consumer_mapping.json" )
1237+
1238+ @pytest .fixture (scope = "class" )
1239+ def consumer_mapping_for_rsv_and_covid (s3_client : BaseClient , consumer_mapping_bucket : BucketName ) -> Generator [ConsumerMapping ]:
1240+ consumer_mapping = ConsumerMapping .model_validate ({})
1241+ consumer_mapping .root [ConsumerId ("consumer-id-mapped-to-rsv-and-covid" )] = [CampaignID ("RSV_campaign_id" ),
1242+ CampaignID ("COVID_campaign_id" )]
1243+
1244+ consumer_mapping_data = consumer_mapping .model_dump (by_alias = True )
1245+ s3_client .put_object (
1246+ Bucket = consumer_mapping_bucket ,
1247+ Key = "consumer_mapping.json" ,
1248+ Body = json .dumps (consumer_mapping_data ),
1249+ ContentType = "application/json" ,
1250+ )
1251+ yield consumer_mapping
1252+ s3_client .delete_object (Bucket = consumer_mapping_bucket , Key = "consumer_mapping.json" )
1253+
1254+ @pytest .fixture (scope = "class" )
1255+ def consumer_mapping_with_various_targets (
1256+ s3_client : BaseClient , consumer_mapping_bucket : BucketName
1257+ ) -> Generator [ConsumerMapping ]:
1258+ consumer_mapping = ConsumerMapping .model_validate ({})
1259+ consumer_mapping .root [ConsumerId ("23-mic7heal-jor6don" )] = [
1260+ CampaignID ("campaign_start_date" ),
1261+ CampaignID ("campaign_start_date_plus_one_day" ),
1262+ CampaignID ("campaign_today" ),
1263+ CampaignID ("campaign_tomorrow" ),
1264+ ]
1265+
1266+ consumer_mapping_data = consumer_mapping .model_dump (by_alias = True )
1267+ s3_client .put_object (
1268+ Bucket = consumer_mapping_bucket ,
1269+ Key = "consumer_mapping.json" ,
1270+ Body = json .dumps (consumer_mapping_data ),
1271+ ContentType = "application/json" ,
1272+ )
1273+ yield consumer_mapping
1274+ s3_client .delete_object (Bucket = consumer_mapping_bucket , Key = "consumer_mapping.json" )
1275+
11521276
11531277# If you put StubSecretRepo in a separate module, import it instead
11541278class StubSecretRepo (SecretRepo ):
0 commit comments