Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
SDESK-7442
  • Loading branch information
eos87 committed Dec 10, 2024
1 parent 44cf909 commit cc252d2
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 128 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ exclude = '''

[tool.pytest.ini_options]
testpaths = ["server/planning", "server/tests/prod_api"]
python_files = "*_test.py *_tests.py test_*.py tests_*.py tests.py test.py"
python_files = "*_test.py *_tests.py test_*.py tests_*.py tests.py test.py"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
3 changes: 1 addition & 2 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,12 @@ def generate_recurring_dates(
start,
frequency,
interval=1,
endRepeatMode="count",
until=None,
byday=None,
count=5,
tz=None,
date_only=False,
_created_externally=False,
**_,
):
"""
Expand Down
5 changes: 5 additions & 0 deletions server/planning/events/events_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from copy import deepcopy
import logging

from planning.types.event import EventResourceModel

from superdesk.resource_fields import ID_FIELD
from superdesk import Resource
from planning.utils import get_related_planning_for_events
Expand All @@ -37,6 +39,9 @@ def on_item_created(self, items, operation=None):
created_from_planning = []
regular_events = []
for item in items:
if isinstance(item, EventResourceModel):
item = item.to_dict()

planning_items = get_related_planning_for_events([item[ID_FIELD]], "primary")
if len(planning_items) > 0:
item["created_from_planning"] = planning_items[0].get("_id")
Expand Down
7 changes: 4 additions & 3 deletions server/planning/events/events_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ async def create(self, docs: list[EventResourceModel]):
"""

docs = await self._convert_dicts_to_model(docs)
print(docs)
ids = await super().create(docs)

embedded_planning_lists: list[tuple[EventResourceModel, list[EmbeddedPlanning]]] = []
Expand Down Expand Up @@ -463,7 +464,7 @@ async def _update_single_event(self, updates: dict[str, Any], original: EventRes
"""

if post_required(updates, original.to_dict()):
merged: EventResourceModel = original.model_copy(updates, deep=True)
merged: EventResourceModel = original.clone_with(updates)

# TODO-ASYNC: replace when `event_post` is async
get_resource_service("events_post").validate_item(merged.to_dict())
Expand Down Expand Up @@ -616,7 +617,7 @@ async def _convert_to_recurring_events(self, updates: dict[str, Any], original:
self._validate_convert_to_recurring(updates, original)
updates["recurrence_id"] = original.id

merged: EventResourceModel = original.model_copy(updates, deep=True)
merged = original.clone_with(updates)

# Generated new events will be "draft"
merged.state = WorkflowState.DRAFT
Expand Down Expand Up @@ -753,7 +754,7 @@ def _generate_recurring_events(
recurring_event_updates[field] = None

# let's finally clone the original event & update it with recurring event data
new_event = event.model_copy(update=recurring_event_updates, deep=True)
new_event = event.clone_with(recurring_event_updates)

# reset embedded_planning to all Events but the first one, as this auto-generates
# associated Planning item with Coverages to the event
Expand Down
13 changes: 7 additions & 6 deletions server/planning/events/events_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from typing import Dict, Optional, List, cast
from copy import deepcopy

import pytz
from eve.utils import str_to_date
from copy import deepcopy
from typing import Dict, Optional, List, cast

from superdesk import get_resource_service

from planning.types import Event, EmbeddedPlanningDict, StringFieldTranslation
from planning.common import get_config_event_fields_to_sync_with_planning
from planning.content_profiles.utils import AllContentProfileData
from planning.utils import str_to_date
from planning.utils import get_related_planning_for_events
from planning.content_profiles.utils import AllContentProfileData
from planning.common import get_config_event_fields_to_sync_with_planning
from planning.types import Event, EmbeddedPlanningDict, StringFieldTranslation
from planning.types.event import EmbeddedPlanning as EmbeddedPlanningModel, EventResourceModel

from .common import VocabsSyncData, SyncItemData, SyncData
Expand Down Expand Up @@ -64,6 +64,7 @@ def sync_event_metadata_with_planning_items(

if isinstance(event_updated["dates"]["start"], str):
event_updated["dates"]["start"] = str_to_date(event_updated["dates"]["start"])

if event_updated["dates"]["start"].tzinfo is None:
event_updated["dates"]["start"] = event_updated["dates"]["start"].replace(tzinfo=pytz.utc)

Expand Down
Loading

0 comments on commit cc252d2

Please sign in to comment.