Skip to content

Commit 33fd30b

Browse files
authored
Merge branch 'master' into fix/datetime-deprecation
2 parents 076d997 + b304ba3 commit 33fd30b

4 files changed

Lines changed: 43 additions & 39 deletions

File tree

exceptions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44

55
class QueuedSampleNotFoundException(Exception):
6-
"""Custom exception handler for queued sample not found."""
6+
"""Raised when a queued sample cannot be found by the given ID."""
77

8-
def __init__(self, message: str) -> None:
9-
Exception.__init__(self)
8+
def __init__(self, message="Queued sample not found."):
9+
# By providing a default, all existing raise sites that call
10+
# this exception without arguments will still work, and new
11+
# calls can optionally provide a custom message.
12+
super().__init__(message)
1013
self.message = message
1114

1215

mod_ci/controllers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,9 @@ def progress_type_request(log, test, test_id, request) -> bool:
24372437
results = g.db.query(count(TestResultFile.got)).filter(
24382438
and_(
24392439
TestResultFile.test_id == test.id,
2440-
TestResultFile.regression_test_id.in_(results_zero_rc),
2440+
TestResultFile.regression_test_id.in_(
2441+
results_zero_rc.select()
2442+
),
24412443
TestResultFile.got.isnot(None)
24422444
)
24432445
).scalar()
@@ -2513,13 +2515,13 @@ def update_final_status():
25132515
finished_tests = select(TestProgress.test_id).filter(
25142516
and_(
25152517
TestProgress.status.in_([TestStatus.canceled, TestStatus.completed]),
2516-
TestProgress.test_id.in_(platform_tests)
2518+
TestProgress.test_id.in_(platform_tests.select())
25172519
)
25182520
)
25192521
in_progress_statuses = [TestStatus.preparation, TestStatus.completed, TestStatus.canceled]
25202522
finished_tests_progress = g.db.query(TestProgress).filter(
25212523
and_(
2522-
TestProgress.test_id.in_(finished_tests),
2524+
TestProgress.test_id.in_(finished_tests.select()),
25232525
TestProgress.status.in_(in_progress_statuses)
25242526
)
25252527
).subquery()

mod_sample/controllers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def display_sample_info(sample) -> Dict[str, Any]:
7070
sq = select(RegressionTest.id).filter(RegressionTest.sample_id == sample.id)
7171
exit_code = g.db.query(TestResult.exit_code).filter(and_(
7272
TestResult.exit_code != TestResult.expected_rc,
73-
and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq))
73+
and_(TestResult.test_id == test_commit.id, TestResult.regression_test_id.in_(sq.select()))
7474
)).first()
7575
not_null = g.db.query(TestResultFile.got).filter(and_(
7676
TestResultFile.got.isnot(None),
77-
and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq))
77+
and_(TestResultFile.test_id == test_commit.id, TestResultFile.regression_test_id.in_(sq.select()))
7878
)).first()
7979

8080
if exit_code is None and not_null is None:
@@ -88,12 +88,12 @@ def display_sample_info(sample) -> Dict[str, Any]:
8888
exit_code = g.db.query(TestResult.exit_code).filter(
8989
and_(
9090
TestResult.exit_code != TestResult.expected_rc,
91-
and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq))
91+
and_(TestResult.test_id == test_release.id, TestResult.regression_test_id.in_(sq.select()))
9292
)
9393
).first()
9494
not_null = g.db.query(TestResultFile.got).filter(and_(
9595
TestResultFile.got.isnot(None),
96-
and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq))
96+
and_(TestResultFile.test_id == test_release.id, TestResultFile.regression_test_id.in_(sq.select()))
9797
)).first()
9898

9999
if exit_code is None and not_null is None:

tests/test_upload/test_controllers.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,35 +170,34 @@ def test_upload_ftp_forbidden_extension(self, mock_shutil, mock_hash, mock_magic
170170
QueuedSample.sha == filehash).first()
171171
self.assertEqual(queued_sample, None)
172172

173-
# TODO: The methods below are not working due to decorator login_required not being mocked
174-
# @mock.patch('mod_upload.controllers.login_required', side_effect=mock_decorator)
175-
# def test_link_id_confirm_invalid(self, mock_login):
176-
# """
177-
# Try to confirm link for invalid sample and queue.
178-
# """
179-
# from mod_upload.controllers import link_id_confirm, QueuedSampleNotFoundException
180-
181-
# with self.assertRaises(QueuedSampleNotFoundException):
182-
# link_id_confirm(1000, 1000)
183-
184-
# @mock.patch('mod_upload.controllers.redirect')
185-
# @mock.patch('mod_upload.controllers.login_required', side_effect=mock_decorator)
186-
# @mock.patch('mod_upload.controllers.QueuedSample')
187-
# @mock.patch('mod_upload.controllers.Sample')
188-
# def test_link_id_confirm(self, mock_sample, mock_queue, mock_login, mock_redirect):
189-
# """
190-
# Test confirm link for valid sample and queue.
191-
# """
192-
# from mod_upload.controllers import link_id_confirm
193-
194-
# mock_queue.query.filter.return_value.first.return_value.user_id = g.user
195-
# mock_sample.query.filter.return_value.first.return_value.upload.user_id = g.user
196-
197-
# response = link_id_confirm(1, 1)
198-
199-
# self.assertEqual(response, mock_redirect())
200-
# mock_queue.query.filter.assert_called_once_with(mock_queue.id == 1)
201-
# mock_sample.query.filter.assert_called_once_with(mock_sample.id == 1)
173+
def test_link_id_confirm_invalid(self):
174+
"""Try to confirm link for invalid sample and queue."""
175+
from mod_upload.controllers import (QueuedSampleNotFoundException,
176+
link_id_confirm)
177+
178+
with self.assertRaises(QueuedSampleNotFoundException):
179+
link_id_confirm.__wrapped__(1000, 1000)
180+
181+
@mock.patch('mod_upload.controllers.redirect')
182+
@mock.patch('mod_upload.controllers.QueuedSample')
183+
@mock.patch('mod_upload.controllers.Sample')
184+
@mock.patch('mod_upload.controllers.g')
185+
def test_link_id_confirm_valid(self, mock_g, mock_sample, mock_queue, mock_redirect):
186+
"""Test confirm link for valid sample and queue."""
187+
from mod_upload.controllers import link_id_confirm
188+
189+
# Mock g.user to have an 'id' attribute to satisfy the controller
190+
mock_g.user.id = 1
191+
192+
# Ensure the mocked database queries return an object owned by that user
193+
mock_queue.query.filter.return_value.first.return_value.user_id = mock_g.user.id
194+
mock_sample.query.filter.return_value.first.return_value.upload.user_id = mock_g.user.id
195+
196+
response = link_id_confirm.__wrapped__(1, 1)
197+
198+
self.assertEqual(response, mock_redirect())
199+
mock_queue.query.filter.assert_called_once()
200+
mock_sample.query.filter.assert_called_once()
202201

203202
def test_create_hash_for_sample(self):
204203
"""Test creating hash for temp file."""

0 commit comments

Comments
 (0)