roughly working again, now dev docker exists

This commit is contained in:
Aron Petau 2025-12-28 19:59:31 +01:00
parent a77a0c0393
commit 155ab39368
26 changed files with 1976 additions and 235 deletions

View file

@ -1,35 +1,48 @@
import os
import sys
from pathlib import Path
import pytest
from unittest.mock import patch, mock_open
from archive.test_errorrate_runner import generate_error_rate_plot
from unittest.mock import patch, mock_open, MagicMock
sys.path.append(str(Path(__file__).parent.parent))
from application_handler import ApplicationHandler
@pytest.fixture
def mock_data_dir(tmp_path):
"""Fixture to create a temporary data directory."""
def temp_applications_file(tmp_path):
data_dir = tmp_path / "data"
data_dir.mkdir()
return data_dir
file = data_dir / "applications.json"
file.write_text("{}", encoding="utf-8")
return file
@patch("builtins.open", new_callable=mock_open, read_data="{}")
@patch("os.path.exists", return_value=True)
def test_generate_error_rate_plot_no_data(mock_exists, mock_open, mock_data_dir):
"""Test generate_error_rate_plot with no data."""
plot_path, summary = generate_error_rate_plot(str(mock_data_dir / "applications.json"))
assert plot_path is None
class DummyStateManager:
email = None
password = None
logged_in = False
def set_autopilot(self, enabled): pass
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)
plot_path, summary = handler._generate_error_rate_plot()
assert plot_path is None or plot_path == ""
assert summary == ""
@patch("builtins.open", new_callable=mock_open)
@patch("os.path.exists", return_value=True)
@patch("matplotlib.pyplot.savefig")
def test_generate_error_rate_plot_with_data(mock_savefig, mock_exists, mock_open, mock_data_dir):
"""Test generate_error_rate_plot with valid data."""
mock_open.return_value.read.return_value = """
def test_generate_error_rate_plot_with_data(mock_savefig, temp_applications_file):
handler = ApplicationHandler(None, DummyStateManager(), applications_file=temp_applications_file)
# Write valid data to the temp applications file
temp_applications_file.write_text('''
{
"1": {"timestamp": "2025-12-25T12:00:00", "company": "CompanyA", "success": true},
"2": {"timestamp": "2025-12-26T12:00:00", "company": "CompanyB", "success": false}
}
"""
plot_path, summary = generate_error_rate_plot(str(mock_data_dir / "applications.json"))
''', encoding="utf-8")
plot_path, summary = handler._generate_error_rate_plot()
assert plot_path is not None
assert "Total attempts" in summary
assert "Successes" in summary