def test_set_job(self): ''' Test if it sets a cron job up for a specified user. ''' self.assertEqual(incron.set_job('cybage', '/home/cybage', 'TO_MODIFY', 'echo "$$ $@ $# $% $&"'), 'Invalid mask type: TO_MODIFY') val = {'pre': [], 'crons': [{'path': '/home/cybage', 'mask': 'IN_MODIFY', 'cmd': 'echo "SALT"', 'comment': ''}]} with patch.object(incron, 'list_tab', MagicMock(return_value=val)): self.assertEqual(incron.set_job('cybage', '/home/cybage', 'IN_MODIFY', 'echo "SALT"'), 'present') 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.set_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.set_job('cybage', '/home/cybage', 'IN_MODIFY', 'echo "SALT"'), 'new') val = {'pre': [], 'crons': [{'path': '/home/cybage', 'mask': 'IN_MODIFY,IN_DELETE', 'cmd': 'echo "SALT"', 'comment': ''}]} with patch.object(incron, 'list_tab', MagicMock(return_value=val)): 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.set_job('cybage', '/home/cybage', 'IN_DELETE', 'echo "SALT"'), 'updated')
def test_set_job(self): """ Test if it sets a cron job up for a specified user. """ self.assertEqual( incron.set_job( "cybage", "/home/cybage", "TO_MODIFY", 'echo "$$ $@ $# $% $&"' ), "Invalid mask type: TO_MODIFY", ) val = { "pre": [], "crons": [ {"path": "/home/cybage", "mask": "IN_MODIFY", "cmd": 'echo "SALT"'} ], } with patch.object(incron, "list_tab", MagicMock(return_value=val)): self.assertEqual( incron.set_job("cybage", "/home/cybage", "IN_MODIFY", 'echo "SALT"'), "present", ) 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.set_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.set_job( "cybage", "/home/cybage", "IN_MODIFY", 'echo "SALT"' ), "new", ) val = { "pre": [], "crons": [ { "path": "/home/cybage", "mask": "IN_MODIFY,IN_DELETE", "cmd": 'echo "SALT"', } ], } with patch.object(incron, "list_tab", MagicMock(return_value=val)): 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.set_job( "cybage", "/home/cybage", "IN_DELETE", 'echo "SALT"' ), "updated", )