Skip to content

Commit 85f9635

Browse files
cfsmp3claude
authored andcommitted
test: Update test_data_for_test to match simplified implementation
The test was checking for g.db.query calls that no longer exist after removing the queue calculation logic. Updated to verify the new behavior that only queries GeneralData for average times. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e2f02ce commit 85f9635

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/test_test/test_controllers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from mod_regression.models import RegressionTest
77
from mod_test.models import (Test, TestPlatform, TestProgress, TestResult,
88
TestResultFile, TestStatus)
9-
from tests.base import BaseTestCase, create_mock_db_query
9+
from tests.base import BaseTestCase
1010
from tests.test_auth.test_controllers import MockUser
1111

1212

@@ -122,25 +122,30 @@ def test_ccextractor_version_not_found(self):
122122
self.assertEqual(response.status_code, 404)
123123
self.assert_template_used('test/test_not_found.html')
124124

125-
@mock.patch('mod_test.controllers.g')
126125
@mock.patch('mod_test.controllers.GeneralData')
127126
@mock.patch('mod_test.controllers.Category')
128-
@mock.patch('mod_test.controllers.TestProgress')
129-
def test_data_for_test(self, mock_test_progress, mock_category, mock_gen_data, mock_g):
127+
def test_data_for_test(self, mock_category, mock_gen_data):
130128
"""Test get_data_for_test method."""
131129
from mod_test.controllers import get_data_for_test
132130

133131
mock_test = mock.MagicMock()
132+
mock_test.progress = [] # No progress yet, so avg_minutes should be calculated
133+
mock_test.platform.value = 'linux'
134134

135-
# Set up mock db query chain to avoid AsyncMock behavior in Python 3.13+
136-
create_mock_db_query(mock_g)
135+
# Mock GeneralData query responses for average times
136+
mock_avg_time = mock.MagicMock()
137+
mock_avg_time.value = '300' # 5 minutes in seconds
138+
mock_prep_time = mock.MagicMock()
139+
mock_prep_time.value = '60' # 1 minute in seconds
140+
mock_gen_data.query.filter.return_value.first.side_effect = [mock_avg_time, mock_prep_time]
137141

138142
result = get_data_for_test(mock_test)
139143

140144
self.assertIsInstance(result, dict)
141-
self.assertEqual(6, mock_g.db.query.call_count)
145+
self.assertIn('avg_minutes', result)
146+
self.assertEqual(result['avg_minutes'], 6) # (300 + 60) / 60 = 6 minutes
142147
mock_category.query.filter.assert_called_once()
143-
mock_gen_data.query.filter.assert_called()
148+
self.assertEqual(mock_gen_data.query.filter.call_count, 2)
144149

145150
@mock.patch('mod_test.controllers.Test')
146151
def test_get_json_data_no_test(self, mock_test):

0 commit comments

Comments
 (0)