Closed vijaykannan21 closed 2 months ago
Descriptor | Linter | Files | Fixed | Errors | Elapsed time |
---|---|---|---|---|---|
✅ PYTHON | flake8 | 4 | 0 | 0.6s | |
✅ PYTHON | isort | 4 | 3 | 0 | 0.35s |
✅ PYTHON | pylint | 4 | 0 | 3.15s | |
✅ REPOSITORY | gitleaks | yes | no | 1.62s |
See detailed report in MegaLinter reports
_Set VALIDATE_ALL_CODEBASE: true
in mega-linter.yml to validate all sources, not only the diff_
Some example tests for reference
# A very Basic tests without mocking
class TestAddNumebrs(unittest.TestCase):
def test_function_adds_numbers(self):
# Given
number_1 = 1
number_2 = 2
# When
response = add_numbers(number_1, number_2)
# Then
self.assertEqual(response, 3)
# A test for the current code (given it returned a value) where we mock the interaction with the S3Service
@patch("services.s3_service.S3Service.__new__")
class TestMTASTSExample(unittest.TestCase):
def test_0_failed_domains_when_all_domains_have_mta_sts_enforce(self, mock_s3_service):
# Given ...setup environment and mocks
mock_s3_service.return_value.is_well_known_mta_sts_enforce.return_value = True
# When ...call main()
failed_domains = main()
# Then ...add assertions
self.assertEquals(len(failed_domains), 0)
Hopefully, this helps get a basic structure together for the unit testing! 🧪
Rephrased check_mta_sts.py Improved readability by renaming variables and functions. Optimized logic for clarity and performance.
Rephrased s3_service.py Enhanced clarity with better variable and function names. Refactored larger functions into smaller ones for better modularity.
Rephrased in test_test_service_testS3_service.py
Pretends the file says "enforce" and checks that the method returns True. Pretends the file says "disabled" and checks that the method returns False. Pretends the file doesn't exist and checks that the method returns False.
Created test_check_mta_sts.py Added unit tests to cover core functionalities of check_mta_sts.py. Included test cases for typical and edge scenarios. Used mocking to isolate tests and assertions to verify outcomes.