Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deprecated UTC time usage #742

Merged
merged 6 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

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

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

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
11 changes: 11 additions & 0 deletions terraform_compliance/extensions/override_radish_utctime.py
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
3 changes: 3 additions & 0 deletions terraform_compliance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
Step.run = StepOverride.run

from terraform_compliance.extensions.override_radish_hookerrors import handle_exception as handle_exception_override
from terraform_compliance.extensions.override_radish_utctime import apply_utctime_patch
from radish import errororacle

errororacle.handle_exception = handle_exception_override
apply_utctime_patch()
##
#

Expand Down
15 changes: 9 additions & 6 deletions tests/terraform_compliance/common/test_bdd_tags.py
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')
Loading