-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
500 error if reach upload or cya page with no session
- Loading branch information
Morgan Rees
authored and
Morgan Rees
committed
Jan 7, 2025
1 parent
3eec0a8
commit 44f96e9
Showing
2 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 39 additions & 18 deletions
57
tests/test_unit/test_report_a_suspected_breach/test_s3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
# TODO: To be updated in DST-512 | ||
# from unittest.mock import MagicMock, Mock, patch | ||
# | ||
# from utils.s3 import get_all_session_files | ||
# | ||
# | ||
# @patch("utils.s3.get_s3_client_from_storage") | ||
# def test_get_all_session_files(mocked_get_s3_client): | ||
# mocked_get_s3_client.return_value = MagicMock() | ||
# mocked_get_s3_client.return_value.list_objects_v2 = MagicMock(return_value={"Contents": [{"Key": "test.png"}]}) | ||
# | ||
# session_object = MagicMock() | ||
# session_object.get = MagicMock(return_value=["test.png"]) | ||
# session_object.session_key = "test_session_key" | ||
# | ||
# session_files = get_all_session_files(Mock(), session_object) | ||
# assert len(session_files) == 1 | ||
# assert "test.png" in session_files | ||
from unittest.mock import MagicMock, Mock, patch | ||
|
||
from django.core.cache import cache | ||
from utils.s3 import get_all_session_files | ||
|
||
|
||
@patch("utils.s3.get_s3_client_from_storage") | ||
def test_get_all_session_files(mocked_get_s3_client): | ||
mocked_get_s3_client.return_value = MagicMock() | ||
mocked_get_s3_client.return_value.list_objects_v2 = MagicMock(return_value={"Contents": [{"Key": "test.png"}]}) | ||
|
||
session_object = MagicMock() | ||
session_object.is_empty = MagicMock(return_value=False) | ||
session_object.get = MagicMock(return_value=["test.png"]) | ||
|
||
session_object.session_key = "test_session_key" | ||
redis_cache_key = f"{session_object.session_key}" | ||
cache.set(redis_cache_key, "test.png") | ||
|
||
session_files = get_all_session_files(Mock(), session_object) | ||
assert len(session_files) == 1 | ||
assert "test.png" in session_files | ||
|
||
|
||
@patch("utils.s3.get_s3_client_from_storage") | ||
def test_no_session_returns_empty_session_files(mocked_get_s3_client): | ||
mocked_get_s3_client.return_value = MagicMock() | ||
mocked_get_s3_client.return_value.list_objects_v2 = MagicMock(return_value={"Contents": [{"Key": "test.png"}]}) | ||
|
||
session_object = MagicMock() | ||
session_object.is_empty = MagicMock(return_value=True) | ||
session_object.get = MagicMock(return_value=["test.png"]) | ||
|
||
session_object.session_key = "test_session_key" | ||
redis_cache_key = f"{session_object.session_key}" | ||
cache.set(redis_cache_key, "test.png") | ||
|
||
session_files = get_all_session_files(Mock(), session_object) | ||
assert len(session_files) == 0 |