def test_remove(self): with patch.dict(cron.__opts__, {"test": True}): self.set_crontab( "# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:1\n" "* 1 * * * foo") result = cron.absent(name="bar", identifier="1") self.assertEqual( result, { "changes": {}, "comment": "Cron bar is set to be removed", "name": "bar", "result": None, }, ) self.assertEqual( self.get_crontab(), "# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:1\n" "* 1 * * * foo", ) with patch.dict(cron.__opts__, {"test": False}): self.set_crontab( "# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:1\n" "* 1 * * * foo") cron.absent(name="bar", identifier="1") self.assertEqual( self.get_crontab(), "# Lines below here are managed by Salt, do not edit", ) self.set_crontab( "# Lines below here are managed by Salt, do not edit\n" "* * * * * foo") cron.absent(name="bar", identifier="1") self.assertEqual( self.get_crontab(), "# Lines below here are managed by Salt, do not edit\n" "* * * * * foo", ) # old behavior, do not remove with identifier set and # even if command match ! self.set_crontab( "# Lines below here are managed by Salt, do not edit\n" "* * * * * foo") cron.absent(name="foo", identifier="1") self.assertEqual( self.get_crontab(), "# Lines below here are managed by Salt, do not edit", ) # old behavior, remove if no identifier and command match self.set_crontab( "# Lines below here are managed by Salt, do not edit\n" "* * * * * foo") cron.absent(name="foo") self.assertEqual( self.get_crontab(), "# Lines below here are managed by Salt, do not edit", )
def test_remove(self): with patch.dict(cron.__opts__, {'test': True}): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo') result = cron.absent(name='bar', identifier='1') self.assertEqual( result, {'changes': {}, 'comment': 'Cron bar is set to be removed', 'name': 'bar', 'result': None} ) self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo') with patch.dict(cron.__opts__, {'test': False}): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' ) set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo' ) # old behavior, do not remove with identifier set and # even if command match ! set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' ) # old behavior, remove if no identifier and command match set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' )
def test_remove(self): set_crontab('# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit') set_crontab('# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') # old behavior, do not remove with identifier setted and # even if command match ! set_crontab('# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit') # old behavior, remove if no identifier and command match set_crontab('# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit')
def test_remove(self): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' ) set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='bar', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo' ) # old behavior, do not remove with identifier set and # even if command match ! set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo', identifier='1') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' ) # old behavior, remove if no identifier and command match set_crontab( '# Lines below here are managed by Salt, do not edit\n' '* * * * * foo') cron.absent(name='foo') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit' )