Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Fix grant request helper unit test file existence verification (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: vassalo <[email protected]>
  • Loading branch information
2 people authored and wallrony committed Aug 19, 2022
1 parent 38268e5 commit b201a4c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions plugins/sdm/lib/helper/test_grant_request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,23 @@ def test_restore_state_when_has_stored_requests(self):
assert not helper.exists(request_id)

def test_raise_exception_when_add_duplicated_request(self):
bot = get_mocked_bot()
with patch("builtins.open", mock_open(read_data=mocked_file_data)) as handle:
helper = GrantRequestHelper(bot)
assert helper.get(request_id) is not None
assert helper.exists(request_id)
assert len(helper.get_request_ids()) == 1
file = handle()
file.read.assert_called_once()
with pytest.raises(Exception) as e:
helper.add(request_id, get_mocked_message(), get_mock_sdm_object(), get_mock_sdm_account(),
GrantRequestType.ACCESS_RESOURCE)
assert "already have a pending grant request" in e.value
helper.remove(request_id)
assert helper.get(request_id) is None
assert not helper.exists(request_id)
with patch("os.path.isfile") as mock_isfile:
mock_isfile.side_effect = [True]
bot = get_mocked_bot()
with patch("builtins.open", mock_open(read_data=mocked_file_data)) as handle:
helper = GrantRequestHelper(bot)
assert helper.get(request_id) is not None
assert helper.exists(request_id)
assert len(helper.get_request_ids()) == 1
file = handle()
file.read.assert_called_once()
with pytest.raises(Exception) as e:
helper.add(request_id, get_mocked_message(), get_mock_sdm_object(), get_mock_sdm_account(),
GrantRequestType.ACCESS_RESOURCE)
assert "already have a pending grant request" in e.value
helper.remove(request_id)
assert helper.get(request_id) is None
assert not helper.exists(request_id)

def test_dont_restore_state_when_has_stored_requests_and_is_disabled(self):
with patch("os.path.isfile") as mock_isfile:
Expand Down

0 comments on commit b201a4c

Please sign in to comment.