@@ -183,3 +183,44 @@ def test_issue_save(self):
183183 self .mock .client .add_comment .assert_called_with (self .mock_issue .jira_issue ,
184184 'test comments' )
185185 self .assertEqual (issue .status , 'Closed' )
186+
187+ def test_issue_save_only_update_missing_watchers (self ):
188+ """Test save only update missing watchers for existing issue."""
189+ self .mock .get_issue .return_value = self .mock_issue
190+ self .
mock_issue .
ccs .
add (
'[email protected] ' )
191+ self .
mock_issue .
ccs .
add (
'[email protected] ' )
192+ self .
mock .
get_watchers .
return_value = [
'[email protected] ' ]
193+ issue = self .issue_tracker .get_issue ('VSEC-3112' )
194+ issue .save (new_comment = 'test comments' )
195+ self .mock .get_watchers .assert_called ()
196+ self .mock .client .add_comment .assert_called_with (self .mock_issue .jira_issue ,
197+ 'test comments' )
198+ self .mock .client .add_watcher .assert_has_calls (
199+ [
200+ unittest .mock .call (self .mock_issue .jira_issue ,
201+ 202+ unittest .
mock .
call (
self .
mock_issue .
jira_issue ,
'[email protected] ' )
203+ ],
204+ any_order = True )
205+
206+ def test_issue_save_bad_watcher (self ):
207+ """Test save still works if a watcher doesn't exist."""
208+ self .mock .get_issue .return_value = self .mock_issue
209+
210+ # Simulate adding a watcher that doesn't exist.
211+ def side_affect_func (watcher ):
212+ if watcher == '[email protected] ' :
213+ raise jira .exceptions .JIRAError (
214+ text =
215+ 'The user "[email protected] " does not have permission to view this issue. This user will not be added to the watch list.' ,
216+ status_code = 401 )
217+
218+ self .
mock_issue .
ccs .
add (
'[email protected] ' )
219+ self .mock .client .add_watcher .side_effect = side_affect_func
220+
221+ issue = self .issue_tracker .get_issue ('VSEC-3112' )
222+ issue .status = 'Closed'
223+ issue .save (new_comment = 'test comments' )
224+ self .mock .client .add_comment .assert_called_with (self .mock_issue .jira_issue ,
225+ 'test comments' )
226+ self .assertEqual (issue .status , 'Closed' )
0 commit comments