-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dpp 584 academy bookmark version handling (#1529)
* add GetCrawler action to permissions (cherry picked from commit 25bec05) * add BOOKMARK_CONTEXT job parameter (cherry picked from commit d5ae51c) * add BOOKMARK_CONTEXT handling * formatting * extract initialise_job to methods * remove type hints * accidentally deleted the function * import logging * point assert at correct module * one too many ctrl z * add _ between job name and bookmark context * remove 'Job' type * add logger to job initialisation
- Loading branch information
1 parent
5e97ebc
commit 187489b
Showing
5 changed files
with
143 additions
and
36 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
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,55 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from scripts.helpers.helpers import initialise_job | ||
|
||
|
||
class TestInitialiseJob(unittest.TestCase): | ||
def setUp(self): | ||
self.mock_job = MagicMock() | ||
self.mock_logger = MagicMock() | ||
self.args_with_bookmark = { | ||
"JOB_NAME": "test_job", | ||
"BOOKMARK_CONTEXT": "test_context", | ||
} | ||
self.args_without_bookmark = {"JOB_NAME": "test_job"} | ||
|
||
def test_initialise_job_with_bookmark_context_and_logger(self): | ||
initialise_job(self.args_with_bookmark, self.mock_job, self.mock_logger) | ||
self.mock_job.init.assert_called_once_with( | ||
"test_job_test_context", self.args_with_bookmark | ||
) | ||
self.mock_logger.error.assert_not_called() | ||
|
||
def test_initialise_job_without_bookmark_context_and_logger(self): | ||
initialise_job(self.args_without_bookmark, self.mock_job, self.mock_logger) | ||
self.mock_job.init.assert_called_once_with( | ||
"test_job", self.args_without_bookmark | ||
) | ||
self.mock_logger.error.assert_not_called() | ||
|
||
def test_initialise_job_without_job_name_and_logger(self): | ||
with self.assertRaises(ValueError): | ||
initialise_job({}, self.mock_job, self.mock_logger) | ||
self.mock_logger.error.assert_called_once() | ||
|
||
@patch("scripts.helpers.helpers.logging") | ||
def test_initialise_job_with_initialisation_exception_and_default_logger( | ||
self, mock_logging | ||
): | ||
self.mock_job.init.side_effect = Exception("Test Exception") | ||
with self.assertRaises(Exception): | ||
initialise_job(self.args_with_bookmark, self.mock_job) | ||
mock_logging.getLogger.assert_called_with("scripts.helpers.helpers") | ||
self.mock_job.init.assert_called_once() | ||
|
||
def test_initialise_job_with_initialisation_exception_and_custom_logger(self): | ||
self.mock_job.init.side_effect = Exception("Test Exception") | ||
with self.assertRaises(Exception): | ||
initialise_job(self.args_with_bookmark, self.mock_job, self.mock_logger) | ||
self.mock_logger.error.assert_called_with( | ||
"Failed to initialise job: Test Exception" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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