11# Import built-in modules
22import os
33import sys
4- import tempfile
54import unittest
65from unittest .mock import Mock , patch , mock_open , call
76
@@ -20,7 +19,7 @@ def setUp(self):
2019 self .mock_api = Mock ()
2120 self .mock_logger = Mock ()
2221 self .vaccine = Vaccine (api = self .mock_api , logger = self .mock_logger )
23-
22+
2423 # Mock paths
2524 self .mock_api .local_script_path = "/mock/local/scripts"
2625 self .mock_api .user_script_path = "/mock/user/scripts"
@@ -33,7 +32,9 @@ def test_virus_name(self):
3332 @patch ('maya_umbrella.vaccines.vaccine4.check_reference_node_exists' )
3433 @patch ('maya_umbrella.vaccines.vaccine4.get_attr_value' )
3534 @patch ('maya_umbrella.vaccines.vaccine4.check_virus_by_signature' )
36- def test_collect_infected_nodes_with_virus_signatures (self , mock_check_virus , mock_get_attr , mock_check_ref , mock_cmds ):
35+ def test_collect_infected_nodes_with_virus_signatures (
36+ self , mock_check_virus , mock_get_attr , mock_check_ref , mock_cmds
37+ ):
3738 """Test detection of infected nodes with virus signatures."""
3839 # Setup mocks
3940 mock_cmds .ls .return_value = ["script1" , "script2" ]
@@ -57,9 +58,9 @@ def test_collect_infected_nodes_with_uifiguration_virus(self, mock_cmds):
5758 mock_cmds .ls .return_value = []
5859 mock_cmds .objExists .return_value = True
5960 mock_cmds .getAttr .return_value = "malicious code with leukocyte and phage"
60-
61+
6162 self .vaccine .collect_infected_nodes ()
62-
63+
6364 mock_cmds .objExists .assert_called_with ('uifiguration' )
6465 mock_cmds .getAttr .assert_called_with ('uifiguration.notes' )
6566 self .mock_api .add_infected_node .assert_called_with ('uifiguration' )
@@ -70,9 +71,9 @@ def test_collect_infected_nodes_with_uifiguration_clean(self, mock_cmds):
7071 mock_cmds .ls .return_value = []
7172 mock_cmds .objExists .return_value = True
7273 mock_cmds .getAttr .return_value = "clean content"
73-
74+
7475 self .vaccine .collect_infected_nodes ()
75-
76+
7677 # Should not add as infected
7778 self .mock_api .add_infected_node .assert_not_called ()
7879
@@ -82,10 +83,10 @@ def test_collect_infected_nodes_uifiguration_exception(self, mock_cmds):
8283 mock_cmds .ls .return_value = []
8384 mock_cmds .objExists .return_value = True
8485 mock_cmds .getAttr .side_effect = Exception ("Access denied" )
85-
86+
8687 # Should not raise exception
8788 self .vaccine .collect_infected_nodes ()
88-
89+
8990 # Should not add as infected due to exception
9091 self .mock_api .add_infected_node .assert_not_called ()
9192
@@ -126,9 +127,9 @@ def test_collect_malicious_files_no_appdata(self, mock_getenv, mock_exists):
126127 """Test collection when APPDATA is not available."""
127128 mock_getenv .return_value = None
128129 mock_exists .return_value = False
129-
130+
130131 self .vaccine .collect_malicious_files ()
131-
132+
132133 # Should handle None APPDATA gracefully
133134 mock_getenv .assert_called_with ("APPDATA" )
134135
@@ -138,7 +139,7 @@ def test_collect_malicious_files_appdata_exception(self, mock_getenv, mock_exist
138139 """Test collection with APPDATA access exception."""
139140 mock_getenv .side_effect = Exception ("Environment error" )
140141 mock_exists .return_value = False
141-
142+
142143 # Should not raise exception
143144 self .vaccine .collect_malicious_files ()
144145
@@ -149,9 +150,9 @@ def test_collect_infected_user_setup_files_with_virus(self, mock_exists, mock_fi
149150 mock_exists .return_value = True
150151 virus_content = "class phage:\n def occupation(self):\n leukocyte = phage()"
151152 mock_file .return_value .read .return_value = virus_content
152-
153+
153154 self .vaccine .collect_infected_user_setup_files ()
154-
155+
155156 # Should detect virus in all 4 userSetup files
156157 self .assertTrue (self .mock_api .add_infected_file .called )
157158
@@ -162,9 +163,9 @@ def test_collect_infected_user_setup_files_clean(self, mock_exists, mock_file):
162163 mock_exists .return_value = True
163164 clean_content = "# Clean userSetup file\n print('Hello Maya')"
164165 mock_file .return_value .read .return_value = clean_content
165-
166+
166167 self .vaccine .collect_infected_user_setup_files ()
167-
168+
168169 # Should not detect any infections
169170 self .mock_api .add_infected_file .assert_not_called ()
170171
@@ -175,9 +176,9 @@ def test_collect_infected_user_setup_files_read_exception(self, mock_check_virus
175176 """Test userSetup files that can't be read."""
176177 mock_exists .return_value = True
177178 mock_check_virus .return_value = True
178-
179+
179180 self .vaccine .collect_infected_user_setup_files ()
180-
181+
181182 # Should fall back to signature check
182183 self .assertTrue (mock_check_virus .called )
183184 self .assertTrue (self .mock_api .add_infected_file .called )
@@ -193,13 +194,13 @@ def test_collect_script_jobs_with_malicious_jobs(self, mock_cmds):
193194 "127: SceneSaved -> SceneSaved.*leukocyte"
194195 ]
195196 mock_cmds .scriptJob .return_value = mock_script_jobs
196-
197+
197198 self .vaccine .collect_script_jobs ()
198-
199+
199200 # Should kill malicious jobs (123, 125, 126, 127)
200201 expected_kill_calls = [
201202 call (kill = 123 ),
202- call (kill = 125 ),
203+ call (kill = 125 ),
203204 call (kill = 126 ),
204205 call (kill = 127 )
205206 ]
@@ -209,9 +210,9 @@ def test_collect_script_jobs_with_malicious_jobs(self, mock_cmds):
209210 def test_collect_script_jobs_no_jobs (self , mock_cmds ):
210211 """Test script job collection when no jobs exist."""
211212 mock_cmds .scriptJob .return_value = []
212-
213+
213214 self .vaccine .collect_script_jobs ()
214-
215+
215216 # Should handle empty job list gracefully
216217 mock_cmds .scriptJob .assert_called_with (listJobs = True )
217218
@@ -220,18 +221,17 @@ def test_collect_script_jobs_kill_exception(self, mock_cmds):
220221 """Test script job killing with exception."""
221222 mock_script_jobs = ["invalid_format_job" ]
222223 mock_cmds .scriptJob .return_value = mock_script_jobs
223-
224+
224225 # Should not raise exception
225226 self .vaccine .collect_script_jobs ()
226227
227228 @patch ('maya_umbrella.vaccines.vaccine4.cmds' )
228229 def test_collect_script_jobs_exception (self , mock_cmds ):
229230 """Test script job collection with exception."""
230231 mock_cmds .scriptJob .side_effect = Exception ("Maya error" )
231-
232+
232233 # Should not raise exception
233234 self .vaccine .collect_script_jobs ()
234-
235235 # Should log warning
236236 self .mock_logger .warning .assert_called ()
237237
@@ -241,9 +241,9 @@ def test_collect_issues_calls_all_methods(self):
241241 patch .object (self .vaccine , 'collect_infected_user_setup_files' ) as mock_setup , \
242242 patch .object (self .vaccine , 'collect_infected_nodes' ) as mock_nodes , \
243243 patch .object (self .vaccine , 'collect_script_jobs' ) as mock_jobs :
244-
244+
245245 self .vaccine .collect_issues ()
246-
246+
247247 # Verify all collection methods were called
248248 mock_files .assert_called_once ()
249249 mock_setup .assert_called_once ()
0 commit comments