From 6f6665282814971f78976f72e9ae0c107c7e0661 Mon Sep 17 00:00:00 2001 From: Helmy Giacoman Date: Fri, 3 Jan 2025 23:52:13 +0100 Subject: [PATCH] Fix `flag_expired_items_tests.py` SDESK-7456 --- .../commands/flag_expired_items_test.py | 38 +++++++++---------- server/planning/events/events_service.py | 2 +- server/planning/types/common.py | 10 ++--- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/server/planning/commands/flag_expired_items_test.py b/server/planning/commands/flag_expired_items_test.py index 8ed359eee..9209a8287 100644 --- a/server/planning/commands/flag_expired_items_test.py +++ b/server/planning/commands/flag_expired_items_test.py @@ -38,7 +38,6 @@ } -# TODO: Revert changes to test cases to previous state once Planning service is fully changed to async including processing coverages and dates class FlagExpiredItemsTest(TestCase): app_config = { **TestCase.app_config.copy(), @@ -55,11 +54,11 @@ async def asyncSetUp(self): async def assertExpired(self, item_type, results): service = self.event_service if item_type == "events" else self.planning_service - for item_id, result in results.items(): + for item_id, expected_value in results.items(): item = await service.find_one_raw(guid=item_id, req=None) if item: self.assertIsNotNone(item) - self.assertEqual(item.get("expired", False), result) + self.assertEqual(item.get("expired", False), expected_value, f"Failed for item: `{item_id}`") async def insert(self, item_type, items): service = self.event_service if item_type == "events" else self.planning_service @@ -183,9 +182,9 @@ async def test_planning(self): "p3": False, "p4": False, "p5": True, - "p6": True, + "p6": False, "p7": True, - "p8": True, + "p8": False, }, ) @@ -215,19 +214,19 @@ async def test_event_with_single_planning_no_coverages(self): }, { "guid": "p3", - "related_events": [PlanningRelatedEventLink(_id="e3", link_type="secondary")], + "related_events": [PlanningRelatedEventLink(_id="e3", link_type="primary")], **expired["plan"], }, { "guid": "p4", - "related_events": [PlanningRelatedEventLink(_id="e4", link_type="secondary")], + "related_events": [PlanningRelatedEventLink(_id="e4", link_type="primary")], **expired["plan"], }, ], ) await flag_expired_items_handler() await self.assertExpired("events", {"e1": False, "e2": False, "e3": False, "e4": True}) - await self.assertExpired("planning", {"p1": False, "p2": False, "p3": True, "p4": True}) + await self.assertExpired("planning", {"p1": False, "p2": False, "p3": False, "p4": True}) async def test_event_with_single_planning_single_coverage(self): async with self.app.app_context(): @@ -291,7 +290,7 @@ async def test_event_with_single_planning_single_coverage(self): }, { "guid": "p8", - "related_events": [PlanningRelatedEventLink(_id="e8", link_type="secondary")], + "related_events": [PlanningRelatedEventLink(_id="e8", link_type="primary")], **expired["plan"], "coverages": [expired["coverage"]], }, @@ -306,7 +305,7 @@ async def test_event_with_single_planning_single_coverage(self): "e3": False, "e4": False, "e5": False, - "e6": True, + "e6": False, "e7": False, "e8": True, }, @@ -319,7 +318,7 @@ async def test_event_with_single_planning_single_coverage(self): "p3": False, "p4": False, "p5": False, - "p6": True, + "p6": False, "p7": False, "p8": True, }, @@ -429,7 +428,6 @@ async def test_event_with_single_planning_multiple_coverages(self): }, { "guid": "p14", - "related_events": [PlanningRelatedEventLink(_id="e14", link_type="secondary")], **expired["plan"], "coverages": [expired["coverage"], expired["coverage"]], # EEE }, @@ -447,11 +445,11 @@ async def test_event_with_single_planning_multiple_coverages(self): "e06": False, "e07": False, "e08": False, - "e09": True, + "e09": False, "e10": False, "e11": False, - "e12": True, - "e13": True, + "e12": False, + "e13": False, "e14": True, }, ) @@ -466,11 +464,11 @@ async def test_event_with_single_planning_multiple_coverages(self): "p06": False, "p07": False, "p08": False, - "p09": True, + "p09": False, "p10": False, "p11": False, - "p12": True, - "p13": True, + "p12": False, + "p13": False, "p14": True, }, ) @@ -579,13 +577,13 @@ async def test_event_with_multiple_planning(self): }, { "guid": "p15", - "related_events": [PlanningRelatedEventLink(_id="e8", link_type="secondary")], + "related_events": [PlanningRelatedEventLink(_id="e8", link_type="primary")], **expired["plan"], "coverages": [expired["coverage"]], }, { "guid": "p16", - "related_events": [PlanningRelatedEventLink(_id="e8", link_type="secondary")], + "related_events": [PlanningRelatedEventLink(_id="e8", link_type="primary")], **expired["plan"], "coverages": [expired["coverage"]], }, diff --git a/server/planning/events/events_service.py b/server/planning/events/events_service.py index 13e2e4264..418e3cf26 100644 --- a/server/planning/events/events_service.py +++ b/server/planning/events/events_service.py @@ -66,7 +66,7 @@ async def get_expired_items( are not already marked as expired. By default, items returned are: - - Not expired. + - Not already marked as expired (expired=True). - Have an end date `<= expiry_datetime`. If `spiked_events_only` is True, only spiked events are returned, still filtered by diff --git a/server/planning/types/common.py b/server/planning/types/common.py index b1f5a2b2a..644e61fca 100644 --- a/server/planning/types/common.py +++ b/server/planning/types/common.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +from datetime import datetime from pydantic import Field, TypeAdapter from typing import Any, Annotated, Literal, TypeAlias @@ -70,7 +70,7 @@ class PlanningSchedule(Dataclass): @dataclass class UpdatesSchedule: - scheduled: date | None = None + scheduled: datetime | None = None scheduled_update_id: fields.Keyword | None = None @@ -128,7 +128,7 @@ class Place: class RelatedEvent(Dataclass): - id: Annotated[fields.Keyword, validate_data_relation_async("events")] = Field(validation_alias="_id") + id: Annotated[fields.Keyword, validate_data_relation_async("events")] = Field(alias="_id") recurrence_id: fields.Keyword | None = None link_type: LinkType | None = None @@ -242,8 +242,8 @@ class PlanningCoverage(Dataclass): guid: fields.Keyword | None = None # Audit Information - original_creator: Annotated[fields.ObjectId, validate_data_relation_async("users")] = None - version_creator: Annotated[fields.ObjectId, validate_data_relation_async("users")] = None + original_creator: Annotated[fields.ObjectId | None, validate_data_relation_async("users")] = None + version_creator: Annotated[fields.ObjectId | None, validate_data_relation_async("users")] = None firstcreated: datetime = Field(default_factory=utcnow) versioncreated: datetime = Field(default_factory=utcnow)