-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix
: Deprecated UTC time usage (#742)
* `fix`: Deprecated UTC time usage * `fix`: Update on codeql * `ref`: Update on general mocking
- Loading branch information
Showing
4 changed files
with
26 additions
and
9 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
11 changes: 11 additions & 0 deletions
11
terraform_compliance/extensions/override_radish_utctime.py
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,11 @@ | ||
import radish.extensions.time_recorder | ||
import datetime | ||
import mock | ||
|
||
def current_utc_time(): | ||
return datetime.datetime.now(datetime.timezone.utc) | ||
|
||
def apply_utctime_patch(): | ||
# Patch datetime specifically within radish.extensions.time_recorder | ||
radish.extensions.time_recorder.datetime = mock.Mock() | ||
radish.extensions.time_recorder.datetime.utcnow = current_utc_time |
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 |
---|---|---|
@@ -1,20 +1,23 @@ | ||
from unittest import TestCase | ||
from unittest import TestCase, mock | ||
from terraform_compliance.common.bdd_tags import look_for_bdd_tags | ||
from terraform_compliance.common.exceptions import Failure | ||
from terraform_compliance.extensions.override_radish_utctime import current_utc_time | ||
from tests.mocks import MockedStep, MockedTags | ||
|
||
|
||
class TestBddTags(TestCase): | ||
|
||
def test_unchanged_step_object(self): | ||
@mock.patch('radish.extensions.time_recorder.datetime') | ||
def test_unchanged_step_object(self, mock_datetime): | ||
mock_datetime.utcnow.side_effect = current_utc_time # Patches within radish | ||
step = MockedStep() | ||
look_for_bdd_tags(step) | ||
self.assertFalse(step.context.no_failure) | ||
self.assertIsNone(step.context.failure_class) | ||
|
||
def test_warning_case(self): | ||
@mock.patch('radish.extensions.time_recorder.datetime') | ||
def test_warning_case(self, mock_datetime): | ||
mock_datetime.utcnow.side_effect = current_utc_time # Patches within radish | ||
step = MockedStep() | ||
step.all_tags = [MockedTags(name='warning')] | ||
look_for_bdd_tags(step) | ||
self.assertTrue(step.context.no_failure) | ||
self.assertEqual(step.context.failure_class, 'warning') | ||
self.assertEqual(step.context.failure_class, 'warning') |