Skip to content

Commit

Permalink
renamed function
Browse files Browse the repository at this point in the history
  • Loading branch information
yaelibarg committed Jan 16, 2025
1 parent ba4d1d2 commit 415efcd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions port_ocean/core/integrations/mixins/sync_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
RAW_ITEM,
CalculationResult,
)
from port_ocean.core.utils.utils import map_entities, zip_and_sum, gather_and_split_errors_from_results
from port_ocean.core.utils.utils import resolve_entities_diff, zip_and_sum, gather_and_split_errors_from_results
from port_ocean.exceptions.core import OceanAbortException

SEND_RAW_DATA_EXAMPLES_AMOUNT = 5
Expand Down Expand Up @@ -175,7 +175,7 @@ async def _map_entities_compared_with_port(
logger.info("getting Entities from port with properties", port_entities=len(entities_at_port_with_properties))

if len(entities_at_port_with_properties) > 0:
return map_entities(entities, entities_at_port_with_properties)
return resolve_entities_diff(entities, entities_at_port_with_properties)
return entities

async def _register_resource_raw(
Expand Down
2 changes: 1 addition & 1 deletion port_ocean/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def are_entities_different(first_entity: Entity, second_entity: Entity) -> bool:
) or not are_entities_fields_equal(first_entity.relations, second_entity.relations)


def map_entities(
def resolve_entities_diff(
third_party_entities: list[Entity], port_entities: list[Entity]
) -> list[Entity]:
"""
Expand Down
8 changes: 5 additions & 3 deletions port_ocean/tests/core/handlers/mixins/test_sync_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ async def test_map_entities_compared_with_port_with_existing_entities(
expected_changed = [third_party_entities[0], third_party_entities[1]]

with patch(
"port_ocean.core.integrations.mixins.sync_raw.map_entities",
"port_ocean.core.integrations.mixins.sync_raw.resolve_entities_diff",
return_value=(expected_changed),
) as mock_map_entities:
) as mock_resolve_entities_diff:
# Execute test
changed_entities = await mock_sync_raw_mixin._map_entities_compared_with_port(
third_party_entities, resource, UserAgentType.exporter
Expand All @@ -655,7 +655,9 @@ async def test_map_entities_compared_with_port_with_existing_entities(
# Verify results
assert len(changed_entities) == 2
assert [e.identifier for e in changed_entities] == ["entity_1", "entity_2"]
assert mock_map_entities.call_count == 1 # Verify map_entities was called once
assert (
mock_resolve_entities_diff.call_count == 1
) # Verify map_entities was called once


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from port_ocean.core.models import Entity
from port_ocean.core.utils.utils import (
are_entities_different,
map_entities,
resolve_entities_diff,
are_entities_fields_equal,
)
from typing import Any
Expand Down Expand Up @@ -351,71 +351,71 @@ def test_are_entities_different_with_different_relations_should_be_true() -> Non
)


def test_map_entities_empty_lists() -> None:
def test_resolve_entities_diff_empty_lists() -> None:
"""Test when both input lists are empty"""
changed = map_entities([], [])
changed = resolve_entities_diff([], [])
assert len(changed) == 0


def test_map_entities_new_entities() -> None:
def test_resolve_entities_diff_new_entities() -> None:
"""Test when there are simple third party entities that are not in Port"""
changed = map_entities([entity1, entity2], [])
changed = resolve_entities_diff([entity1, entity2], [])
assert len(changed) == 2
assert changed[0] == entity1
assert changed[1] == entity2


def test_map_entities_deleted_entities() -> None:
def test_resolve_entities_diff_deleted_entities() -> None:
"""Test when entities exist in Port but not in third party"""
changed = map_entities([], [entity1, entity2])
changed = resolve_entities_diff([], [entity1, entity2])
assert len(changed) == 0


def test_map_entities_identical_entities() -> None:
def test_resolve_entities_diff_identical_entities() -> None:
"""Test when entities are identical in both sources"""
changed = map_entities([entity1], [entity1])
changed = resolve_entities_diff([entity1], [entity1])
assert len(changed) == 0


def test_map_entities_modified_properties() -> None:
def test_resolve_entities_diff_modified_properties() -> None:
"""Test when entities exist but have different properties"""
changed = map_entities([entity1_modified_properties], [entity1])
changed = resolve_entities_diff([entity1_modified_properties], [entity1])
assert len(changed) == 1
assert changed[0] == entity1_modified_properties


def test_map_entities_modified_relations() -> None:
def test_resolve_entities_diff_modified_relations() -> None:
"""Test when entities exist but have different relations"""
changed = map_entities([entity1_modified_relations], [entity1])
changed = resolve_entities_diff([entity1_modified_relations], [entity1])
assert len(changed) == 1
assert changed[0] == entity1_modified_relations


def test_map_entities_search_identifier_entity() -> None:
def test_resolve_entities_diff_search_identifier_entity() -> None:
"""Test when entity uses search identifier"""
with patch(
"port_ocean.core.utils.utils.are_entities_different", return_value=False
) as mock_are_different:
changed = map_entities([entity_with_search_identifier], [])
changed = resolve_entities_diff([entity_with_search_identifier], [])
assert len(changed) == 1
assert changed[0] == entity_with_search_identifier
mock_are_different.assert_not_called()


def test_map_entities_search_relation_entity() -> None:
def test_resolve_entities_diff_search_relation_entity() -> None:
"""Test when entity uses search relation"""
with patch(
"port_ocean.core.utils.utils.are_entities_different", return_value=False
) as mock_are_different:
changed = map_entities([entity_with_search_relation], [])
changed = resolve_entities_diff([entity_with_search_relation], [])
assert len(changed) == 1
assert changed[0] == entity_with_search_relation
mock_are_different.assert_not_called()


def test_map_entities_multiple_entities() -> None:
def test_resolve_entities_diff_multiple_entities() -> None:
"""Test with multiple entities in both sources"""
changed = map_entities(
changed = resolve_entities_diff(
[entity1_modified_properties, entity2, entity_with_search_identifier],
[entity1, entity3],
)
Expand Down

0 comments on commit 415efcd

Please sign in to comment.