-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_result_loading.py
More file actions
80 lines (61 loc) · 2.84 KB
/
test_result_loading.py
File metadata and controls
80 lines (61 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import sys
import os
import tempfile
import json
import shutil
# Add the package directory to the path so we can import the main module
script_dir = os.path.dirname(os.path.abspath(__file__))
if '/usr/lib/csas-sharepoint' in script_dir:
# Running from installed package
sys.path.insert(0, '/usr/lib/csas-sharepoint')
else:
# Running from source
sys.path.insert(0, os.path.join(os.path.dirname(script_dir), 'src'))
from main import CSASSharePointUploader
def test_result_loading():
"""Test the result loading functionality with mock data."""
print("Testing result loading functionality...")
# Create a temporary directory for testing
temp_dir = tempfile.mkdtemp(prefix='csas_test_')
print(f"Using temp directory: {temp_dir}")
try:
# Set up environment for testing
os.environ['RESULT_FILE'] = os.path.join(temp_dir, 'original_result.json')
# Create uploader instance
uploader = CSASSharePointUploader(temp_dir)
# Set up temporary result file
uploader._setup_temp_result_file()
print(f"Temp result file: {uploader.temp_result_file}")
# Test 1: Copy mock download result and test loading
if uploader.temp_result_file:
shutil.copy2('/tmp/mock_csas_result.json', uploader.temp_result_file)
download_result = uploader._load_temp_result('download')
print("\\nDownload result loaded:")
print(json.dumps(download_result, indent=2))
# Test 2: Copy mock upload result and test loading
shutil.copy2('/tmp/mock_sharepoint_result.json', uploader.temp_result_file)
upload_result = uploader._load_temp_result('upload')
print("\\nUpload result loaded:")
print(json.dumps(upload_result, indent=2))
# Test 3: Test result writing
uploader.download_result = download_result
uploader.upload_results = [upload_result]
uploader.downloaded_files = ['/tmp/test1.pdf', '/tmp/test2.pdf']
# Mock the original result file
uploader.original_result_file = os.path.join(temp_dir, 'final_report.json')
uploader._write_final_result()
# Read and display final result
with open(uploader.original_result_file, 'r') as f:
final_result = json.load(f)
print("\\nFinal combined result:")
print(json.dumps(final_result, indent=2))
else:
print("No temp result file was set up")
finally:
# Cleanup
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
print(f"\\nCleaned up temp directory: {temp_dir}")
if __name__ == "__main__":
test_result_loading()