mirror of
https://github.com/sstent/FitTrack_ReportGenerator.git
synced 2026-01-27 09:32:12 +00:00
sync
This commit is contained in:
@@ -1,34 +1,35 @@
|
||||
import io
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock, patch, ANY
|
||||
from src.core.file_parser import TcxParser, WorkoutData, WorkoutMetadata
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_tcx_parser():
|
||||
# Patch the TCXParser class where it's imported in src.core.file_parser
|
||||
with patch('src.core.file_parser.TCXParser') as mock_tcx_parser_class:
|
||||
with patch("src.core.file_parser.TCXParser") as mock_tcx_parser_class:
|
||||
mock_tcx_instance = MagicMock()
|
||||
mock_tcx_parser_class.return_value = mock_tcx_instance
|
||||
|
||||
mock_tcx_instance.started_at = datetime(2023, 1, 1, 10, 0, 0)
|
||||
mock_tcx_instance.duration = 3600 # 1 hour
|
||||
mock_tcx_instance.duration = 3600 # 1 hour
|
||||
# Mock other attributes as needed for future tests
|
||||
|
||||
yield mock_tcx_parser_class
|
||||
|
||||
def test_tcx_parser_initialization():
|
||||
parser = TcxParser("dummy.tcx")
|
||||
assert parser.file_path == "dummy.tcx"
|
||||
|
||||
def test_tcx_parser_parse_method_returns_workout_data(mock_tcx_parser):
|
||||
parser = TcxParser("dummy.tcx")
|
||||
workout_data = parser.parse()
|
||||
parser = TcxParser()
|
||||
workout_data = parser.parse(io.BytesIO(b"<tcx></tcx>"))
|
||||
|
||||
mock_tcx_parser.assert_called_once_with("dummy.tcx")
|
||||
mock_tcx_parser.assert_called_once_with(ANY)
|
||||
|
||||
assert isinstance(workout_data, WorkoutData)
|
||||
assert isinstance(workout_data.metadata, WorkoutMetadata)
|
||||
assert workout_data.metadata.file_type == "TCX"
|
||||
assert workout_data.metadata.start_time == datetime(2023, 1, 1, 10, 0, 0)
|
||||
assert workout_data.metadata.duration == timedelta(seconds=3600)
|
||||
assert workout_data.time_series_data.empty # Currently, no time series data is mocked
|
||||
assert (
|
||||
workout_data.time_series_data.empty
|
||||
) # Currently, no time series data is mocked
|
||||
|
||||
Reference in New Issue
Block a user