Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMwangi21 committed Dec 2, 2024
1 parent 9102f9c commit dd3feef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/planning/assignments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
from .assignments_history import AssignmentsHistoryResource, AssignmentsHistoryService
from .delivery import DeliveryResource

from .service import AssingmentsAsyncService
from .service import AssignmentsAsyncService
from .module import assignments_resource_config

__all__ = ["assignments_resource_config", "AssingmentsAsyncService"]
__all__ = ["assignments_resource_config", "AssignmentsAsyncService"]


def init_app(app):
Expand Down
4 changes: 2 additions & 2 deletions server/planning/commands/delete_spiked_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from planning.events import EventsAsyncService
from planning.events.utils import get_recurring_timeline
from planning.planning import PlanningAsyncService
from planning.assignments import AssingmentsAsyncService
from planning.assignments import AssignmentsAsyncService
from .async_cli import planning_cli


Expand Down Expand Up @@ -154,7 +154,7 @@ async def delete_spiked_planning(expiry_datetime):
plans_deleted.add(plan_id)

# Delete assignments
assignment_service = AssingmentsAsyncService()
assignment_service = AssignmentsAsyncService()
for assign_id in assignments_to_delete:
await assignment_service.delete_many(lookup={"_id": assign_id})
assignments_deleted.add(assign_id)
Expand Down
17 changes: 10 additions & 7 deletions server/planning/commands/delete_spiked_items_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from planning.common import WORKFLOW_STATE
from planning.events import EventsAsyncService
from planning.planning import PlanningAsyncService
from planning.assignments import AssingmentsAsyncService
from planning.assignments import AssignmentsAsyncService

now = utcnow()
yesterday = now - timedelta(hours=48)
Expand Down Expand Up @@ -78,21 +78,21 @@ async def asyncSetUp(self):

self.event_service = EventsAsyncService()
self.planning_service = PlanningAsyncService()
self.assignment_service = AssingmentsAsyncService()
self.assignment_service = AssignmentsAsyncService()

async def assertDeleteOperation(self, item_type, ids, not_deleted=False):
service = self.event_service if item_type == "events" else self.planning_service

for item_id in ids:
item = await service.find_one(_id=item_id, req=None)
item = await service.find_one(guid=item_id, req=None)
if not_deleted:
self.assertIsNotNone(item)
else:
self.assertIsNone(item)

async def assertAssignmentDeleted(self, assignment_ids, not_deleted=False):
for assignment_id in assignment_ids:
assignment = await self.assignment_service.find_one(_id=assignment_id, req=None)
assignment = await self.assignment_service.find_one(guid=assignment_id, req=None)
if not_deleted:
self.assertIsNotNone(assignment)
else:
Expand All @@ -103,7 +103,8 @@ async def insert(self, item_type, items):
await service.create(items)

async def get_assignments_count(self):
return await self.assignment_service.find({"_id": {"$exists": 1}}).count()
results = await self.assignment_service.find({"_id": {"$exists": 1}})
return await results.count()

async def test_delete_spike_disabled(self):
self.app.config.update({"PLANNING_DELETE_SPIKED_MINUTES": 0})
Expand Down Expand Up @@ -152,7 +153,9 @@ async def test_delete_spike_disabled(self):
)
await delete_spiked_items_handler()
await self.assertDeleteOperation("events", ["e1", "e2", "e3"], not_deleted=True)
await self.assertDeleteOperation("planning", ["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"], True)
await self.assertDeleteOperation(
"planning", ["p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8"], not_deleted=True
)

async def test_event(self):
async with self.app.app_context():
Expand Down Expand Up @@ -292,7 +295,7 @@ async def test_planning_assignment_deletion(self):
# Map plannings to assignments
assignments = {}
for plan_id in ["p1", "p2", "p3", "p4"]:
planning = await self.planning_service.find_one(_id=plan_id, req=None)
planning = await self.planning_service.find_one(guid=plan_id, req=None)
if planning:
assignments[plan_id] = planning["coverages"][0]["assigned_to"]["assignment_id"]

Expand Down

0 comments on commit dd3feef

Please sign in to comment.