Skip to content

Commit

Permalink
fix: created mock to override file open (#580)
Browse files Browse the repository at this point in the history
This PR mocks the builtins.open for the
test_that_update_with_new_pattern_succeeds test so that the test doesn't
open and modify the actual secureli.yaml file in the repository

Tested that all tests still pass and that the secureli file is no longer
modified after running tests

## Clean Code Checklist
<!-- This is here to support you. Some/most checkboxes may not apply to
your change -->
- [ ] Meets acceptance criteria for issue
- [ ] New logic is covered with automated tests
- [ ] Appropriate exception handling added
- [ ] Thoughtful logging included
- [ ] Documentation is updated
- [ ] Follow-up work is documented in TODOs
- [ ] TODOs have a ticket associated with them
- [ ] No commented-out code included


<!--
Github-flavored markdown reference:
https://docs.github.com/en/get-started/writing-on-github
-->

Co-authored-by: Ian Bowden <ian.bowden@slalom>
  • Loading branch information
ian-bowden-slalom and Ian Bowden authored Jul 8, 2024
1 parent 51f2705 commit 525a738
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/application/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,19 @@ def test_that_scan_implements_multiple_file_args(mock_container: MagicMock):
)


def test_that_update_with_new_pattern_succeeds():
@pytest.fixture()
def mock_secureli_yaml_open_fn(mocker: MockerFixture) -> MagicMock:
mock_open = mocker.mock_open(
read_data="""
{}
"""
)
return mocker.patch("builtins.open", mock_open)


def test_that_update_with_new_pattern_succeeds(
mock_secureli_yaml_open_fn: MagicMock, # so we don't open and write to the actual secureli.yaml file
):
result = CliRunner().invoke(secureli.main.app, ["update", "--new-pattern", "foo"])
assert result.exit_code == 0
assert result.stdout == ""

0 comments on commit 525a738

Please sign in to comment.