|
| 1 | +import datetime |
1 | 2 | import json |
2 | 3 | import logging |
3 | 4 | import os |
|
19 | 20 | from eligibility_signposting_api.model import eligibility_status |
20 | 21 | from eligibility_signposting_api.model.campaign_config import ( |
21 | 22 | CampaignConfig, |
| 23 | + EndDate, |
22 | 24 | RuleType, |
| 25 | + StartDate, |
23 | 26 | ) |
24 | 27 | from eligibility_signposting_api.repos.campaign_repo import BucketName |
25 | 28 | from eligibility_signposting_api.repos.person_repo import TableName |
@@ -380,7 +383,7 @@ def persisted_person_all_cohorts(person_table: Any, faker: Faker) -> Generator[e |
380 | 383 | nhs_number, |
381 | 384 | date_of_birth=date_of_birth, |
382 | 385 | postcode="SW19", |
383 | | - cohorts=["cohort_label1", "cohort_label2", "cohort_label3", "cohort_label4"], |
| 386 | + cohorts=["cohort_label1", "cohort_label2", "cohort_label3", "cohort_label4", "cohort_label5"], |
384 | 387 | icb="QE1", |
385 | 388 | ).data |
386 | 389 | ): |
@@ -484,6 +487,48 @@ def campaign_config(s3_client: BaseClient, rules_bucket: BucketName) -> Generato |
484 | 487 | s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json") |
485 | 488 |
|
486 | 489 |
|
| 490 | +@pytest.fixture(scope="class") |
| 491 | +def inactive_iteration_config(s3_client: BaseClient, rules_bucket: BucketName) -> Generator[list[CampaignConfig]]: |
| 492 | + campaigns, campaign_data_keys = [], [] |
| 493 | + |
| 494 | + target_iteration_dates = { |
| 495 | + "start_date": ("RSV", datetime.date(2025, 1, 1)), # Active Iteration Date |
| 496 | + "start_date_plus_one_day": ("COVID", datetime.date(2025, 1, 2)), # Active Iteration Date |
| 497 | + "today": ("FLU", datetime.date(2025, 8, 8)), # Active Iteration Date |
| 498 | + "tomorrow": ("MMR", datetime.date(2025, 8, 9)), # Inactive Iteration Date |
| 499 | + } |
| 500 | + |
| 501 | + for target, data in target_iteration_dates.items(): |
| 502 | + campaign = rule.CampaignConfigFactory.build( |
| 503 | + id=f"campaign_{target}", |
| 504 | + target=data[0], |
| 505 | + type="V", |
| 506 | + iterations=[ |
| 507 | + rule.IterationFactory.build( |
| 508 | + iteration_rules=[rule.PersonAgeSuppressionRuleFactory.build()], |
| 509 | + iteration_cohorts=[rule.IterationCohortFactory.build(cohort_label="cohort_label1")], |
| 510 | + ) |
| 511 | + ], |
| 512 | + ) |
| 513 | + |
| 514 | + campaign.start_date = StartDate(datetime.date(2025, 1, 1)) |
| 515 | + campaign.end_date = EndDate(datetime.date(2026, 1, 1)) |
| 516 | + campaign.iterations[0].iteration_date = data[1] |
| 517 | + |
| 518 | + campaign_data = {"CampaignConfig": campaign.model_dump(by_alias=True)} |
| 519 | + key = f"{campaign.name}.json" |
| 520 | + s3_client.put_object( |
| 521 | + Bucket=rules_bucket, Key=key, Body=json.dumps(campaign_data), ContentType="application/json" |
| 522 | + ) |
| 523 | + campaigns.append(campaign) |
| 524 | + campaign_data_keys.append(key) |
| 525 | + |
| 526 | + yield campaigns |
| 527 | + |
| 528 | + for key in campaign_data_keys: |
| 529 | + s3_client.delete_object(Bucket=rules_bucket, Key=key) |
| 530 | + |
| 531 | + |
487 | 532 | @pytest.fixture(scope="class") |
488 | 533 | def campaign_config_with_and_rule(s3_client: BaseClient, rules_bucket: BucketName) -> Generator[CampaignConfig]: |
489 | 534 | campaign: CampaignConfig = rule.CampaignConfigFactory.build( |
|
0 commit comments