Skip to content

Commit

Permalink
fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
inflac committed Aug 26, 2024
1 parent bf5bdcd commit cf52e7a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions testing/filehandler/test_safe_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

from io import StringIO, BytesIO
import tempfile

import sys
sys.path.append('html')
import os

# Ensure the 'html' directory is in sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../html')))
print(sys.path)

from filehandler import safe_file
from extensions.cms.CMSConfig import CMSConfig
from extensions.cms.CMSConfig import get_setting_from_config

class TestSafeFile(unittest.TestCase):

Expand All @@ -17,10 +23,11 @@ class TestSafeFile(unittest.TestCase):
@patch('filehandler.add_file_to_queue', return_value=True)
@patch('filehandler.sent_email_approval_request', return_value=True)
@patch('os.path.exists', return_value=True)
@patch('get_setting_from_config', return_value=False)
@patch('filehandler.get_setting_from_config', return_value=CMSConfig(0, "email_approve", False))
def test_successful_safe_file(self, mock_check_global_upload_limit,
mock_check_file_exist_in_db, mock_add_file_to_queue,
mock_sent_email_approval_request, mock_os_path_exists):
mock_sent_email_approval_request, mock_os_path_exists, mock_get_setting_from_config):

# Create a temporary directory
with tempfile.TemporaryDirectory() as temp_dir:
# Mock file object
Expand All @@ -36,6 +43,7 @@ def test_successful_safe_file(self, mock_check_global_upload_limit,
# Assertions
self.assertTrue(result)
# Add more assertions as needed

# Add more test cases for different scenarios

# Run the tests
if __name__ == '__main__':
unittest.main()

0 comments on commit cf52e7a

Please sign in to comment.