test: More coverage on methods. All tests are passed.

This commit is contained in:
kbe
2025-07-25 14:17:12 +02:00
parent 0baa5b6e3f
commit f975cb529f
2 changed files with 70 additions and 2 deletions

1
TODO
View File

@@ -32,6 +32,5 @@ No tests for concurrent booking scenarios
Test private methods like _make_request through their public interfaces or consider making them protected
Add integration tests for the complete booking flow
Improve edge case coverage in existing tests

View File

@@ -105,5 +105,74 @@ class TestSessionConfig:
assert sessions[1] == (0, "18:00", "")
assert sessions[2] == (0, "00:00", "Test")
def test_load_preferred_sessions_partial_json(self):
"""Test behavior when the config file contains partial JSON content"""
# Create partial JSON content
partial_json = '{"day_of_week": 1, "start_time": "08:00" ' # Missing closing brace
# Mock the open function to return partial JSON
with patch('builtins.open', mock_open(read_data=partial_json)):
with patch('logging.warning') as mock_warning:
sessions = SessionConfig.load_preferred_sessions()
# Verify warning was logged
mock_warning.assert_called_once()
assert "decode" in mock_warning.call_args[0][0]
# Verify default sessions are returned
assert len(sessions) == 3
assert sessions[0] == (2, "18:30", "CONDITIONING")
assert sessions[1] == (4, "17:00", "WEIGHTLIFTING")
assert sessions[2] == (5, "12:30", "HYROX")
def test_load_preferred_sessions_incorrect_field_types(self):
"""Test behavior when the config file contains JSON with incorrect field types"""
# Create JSON with incorrect field types
mock_content = json.dumps([
{"day_of_week": "Monday", "start_time": "08:00", "session_name_contains": "Morning"},
{"day_of_week": 1, "start_time": 800, "session_name_contains": "Morning"},
])
# Mock the open function to return our mock file content
with patch('builtins.open', mock_open(read_data=mock_content)):
sessions = SessionConfig.load_preferred_sessions()
# Verify the returned sessions use the values as provided
assert len(sessions) == 2
assert sessions[0] == ("Monday", "08:00", "Morning")
assert sessions[1] == (1, 800, "Morning")
def test_load_preferred_sessions_extra_fields(self):
"""Test behavior when the config file contains JSON with extra fields"""
# Create JSON with extra fields
mock_content = json.dumps([
{"day_of_week": 1, "start_time": "08:00", "session_name_contains": "Morning", "extra_field": "extra_value"},
])
# Mock the open function to return our mock file content
with patch('builtins.open', mock_open(read_data=mock_content)):
sessions = SessionConfig.load_preferred_sessions()
# Verify the returned sessions ignore extra fields
assert len(sessions) == 1
assert sessions[0] == (1, "08:00", "Morning")
def test_load_preferred_sessions_duplicate_entries(self):
"""Test behavior when the config file contains duplicate session entries"""
# Create JSON with duplicate entries
mock_content = json.dumps([
{"day_of_week": 1, "start_time": "08:00", "session_name_contains": "Morning"},
{"day_of_week": 1, "start_time": "08:00", "session_name_contains": "Morning"},
])
# Mock the open function to return our mock file content
with patch('builtins.open', mock_open(read_data=mock_content)):
sessions = SessionConfig.load_preferred_sessions()
# Verify the returned sessions contain duplicates
assert len(sessions) == 2
assert sessions[0] == (1, "08:00", "Morning")
assert sessions[1] == (1, "08:00", "Morning")
if __name__ == "__main__":
pytest.main([__file__, "-v"])