-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for
DAQJobHandleStats
- Loading branch information
1 parent
d361b5d
commit 63a03a4
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import unittest | ||
from datetime import datetime | ||
from typing import cast | ||
from unittest.mock import MagicMock, patch | ||
|
||
from daq.base import DAQJob | ||
from daq.jobs.handle_stats import ( | ||
DAQJobHandleStats, | ||
DAQJobMessageStats, | ||
DAQJobStatsRecord, | ||
) | ||
from daq.models import DAQJobStats | ||
|
||
|
||
class TestDAQJobHandleStats(unittest.TestCase): | ||
def setUp(self): | ||
self.config = MagicMock() | ||
self.daq_job_handle_stats = DAQJobHandleStats(config=self.config) | ||
self.daq_job_handle_stats.message_out = MagicMock() | ||
|
||
def test_handle_message_success(self): | ||
message = DAQJobMessageStats( | ||
stats={ | ||
type(cast(DAQJob, MagicMock())): DAQJobStats( | ||
message_in_stats=DAQJobStatsRecord( | ||
last_updated=datetime.now(), count=5 | ||
), | ||
message_out_stats=DAQJobStatsRecord( | ||
last_updated=datetime.now(), count=3 | ||
), | ||
restart_stats=DAQJobStatsRecord( | ||
last_updated=datetime.now(), count=1 | ||
), | ||
) | ||
} | ||
) | ||
|
||
result = self.daq_job_handle_stats.handle_message(message) | ||
|
||
self.assertTrue(result) | ||
self.daq_job_handle_stats.message_out.put.assert_called_once() | ||
|
||
def test_handle_message_failure(self): | ||
message = MagicMock() | ||
with patch("daq.jobs.handle_stats.DAQJob.handle_message", return_value=False): | ||
result = self.daq_job_handle_stats.handle_message(message) | ||
|
||
self.assertFalse(result) | ||
self.daq_job_handle_stats.message_out.put.assert_not_called() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |