def test_rm_job(self): ''' Test if it remove a cron job for a specified user. If any of the day/time params are specified, the job will only be removed if the specified params match. ''' self.assertEqual(incron.rm_job('cybage', '/home/cybage', 'TO_MODIFY', 'echo "$$ $@ $# $% $&"'), 'Invalid mask type: TO_MODIFY') with patch.object(incron, 'list_tab', MagicMock(return_value={'pre': ['salt'], 'crons': []})): mock = MagicMock(return_value='incrontab') with patch.dict(incron.__grains__, {'os_family': mock}): with patch.object(incron, '_write_incron_lines', MagicMock(return_value={'retcode': True, 'stderr': 'error'})): self.assertEqual(incron.rm_job('cybage', '/home/cybage', 'IN_MODIFY', 'echo "SALT"'), 'error') with patch.object(incron, 'list_tab', MagicMock(return_value={'pre': ['salt'], 'crons': []})): mock = MagicMock(return_value='incrontab') with patch.dict(incron.__grains__, {'os_family': mock}): with patch.object(incron, '_write_incron_lines', MagicMock(return_value={'retcode': False, 'stderr': 'error'})): self.assertEqual(incron.rm_job('cybage', '/home/cybage', 'IN_MODIFY', 'echo "SALT"'), 'absent')
def test_rm_job(self): """ Test if it remove a cron job for a specified user. If any of the day/time params are specified, the job will only be removed if the specified params match. """ self.assertEqual( incron.rm_job("cybage", "/home/cybage", "TO_MODIFY", 'echo "$$ $@ $# $% $&"'), "Invalid mask type: TO_MODIFY", ) with patch.object( incron, "list_tab", MagicMock(return_value={ "pre": ["salt"], "crons": [] })): mock = MagicMock(return_value="incrontab") with patch.dict(incron.__grains__, {"os_family": mock}): with patch.object( incron, "_write_incron_lines", MagicMock(return_value={ "retcode": True, "stderr": "error" }), ): self.assertEqual( incron.rm_job("cybage", "/home/cybage", "IN_MODIFY", 'echo "SALT"'), "error", ) with patch.object( incron, "list_tab", MagicMock(return_value={ "pre": ["salt"], "crons": [] })): mock = MagicMock(return_value="incrontab") with patch.dict(incron.__grains__, {"os_family": mock}): with patch.object( incron, "_write_incron_lines", MagicMock(return_value={ "retcode": False, "stderr": "error" }), ): self.assertEqual( incron.rm_job("cybage", "/home/cybage", "IN_MODIFY", 'echo "SALT"'), "absent", )