Skip to content

Commit 148f1aa

Browse files
authored
fix: Deprecated UTC time usage (terraform-compliance#742)
* `fix`: Deprecated UTC time usage * `fix`: Update on codeql * `ref`: Update on general mocking
1 parent 4a71a5b commit 148f1aa

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
# Initializes the CodeQL tools for scanning.
2929
- name: Initialize CodeQL
30-
uses: github/codeql-action/init@v1
30+
uses: github/codeql-action/init@v2
3131
with:
3232
languages: ${{ matrix.language }}
3333
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -38,7 +38,7 @@ jobs:
3838
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3939
# If this step fails, then you should remove it and run the build manually (see below)
4040
- name: Autobuild
41-
uses: github/codeql-action/autobuild@v1
41+
uses: github/codeql-action/autobuild@v2
4242

4343
# ℹ️ Command-line programs to run using the OS shell.
4444
# 📚 https://git.io/JvXDl
@@ -52,4 +52,4 @@ jobs:
5252
# make release
5353

5454
- name: Perform CodeQL Analysis
55-
uses: github/codeql-action/analyze@v1
55+
uses: github/codeql-action/analyze@v2
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import radish.extensions.time_recorder
2+
import datetime
3+
import mock
4+
5+
def current_utc_time():
6+
return datetime.datetime.now(datetime.timezone.utc)
7+
8+
def apply_utctime_patch():
9+
# Patch datetime specifically within radish.extensions.time_recorder
10+
radish.extensions.time_recorder.datetime = mock.Mock()
11+
radish.extensions.time_recorder.datetime.utcnow = current_utc_time

terraform_compliance/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
Step.run = StepOverride.run
2323

2424
from terraform_compliance.extensions.override_radish_hookerrors import handle_exception as handle_exception_override
25+
from terraform_compliance.extensions.override_radish_utctime import apply_utctime_patch
2526
from radish import errororacle
27+
2628
errororacle.handle_exception = handle_exception_override
29+
apply_utctime_patch()
2730
##
2831
#
2932

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
from unittest import TestCase
1+
from unittest import TestCase, mock
22
from terraform_compliance.common.bdd_tags import look_for_bdd_tags
3-
from terraform_compliance.common.exceptions import Failure
3+
from terraform_compliance.extensions.override_radish_utctime import current_utc_time
44
from tests.mocks import MockedStep, MockedTags
55

6-
76
class TestBddTags(TestCase):
87

9-
def test_unchanged_step_object(self):
8+
@mock.patch('radish.extensions.time_recorder.datetime')
9+
def test_unchanged_step_object(self, mock_datetime):
10+
mock_datetime.utcnow.side_effect = current_utc_time # Patches within radish
1011
step = MockedStep()
1112
look_for_bdd_tags(step)
1213
self.assertFalse(step.context.no_failure)
1314
self.assertIsNone(step.context.failure_class)
1415

15-
def test_warning_case(self):
16+
@mock.patch('radish.extensions.time_recorder.datetime')
17+
def test_warning_case(self, mock_datetime):
18+
mock_datetime.utcnow.side_effect = current_utc_time # Patches within radish
1619
step = MockedStep()
1720
step.all_tags = [MockedTags(name='warning')]
1821
look_for_bdd_tags(step)
1922
self.assertTrue(step.context.no_failure)
20-
self.assertEqual(step.context.failure_class, 'warning')
23+
self.assertEqual(step.context.failure_class, 'warning')

0 commit comments

Comments
 (0)