Skip to content

Commit 3715f64

Browse files
committed
test: added additional tests
1 parent 853794c commit 3715f64

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

tests/platforms/test_dispatcher.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from unittest.mock import patch
2+
3+
import pytest
4+
5+
import app.platforms.dispatcher as dispatcher
6+
from app.platforms.base import BaseProcessingPlatform
7+
from app.schemas import ProcessType, ProcessingJobSummary
8+
9+
10+
class DummyPlatform(BaseProcessingPlatform):
11+
def execute_job(self, title: str, details: dict, parameters: dict) -> ProcessingJobSummary:
12+
return ProcessingJobSummary(
13+
id="dummy-job-id",
14+
title=title,
15+
status="created"
16+
)
17+
18+
19+
@pytest.fixture(autouse=True)
20+
def clear_registry():
21+
"""Ensure PROCESSING_PLATFORMS is clean before each test."""
22+
dispatcher.PROCESSING_PLATFORMS.clear()
23+
yield
24+
dispatcher.PROCESSING_PLATFORMS.clear()
25+
26+
27+
def test_register_processing_platform():
28+
dispatcher.register_processing_platform(ProcessType.OPENEO, DummyPlatform)
29+
assert dispatcher.PROCESSING_PLATFORMS[ProcessType.OPENEO] is DummyPlatform
30+
31+
32+
def test_get_processing_platform_success():
33+
dispatcher.PROCESSING_PLATFORMS[ProcessType.OPENEO] = DummyPlatform
34+
instance = dispatcher.get_processing_platform(ProcessType.OPENEO)
35+
assert isinstance(instance, DummyPlatform)
36+
37+
38+
def test_get_processing_platform_unsupported():
39+
with pytest.raises(ValueError, match="Unsupported service type"):
40+
dispatcher.get_processing_platform(ProcessType.OPENEO)
41+
42+
43+
@patch("app.platforms.dispatcher.importlib.import_module")
44+
@patch("app.platforms.dispatcher.pkgutil.iter_modules")
45+
def test_load_processing_platforms(mock_iter_modules, mock_import_module):
46+
# Simulate two modules found in the implementations package
47+
mock_iter_modules.return_value = [
48+
(None, "mod1", False),
49+
(None, "mod2", False),
50+
]
51+
52+
dispatcher.load_processing_platforms()
53+
54+
mock_import_module.assert_any_call("app.platforms.implementations.mod1")
55+
mock_import_module.assert_any_call("app.platforms.implementations.mod2")
56+
assert mock_import_module.call_count == 2
57+
58+
59+
@patch("app.platforms.dispatcher.pkgutil.iter_modules")
60+
def test_load_processing_platforms_no_modules(mock_iter_modules):
61+
mock_iter_modules.return_value = []
62+
# Should not raise, just do nothing
63+
dispatcher.load_processing_platforms()

tests/services/test_processing.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from unittest.mock import patch, MagicMock
2+
3+
import pytest
4+
5+
from app.schemas import BaseJobRequest, ProcessingJobSummary, ProcessType, ServiceDetails
6+
from app.services.processing import create_processing_job
7+
8+
9+
def make_job_request():
10+
"""Helper to build a valid job request."""
11+
return BaseJobRequest(
12+
label=ProcessType.OPENEO,
13+
title="Test Job",
14+
service= ServiceDetails(
15+
service="dummy-service-id",
16+
application="dummy-application"
17+
),
18+
parameters={"param": 1}
19+
)
20+
21+
22+
@patch("app.services.processing.get_processing_platform")
23+
def test_create_processing_job_calls_platform_execute(mock_get_platform):
24+
25+
# Arrange
26+
fake_summary = make_job_request()
27+
fake_result = ProcessingJobSummary(
28+
id="fake-job-id",
29+
title=fake_summary.title,
30+
status="created"
31+
)
32+
33+
fake_platform = MagicMock()
34+
fake_platform.execute_job.return_value = fake_result
35+
mock_get_platform.return_value = fake_platform
36+
37+
# Act
38+
result = create_processing_job(fake_summary)
39+
40+
# Assert
41+
mock_get_platform.assert_called_once_with(fake_summary.label)
42+
fake_platform.execute_job.assert_called_once_with(
43+
title=fake_summary.title,
44+
details=fake_summary.service,
45+
parameters=fake_summary.parameters
46+
)
47+
assert result is fake_result
48+
49+
50+
@patch("app.services.processing.get_processing_platform")
51+
def test_create_processing_job_platform_raises(mock_get_platform):
52+
# Arrange
53+
fake_summary = make_job_request()
54+
mock_get_platform.side_effect = ValueError("Unsupported platform")
55+
56+
# Act & Assert
57+
with pytest.raises(ValueError, match="Unsupported platform"):
58+
create_processing_job(fake_summary)

0 commit comments

Comments
 (0)