Skip to content

Commit

Permalink
Fix flag_expired_items_tests.py
Browse files Browse the repository at this point in the history
SDESK-7456
  • Loading branch information
eos87 committed Jan 3, 2025
1 parent 51eed09 commit 1cfcd1d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
39 changes: 19 additions & 20 deletions server/planning/commands/flag_expired_items_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -55,11 +54,12 @@ 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)
print(item.get("expired"), item_id)
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
Expand Down Expand Up @@ -183,9 +183,9 @@ async def test_planning(self):
"p3": False,
"p4": False,
"p5": True,
"p6": True,
"p6": False,
"p7": True,
"p8": True,
"p8": False,
},
)

Expand Down Expand Up @@ -215,19 +215,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():
Expand Down Expand Up @@ -291,7 +291,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"]],
},
Expand All @@ -306,7 +306,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,
},
Expand All @@ -319,7 +319,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,
},
Expand Down Expand Up @@ -429,7 +429,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
},
Expand All @@ -447,11 +446,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,
},
)
Expand All @@ -466,11 +465,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,
},
)
Expand Down Expand Up @@ -579,13 +578,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"]],
},
Expand Down
2 changes: 1 addition & 1 deletion server/planning/events/events_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions server/planning/types/common.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1cfcd1d

Please sign in to comment.