mostly working shape?

This commit is contained in:
Aron Petau 2025-12-31 16:06:42 +01:00
parent 3057cda8d3
commit 540a3cc884
10 changed files with 462 additions and 183 deletions

View file

@ -16,12 +16,18 @@ def temp_applications_file(tmp_path):
@pytest.fixture
def application_handler(temp_applications_file, monkeypatch):
"""Fixture to create an ApplicationHandler instance with a temporary applications file."""
class DummyContext: pass
class DummyStateManager: pass
monkeypatch.setattr("application_handler.APPLICATIONS_FILE", temp_applications_file)
return ApplicationHandler(browser_context=None, state_manager=None)
return ApplicationHandler(browser_context=DummyContext(), state_manager=DummyStateManager(), applications_file=temp_applications_file)
import types
class DummyContext: pass
class DummyStateManager: pass
def test_detect_company_domains():
handler = ApplicationHandler(browser_context=None, state_manager=None)
handler = ApplicationHandler(browser_context=DummyContext(), state_manager=DummyStateManager())
assert handler._detect_company('https://howoge.de/abc') == 'howoge'
assert handler._detect_company('https://www.howoge.de/abc') == 'howoge'
assert handler._detect_company('https://portal.gewobag.de/') == 'gewobag'
@ -32,7 +38,7 @@ def test_detect_company_domains():
assert handler._detect_company('https://wbm.de/') == 'wbm'
def test_detect_company_path_fallback():
handler = ApplicationHandler(browser_context=None, state_manager=None)
handler = ApplicationHandler(browser_context=DummyContext(), state_manager=DummyStateManager())
assert handler._detect_company('https://example.com/howoge/abc') == 'howoge'
assert handler._detect_company('https://foo.bar/gewobag') == 'gewobag'
assert handler._detect_company('https://foo.bar/degewo') == 'degewo'
@ -41,7 +47,7 @@ def test_detect_company_path_fallback():
assert handler._detect_company('https://foo.bar/wbm') == 'wbm'
def test_detect_company_unknown():
handler = ApplicationHandler(browser_context=None, state_manager=None)
handler = ApplicationHandler(browser_context=DummyContext(), state_manager=DummyStateManager())
assert handler._detect_company('https://example.com/') == 'unknown'
assert handler._detect_company('') == 'unknown'
assert handler._detect_company(None) == 'unknown'

View file

@ -13,7 +13,8 @@ class DummyStateManager:
def make_handler():
# context is not used for _detect_company
return ApplicationHandler(browser_context=None, state_manager=DummyStateManager())
class DummyContext: pass
return ApplicationHandler(browser_context=DummyContext(), state_manager=DummyStateManager())
def test_detect_company_domains():
handler = make_handler()

View file

@ -24,17 +24,23 @@ class DummyStateManager:
def is_autopilot_enabled(self): return False
@patch("matplotlib.pyplot.savefig")
def test_generate_error_rate_plot_no_data(mock_savefig, temp_applications_file):
handler = ApplicationHandler(None, DummyStateManager(), applications_file=temp_applications_file)
class DummyContext: pass
handler = ApplicationHandler(DummyContext(), DummyStateManager(), applications_file=temp_applications_file)
plot_path, summary = handler._generate_error_rate_plot()
assert plot_path is None or plot_path == ""
assert summary == ""
@patch("matplotlib.pyplot.savefig")
from unittest.mock import patch
@patch("matplotlib.figure.Figure.savefig")
def test_generate_error_rate_plot_with_data(mock_savefig, temp_applications_file):
handler = ApplicationHandler(None, DummyStateManager(), applications_file=temp_applications_file)
class DummyContext: pass
handler = ApplicationHandler(DummyContext(), DummyStateManager(), applications_file=temp_applications_file)
# Write valid data to the temp applications file
temp_applications_file.write_text('''
{
@ -48,4 +54,4 @@ def test_generate_error_rate_plot_with_data(mock_savefig, temp_applications_file
assert "Successes" in summary
assert "Failures" in summary
assert "Overall error rate" in summary
mock_savefig.assert_called_once()
mock_savefig.assert_called()

View file

@ -1,3 +1,6 @@
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent.parent))
import pytest
from handlers.howoge_handler import HowogeHandler
from handlers.gewobag_handler import GewobagHandler
@ -16,7 +19,7 @@ class MockBaseHandler(BaseHandler):
async def test_howoge_handler():
context = AsyncMock()
handler = HowogeHandler(context)
listing = {"link": "https://www.howoge.de/example"}
listing = {"link": "https://www.howoge.de/example", "id": "testid"}
result = {"success": False}
await handler.apply(listing, result)
assert "success" in result