Skip to content

Commit

Permalink
Update fake integration tests according to new core standards
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Sep 17, 2024
1 parent 2be1782 commit 2f09b26
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
5 changes: 5 additions & 0 deletions integrations/fake-integration/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ruff: noqa
from port_ocean.tests.helpers.fixtures import (
get_mocked_ocean_app,
get_mock_ocean_resource_configs,
)
67 changes: 34 additions & 33 deletions integrations/fake-integration/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Any
from unittest.mock import AsyncMock

from port_ocean.tests.helpers import (
get_raw_result_on_integration_sync_kinds,
from port_ocean.tests.helpers.ocean_app import (
get_raw_result_on_integration_sync_resource_config,
)
from pytest_httpx import HTTPXMock

Expand All @@ -26,7 +26,20 @@
FAKE_PERSON_RAW = FAKE_PERSON.dict()


def assert_on_results(results: Any, kind: str) -> None:
assert len(results) > 0
entities, errors = results
assert len(errors) == 0
assert len(entities) > 0
if kind == "fake-person":
assert entities[0] == FAKE_PERSON_RAW
else:
assert len(entities) == 5


async def test_full_sync_with_http_mock(
get_mocked_ocean_app: Any,
get_mock_ocean_resource_configs: Any,
httpx_mock: HTTPXMock,
) -> None:
httpx_mock.add_response(
Expand All @@ -38,45 +51,33 @@ async def test_full_sync_with_http_mock(
},
)

results = await get_raw_result_on_integration_sync_kinds(INTEGRATION_PATH)

assert len(results) > 0

assert "fake-person" in results
assert "fake-department" in results
app = get_mocked_ocean_app()
resource_configs = get_mock_ocean_resource_configs()

person_results = results["fake-person"]
department_results = results["fake-department"]
for resource_config in resource_configs:
results = await get_raw_result_on_integration_sync_resource_config(
app, resource_config
)

assert len(person_results) > 0
assert len(person_results[0][0]) > 1
assert len(person_results[0][1]) == 0
assert_on_results(results, resource_config.kind)

assert len(department_results) > 0
assert len(department_results[0][0]) == 5
assert len(department_results[0][1]) == 0


async def test_full_sync_using_mocked_3rd_party(monkeypatch: Any) -> None:
async def test_full_sync_using_mocked_3rd_party(
monkeypatch: Any,
get_mocked_ocean_app: Any,
get_mock_ocean_resource_configs: Any,
) -> None:
fake_client_mock = AsyncMock()
fake_client_mock.return_value = [FakePerson(**FAKE_PERSON_RAW)]

monkeypatch.setattr(fake_client, "get_fake_persons", fake_client_mock)

results = await get_raw_result_on_integration_sync_kinds(INTEGRATION_PATH)

assert len(results) > 0

assert "fake-person" in results
assert "fake-department" in results

person_results = results["fake-person"]
department_results = results["fake-department"]
app = get_mocked_ocean_app()
resource_configs = get_mock_ocean_resource_configs()

assert len(person_results) > 0
assert len(person_results[0][0]) == 5
assert len(person_results[0][1]) == 0
for resource_config in resource_configs:
results = await get_raw_result_on_integration_sync_resource_config(
app, resource_config
)

assert len(department_results) > 0
assert len(department_results[0][0]) == 5
assert len(department_results[0][1]) == 0
assert_on_results(results, resource_config.kind)

0 comments on commit 2f09b26

Please sign in to comment.